<template>
	<view class="center">
		<view v-if='lists.length>0'>
			<view v-for="(item , index) in lists" :Key="index">
				<view @click="navToDetailPage(item)" class="forList">
					<view class="flex">
						<view class="company" v-if="item.customerType == '企业'">{{item.customerType}}</view>
						<view class="company1" v-if="item.customerType == '个人'">{{item.customerType}}</view>
						<view class="infos">
							<view class="info1">
							<text v-if='item.customerTypeFlag==1'>{{item.customerName}}</text>
							<text v-if='item.customerTypeFlag==2'>{{item.compName}}</text>
								<view class='but but1' v-if="item.authenticationStatus == '已认证'">{{item.authenticationStatus}}</view>
								<view class='but but2' v-if="item.authenticationStatus == '审核中'">{{item.authenticationStatus}}</view>
								<view class='but but3' v-if="item.authenticationStatus == '未通过'">{{item.authenticationStatus}}</view>
								<view class='but but4' v-if="item.authenticationStatus == '已覆盖'">{{item.authenticationStatus}}</view>
							</view>
							<view class="info2">{{item.customerPhone}}</view>
						
							
						</view>

					</view>
						<hr style="margin: 10px 0px;">
					<label>
						<checkbox style='transform: scale(0.8);' :value='item.id' :checked="item.checked" @click.stop="checkBox($event,item)" ></checkbox>
						<text>设置默认</text>
					</label>
				</view>
			</view>
		</view>
		
		<view style='text-align:center;' v-else>
			当前暂无已认证的粮商身份
		</view>
	</view>

</template>

<script>
	import {
		mapState
	} from 'vuex';
	export default {
		name: "buy",
		data() {
			return {
				lists:[],
				PageCur: "buy",
				buyInfo: [],
				pages: 1, //页数
				limit: 10, //每次取条目数
				loadStatus: 'loading', //加载样式：more-加载前样式，loading-加载中样式，nomore-没有数据样式
				isLoadMore: false, //是否加载中
				showTran: true,
				scrollTop: 0,
				TabCur: 0,
				current: 1,
				id:0,
				checked:false,
				status:0,
				goodsName:'',
				receivePrivate:'',
				receiveCity:'',
				receiveArea:'',
				minimumVolume:'',
				basis:'',
				buyer:'',
				unitPrice:'',
				receiveWarehouse:'',
				procurementPlanType:'',
				procurementPlan:'',
				identityAuthenticationInfo: {
					pageSize: 10,
					currentPage: 1,
					commonId: "",
					
					
				},
			};
		},
		onLoad(options) {
			this.status=options.status
		},
		onShow(){
			this.getList()
		},
		computed: {
			...mapState(['hasLogin', 'userInfo'])
		},
		methods: {
			getList() {
				console.log(this.userInfo)
				this.identityAuthenticationInfo.commonId = this.userInfo.id
				this.$api.doRequest('get', '/identityAuthenticationInfo/selectIdentityAuthenticationInfo', {
						pageSize: 10,
						currentPage: 1,
						commonId: this.userInfo.id,
						flag:1
					}, 'application/json;charset=UTF-8').then(res => {
						if(res.data.code==200){
							for(var i=0;i<res.data.data.records.length;i++){
								if(res.data.data.records[i].defaultFlag!=1){
									res.data.data.records[i].checked=false
								}else{
									res.data.data.records[i].checked=true
								}
							}
							this.lists = res.data.data.records
						}
					})
					.catch(res => {
						uni.showToast({
							title: res.errmsg,
							icon: 'none',
							duration: 2000
						})
					});
			},
			checkBox(e,item){
				for(var i=0;i<this.lists.length;i++){
					this.lists[i].checked=true
				}
				item.checked=true
				this.$api.doRequest('post', '/identityAuthenticationInfo/api/setDefault', {
						id:item.id,
						commonId: this.userInfo.id
					}).then(res => {
						if(res.data.code==200){
							// this.lists = res.data.data.records
						}
					})
					.catch(res => {
						uni.showToast({
							title: res.errmsg,
							icon: 'none',
							duration: 2000
						})
					});
			},
			// adddriver(index) {
			// 	if (index == 1) {
			// 		uni.navigateTo({
			// 			url: `/pageD/identity/companyIdentity`
			// 		})
			// 	} else {
			// 		uni.navigateTo({
			// 			url: `/pageD/identity/driverIdentity`
			// 		})
			// 	}
			// },
			navToDetailPage(item) {
				console.log(11111)
				var url=''
				if(this.status==1){
					url='/pageD/myRelease/buyGrain'
				}else{
					url='/pageD/myRelease/sellGrain'
				}
				// if (index == 1) {
					if(item.customerTypeFlag==1){
						uni.navigateTo({
						url: url+`?id=${item.id}&customerName=${item.customerName}`
					})
					}else{
						uni.navigateTo({
							url: url+`?id=${item.id}&customerName=${item.compName}`
						})
					}
					
					},
				// } else {
				// 	uni.navigateTo({
				// 		url: `/pageD/identity/driverIdentityLook`
				// 	})
				

			// }
		}
	}
</script>

<style>
	.center {
		padding: 10px 20px;
		background-color: #F5F6FA;
	}

	.title {
		font-size: 18px;
		font-weight: 900;
		margin-right: 20px;
		display: initial;
	}

	.company {
		width: 35px;
		height: 35px;
		background-color: #E9F8F0;
		font-size: 16px;
		margin-top: 10px;
		border-radius: 5px;
		text-align: center;
		line-height: 35px;
		color: #22C572;
		font-size: 12px;
		
	}
	.company1{
		width: 35px;
		height: 35px;
		background-color: #FEECE6;
		font-size: 16px;
		margin-top: 10px;
		border-radius: 5px;
		text-align: center;
		line-height: 35px;
		color:#FE6430;
		font-size: 12px;
	}

	.infos {
		/* margin: 10px 20px; */
		width: 100%;
		display: inline-table;
	}

	.info {
		line-height: 20px;
	}

	.but {
		margin-right: 30px;
		float: right;
		font-size: 14px;
		
		background-color: #FFFFFF;
	}
	.but1{
		color: #22C572 ;
	}
	.but2{
		color:#FE6430;
	}
	.but3{
		color:#FB1E1E;
	}
	.but4{
		color:#AFB3BF;
	}
	.forList{
		background-color: #FFFFFF;
		padding: 10px 10px;
		border-radius: 10px;
		margin-top: 10px;
	}
/* 	.guess-item{
		font-size: 18px;
		margin-left: 20px;
		font-weight: 700;
	} */
	.info1{
		font-size: 18px;
		margin-left: 20px;
		font-weight: 700;
	}
	.info2{
		margin-left: 20px;
		color: #AFB3BF;
	}
</style>
