<template>
	<view class="content">
		<view class="headbgbox flex2">

			<view class="searchbox">
				<u-icon name="search" bold="true" size="25" color="rgb(246,185,78)"></u-icon>
				<input type="text" v-model="keywords" placeholder="请输入供应商名称"
					placeholder-style="color:#BBBCBE" @blur="changeSeach"/>
			</view>
			<view class="screen" @click="show = true">
				<text>筛选</text>
				<view style="padding-left: 10rpx;">
					<u-icon name="arrow-down" color="#1F242A" size="14" bold="true"></u-icon>
				</view>

			</view>
		</view>
		<view class="cardlist">
			<view class="lable" v-for="(item,index) in listall" style="width: 100%;" >
				<view class="radiobox" v-if="editall">
					<radio :value="index" :checked="item.checked" color="#D8AB5A" @click="checkBox(item.id)" />
				</view>
				<view class="card" @click.stop="moveDetail(item.id)">
					<view class="passreview" v-if="item.status==1&&item.isDeleted==0">
						<image src="../../static/img/Cercomplete.png" mode="aspectFill"></image>
					</view>
					<view class="passreview" v-if="item.status==0&&item.isDeleted==0">
						<image src="../../static/img/toreviewe.png" mode="aspectFill"></image>
					</view>
					<view class="passreview" v-if="item.status==3&&item.isDeleted==0">
						<image src="../../static/img/fail.png" mode="aspectFill"></image>
					</view>
					<view class="passreview" v-if="item.isDeleted==1">
						<image src="../../static/img/disabled.png" mode="aspectFill"></image>
					</view>
					<view class="cicle" v-if="item.status==1&&item.isDeleted==0"></view>
					<view class="cicle" v-if="item.status==0" style="background-color: #D05C39;"></view>
					<view class="cicle" v-if="item.status==3" style="background-color: #1F242A;"></view>
					<view class="cicle" v-if="item.isDeleted==1" style="background-color: #BEBDBB;"></view>
					<view class="innerbox">

						<text class="cardtitle">{{item.name}}</text>
					</view>
					<view class="contractmsg flex5">
						<text style="color: #68625B;">法人名称：{{item.legalPerson}}</text>
						<view style="padding-top: 10rpx;color: #BEBDBB;" class="flex2">
							<text>联系人：{{item.contacts}}</text>
							<text>电话：{{item.contactsMobile}}</text>
						</view>

					</view>
				</view>
			</view>

		</view>
		<view class="nomore" v-if="listall.length==0">
			<text>暂无数据</text>
		</view>
		<view class="totalmanage ">
			<text style="color:#68625B;font-size: 28rpx;">合计：{{total}}份</text>
			<view class=" maboxtitls" @click="editall=true">
				<view class="managebox">
					<image src="/static/img/manage.png" mode="aspectFit"></image>
				</view>
				<text style="padding-left: 15rpx;">管理</text>
			</view>
		</view>
		<view class="safebt"></view>
		<u-popup :show="show" @close="close" @open="open">
			<view class="popscreen" style="height: 440rpx;">
				<view class="checklist" v-for="(item,index) in ctrstatus" :key="index">
					<view class="alllistbtn">
						<text class="btntitle" style="">{{item.title}}</text>
						<view class="yunbtn">
							<view class="btnchoose" v-for="(i,k) in item.list" :key="k" @click="choose(item.title,k)"
								:class="[contract_status == k?'active':'btnchoose']">
								<text>{{i.name}}</text>
							</view>
						</view>
					</view>
				</view>
				<view class="aszs flex6">
					<view class="againbtn" @click="restoreALL"><text>重置</text></view>
					<view class="againbtn" style="color: #D8AB5A;border: 1rpx solid #D8AB5A;" @click="makeSureSelect()"><text>确认</text></view>
				</view>
			</view>
		</u-popup>
		<u-datetime-picker :show="dateshow" v-model="value1" mode="year-month" @confirm="chooseDate"
			@cancel="closeDate"></u-datetime-picker>
		<!-- 底部删除 -->
		<u-popup :show="editall&&state==1" @close="closeEidt" @open="openEidt" :overlay="false">
			<view class="editbox">
				<view class="chooseall flex6">
					<view class="leftchoose ">
						<radio :checked="quan" @click="makeSureAll" color="#D8AB5A"></radio>
						<text>全选</text>
					</view>
					<view class="surebtn" @click="selectDown">
						完成
					</view>
				</view>
				<view class="choosebtn">
					<view class="delbtn flex1">删除</view>
					<view class="restorebtn flex1">复原</view>
				</view>
			</view>
		</u-popup>
		<u-popup :show="editall&&state==0" @close="closeEidt" @open="openEidt" :overlay="false">
			<view class="editbox">
				<view class="chooseall flex6">
					<view class="leftchoose ">
						<radio :checked="quan" @click="makeSureAll" color="#D8AB5A"></radio>
						<text>全选</text>
					</view>
					<view class="anniu">
						<text class="usa" @click="dele()">删除</text>
						<text class="usa" @click="restore()">复原</text>
						<text @click="selectDown" class="usa">完成</text>
					</view>
				</view>
				<view class="choosebtn">
					<view class="delbtn flex1" @click="examineFail()">审核失败</view>
					<view class="restorebtn flex1" @click="examineSuccess()">审核成功</view>
				</view>
			</view>
		</u-popup>
		<tabar checked="supplier"></tabar>
	</view>
</template>

<script>
	let that
	import tabar from "@/componet/tabbar/tabbar.vue"
	export default {
		components: {
			tabar
		},
		data() {
			return {
				keywords:'',
				statusall:0,	
							editall: false,
				quan: false,
				keywords: '',
				show: false,
				dateshow: false,
				creatTime: "请选择",
				endTime: "请选择",
				value1: '',
				intime: 1,
				pageIndex:1,
				total:'',
				nomore:false,
				contract_status: '',
				draft_status: '',
				time_status: '',
				listall: [],
				state: 0,
				ctrstatus: [{
					title: "供应商状态",
					list: [{
							name: "全部",
				
						},
						{
							name: "待审核",
				
						},
						{
							name: "已禁用",
				
						},
						{
							name: "认证完成",
										
						},
						{
							name: "认证失败",
										
						},
						
					]
				}],
			
			}
		},
		onLoad() {
			that=this
			this.state = this.$store.state.admin
			// this.init()
		},
		onShow(){
			that.pageIndex = 1
			that.nomore = false
			that.listall = []
			this.init()
		},
		// 下拉到底部后加载新数据
		    onReachBottom() {
		      //判断下一页是否存在数据，不存在将显示暂无数据等提示语
		      if (this.listall.length >= this.pageIndex * 10) {
		        this.pageIndex++;//页数加一
				this.init();//回调接口
		      }else{
				  this.nomore=true
			  }
		      
		    },
		methods: {
			init() {
				uni.showLoading()
				uni.$u.http.post('/api/Supplier/search', {
					pageIndex: this.pageIndex,
					pageSize: 10,
					// startTime:'',
					// endTime:'',
					name:this.keywords,
					status: this.statusall,
					// contractStatus:'',
					// contractNo:''
				}, {
					custom: {
						auth: true
					}
				}).then((res) => {
					uni.hideLoading()
					this.total=res.total
					let list=res.result
					if(list.length>0){
						list.forEach(item=>{
							item.checked=false
							this.listall.push(item)
						})
						if(list.length<10){
							that.nomore=true
						}
					}
				}).catch((err) => {
					uni.hideLoading()
					console.log(err)
				})
			},
			closeEidt() {
				this.editall = false
			},
			openEidt() {
				this.editall = true
			},
			selectDown() {
				this.editall = false
				this.quan=false
				let list = this.listall
				list.forEach(item => {
					item.checked = false
				})
			},
			close() {
				this.show = false
			},
			open(){
				
			},
			changeSeach(e){
				this.keywords=e.detail.value
				that.pageIndex = 1
				that.nomore = false
				that.listall = []
				this.init()
			},
			choose(title, k) {
				if (title == "供应商状态") {
					this.contract_status = k
					if (k == 2) {
						this.statusall = 4
					} else if (k == 1) {
						this.statusall = 1
					} else if (k == 0) {
						this.statusall = 0
					}else if(k==3){
						this.statusall = 2
					}else if(k==4){
						this.statusall = 3
					}
			
				}
			},
			makeSureSelect() {
				that.pageIndex = 1
				that.nomore = false
				that.listall = []
				this.init()
				this.close()
			},
			restoreALL() {
				this.contract_status = 0
				
			},
			checkBox(id) {
				let list = this.listall
				list.forEach(item => {
					if (item.id == id) {
						item.checked = !item.checked
					}
				})
				this.listall = JSON.parse(JSON.stringify(list))

			},
			selectDown() {
				this.editall=false
				this.quan=false
				let list = this.listall
				list.forEach(item => {
					item.checked = false
				})
			},
			allSelect(){
				let list=this.listall
				console.log(this.quan,778)
				if(this.quan){
					list.forEach(item => {
						item.checked =true
					})
				}else{
					list.forEach(item => {
						item.checked =false
					})
				}
				this.listall = JSON.parse(JSON.stringify(list))
			},
			makeSureAll(){
				this.quan=!this.quan
				this.allSelect()
			},
			chooseDate(e) {
				this.dateshow = false
				const timeFormat = uni.$u.timeFormat
				if (this.intime == 1) {
					this.creatTime = timeFormat(e.value, 'yyyy-mm')
				} else {
					this.endTime = timeFormat(e.value, 'yyyy-mm')
				}

			},
			moveDetail(id) {
				uni.navigateTo({
					url: '/pages/alldeatil/supplierdetail?id=' + id
				})
			},
			addContract() {
				uni.navigateTo({
					url: '/pages/alldeatil/upcontract'
				})
			},
			openDatePicker(e) {
				console.log(e)
				if (e == 1) {
					this.intime = 1
				} else {
					this.intime = 2
				}
				this.dateshow = true
			},
			closeDate() {
				this.dateshow = false
			},
			open() {
				// console.log('open');
			},
			close() {
				this.show = false
				// console.log('close');
			},
			// choose(title, k) {
			// 	if (title == "合同状态") {
			// 		this.contract_status = k
			// 	} else if (title == "汇票状态") {
			// 		this.draft_status = k
			// 	} else if (title == "上传日期") {
			// 		this.time_status = k
			// 	}
			// },
			examineFail(){
				let ids=[]
				that.listall.forEach(item=>{
					if(item.checked){
						ids.push(item.id)
					}
				})
				if(ids.length==0){
					this.$toast("请选择合同")
					return
				}
				uni.showModal({
					title: '提示',
					content: '是否批量审核失败？',
					success: function (res) {
						if (res.confirm) {
							
							uni.showLoading()
							uni.$u.http.post('/api/Supplier/manage', 
							{
								ids:ids,
								operateType:4
							},
							{
								custom: {
									auth: true
								}
							}).then((res) => {
								uni.hideLoading()
								that.editall=false
								that.quan=false
								that.$toast("操作成功")
								setTimeout(()=>{
									that.pageIndex=1
									that.nomore=false
									that.listall=[]
									that.init()
								},500)
							}).catch((err) => {
								uni.hideLoading()
								that.$toast(err.msg)
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
				
			},
			dele(){
				let ids=[]
				that.listall.forEach(item=>{
					if(item.checked){
						ids.push(item.id)
					}
				})
				if(ids.length==0){
					that.$toast("请选择合同")
					return
				}
				uni.showModal({
					title: '提示',
					content:"是否批量删除？",
					success: function (res) {
							if (res.confirm) {
								
								uni.showLoading()
								uni.$u.http.post('/api/Supplier/manage',
								{
									ids:ids,
									operateType:1
								},
								{
									custom: {
										auth: true
									}
								}).then((res) => {
									uni.hideLoading()
									that.editall=false
									that.quan=false
									that.$toast("操作成功")
									setTimeout(()=>{
										that.pageIndex=1
										that.nomore=false
										that.listall=[]
										that.init()
									},500)
									
								}).catch((err) => {
									uni.hideLoading()
									that.$toast(err.msg)
								})
							
							} else if (res.cancel) {
							
							}
						}
				})
				
			},
			restore(){
				let ids=[]
				that.listall.forEach(item=>{
					if(item.checked){
						ids.push(item.id)
					}
				})
				if(ids.length==0){
					that.$toast("请选择合同")
					return
				}
				uni.showModal({
					title: '提示',
					content:"是否批量复原？",
					success: function (res) {
							if (res.confirm) {
								
								uni.showLoading()
								uni.$u.http.post('/api/Supplier/manage',
								{
									ids:ids,
									operateType:2
								},
								{
									custom: {
										auth: true
									}
								}).then((res) => {
									uni.hideLoading()
									that.editall=false
									that.quan=false
									that.$toast("操作成功")
									setTimeout(()=>{
										that.pageIndex=1
										that.nomore=false
										that.listall=[]
										that.init()
									},500)
									
								}).catch((err) => {
									uni.hideLoading()
									that.$toast(err.msg)
								})
							
							} else if (res.cancel) {
							
							}
						}
				})
				
			},
			examineSuccess(){
				let ids=[]
				that.listall.forEach(item=>{
					if(item.checked){
						ids.push(item.id)
					}
				})
				if(ids.length==0){
					that.$toast("请选择合同")
					return
				}
				uni.showModal({
					title: '提示',
					content:"是否批量审核成功？",
					success: function (res) {
							if (res.confirm) {
								
								uni.showLoading()
								uni.$u.http.post('/api/Supplier/manage',
								{
									ids:ids,
									operateType:3
								},
								{
									custom: {
										auth: true
									}
								}).then((res) => {
									uni.hideLoading()
									that.editall=false
									that.quan=false
									that.$toast("操作成功")
									setTimeout(()=>{
										that.pageIndex=1
										that.nomore=false
										that.listall=[]
										that.init()
									},500)
									
								}).catch((err) => {
									uni.hideLoading()
									that.$toast(err.msg)
								})
							
							} else if (res.cancel) {
							
							}
						}
				})
				
			},
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #F6F6F6 !important;
	}

	.headbgbox {
		background-color: #fff;
		padding: 23rpx 31rpx;
		box-sizing: border-box;
		position: fixed;
		top: 0;
		z-index: 999;
		width: 100%;

		.screen {
			display: flex;
			justify-content: center;
			align-items: center;
			padding-left: 30rpx;
		}
	}

	.searchbox {
		padding-left: 30rpx;
		box-sizing: border-box;
		background-color: #ECECEC;
		border-radius: 38rpx;
		// width: 688rpx;
		flex: 1;
		height: 75rpx;
		margin: 0 auto;
		display: flex;
		align-items: center;
		// justify-content: center;
		// margin-top: -10rpx;
	}

	.cardlist {
		display: flex;
		justify-content: center;
		flex-direction: column;
		// align-items: center;
		margin: 0 auto;
		margin-top: 120rpx;
		flex: 1;
	}

	.card {
		margin: 0 auto;
		overflow: hidden;
		// margin-top: 20rpx;

		margin: 0 30rpx;
		flex: 1;
		width: 100%;
		// height: 264rpx;
		border-radius: 20rpx;
		background-color: #fff;
		position: relative;
		box-shadow: 0px 8rpx 20rpx 1rpx rgba(31, 36, 42, 0.08);

		.passreview {
			position: absolute;
			right: 30rpx;
			top: 30rpx;
			width: 141rpx;
			height: 123.5rpx;

			image {
				width: 100%;
				height: 100%;
			}
		}

		.cicle {
			position: absolute;
			width: 40rpx;
			height: 20rpx;
			background-color: #D8AB5A;
			border-radius: 20rpx;
			top: 60rpx;
			left: -20rpx;
		}

		.innerbox {
			padding: 49rpx 0rpx;
			padding-bottom: 30rpx;
			margin: 0 30rpx;
			display: flex;
			align-items: center;

			border-bottom: 1rpx solid #E8E8E8;

			.listicon {
				width: 32rpx;
				height: 36rpx;

				image {
					width: 100%;
					height: 100%;
				}
			}
		}

		.cardtitle {
			font-size: 32rpx;
			font-weight: 600;
			padding-left: 10rpx;
		}

		.timebox {
			background-color: #FFF8E5;
			width: 100%;
			padding: 0 30rpx;
			box-sizing: border-box;
			color: #D8AB5A;
			font-size: 28rpx;
			height: 60rpx;
			line-height: 60rpx;
		}

		.contractmsg {
			padding: 30rpx;
			box-sizing: border-box;
			color: #68625B;
			font-size: 26rpx;
		}
	}


	.totalmanage {
		margin-top: 90rpx;
		margin-bottom: 100rpx;
		// position: fixed;
		bottom: 0;
		display: flex;
		justify-content: space-between;
		align-items: center;
		width: 100%;
		padding: 0 30rpx;
		box-sizing: border-box;

		.managebox {
			width: 23.8rpx;
			height: 29.7rpx;

			image {
				width: 100%;
				height: 100%;
			}
		}

		.maboxtitls {
			width: 160rpx;
			height: 60rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			border-radius: 30rpx;
			background-color: #D9D9D9;
			// line-height: 60rpx;
			font-size: 28rpx;
			box-sizing: border-box;
			// align-items: center;
		}
	}

	.popscreen {
		padding-top: 47rpx;
		height: 1000rpx;
		overflow: auto;

		.checklist {


			.alllistbtn {

				.btntitle {
					padding: 0 30rpx;
					display: block;
					margin: 48rpx 0 30rpx;
					font-size: 32rpx;
					font-weight: 600;
					margin-top: 20rpx;
				}

				.yunbtn {
					display: flex;
					flex-direction: row;
					flex-wrap: wrap;
					margin-left: 30rpx;
				}

				.btnchoose {
					margin-bottom: 30rpx;
					margin-right: 41rpx;
					width: 200rpx;
					height: 68rpx;
					background-color: #F6F6F6;
					border-radius: 34rpx;
					font-size: 26rpx;
					color: #68625B;
					text-align: center;
					line-height: 68rpx;
				}

				.active {
					margin-bottom: 30rpx;
					margin-right: 41rpx;
					width: 200rpx;
					height: 68rpx;
					background-color: #FFF8E5;
					border-radius: 34rpx;
					font-size: 26rpx;
					color: #D8AB5A;
					border: 1rpx solid #D8AB5A;
					text-align: center;
					line-height: 68rpx;
					box-sizing: border-box;
				}
			}
		}

		.custom {
			margin: 50rpx 30rpx;
			margin-top: 20rpx;
			display: flex;
			align-items: center;

			.custombox {
				margin-left: 50rpx;
				flex: 1;

				.creatdata {
					color: #68625B;
					font-size: 28rpx;

					width: 100%;
					margin-bottom: 10rpx;
					padding: 20rpx 0;
					border-bottom: 1rpx solid #E8E8E8;
				}

				.chodatain {
					color: #BEBDBB;
				}
			}
		}

		.aszs {
			padding: 20rpx 0;
			border-top: 1rpx solid #E8E8E8;
			margin: 0 30rpx;
			margin-bottom: 20rpx;
			font-size: 28rpx;

			.againbtn {
				width: 335rpx;
				height: 88rpx;
				line-height: 88rpx;
				text-align: center;
				border-radius: 45rpx;
				border: 1rpx solid #E8E8E8;
			}
		}
	}
</style>
