<template>
	<view class="center">
		<view v-for="(item , index) in lists" :Key="index">
			<view>
				<view class="company">{{item.customerType}}</view>
				<view class="guess-item" @click="navToDetailPage(item)">
					<view class="infos">

						<view class="info">{{item.customerName}}
							<view class='cu-tag radius line-pink but'>{{item.authenticationStatus}}</view>
						</view>
						<view class="info">{{item.customerPhone}}</view>
						<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>
	</view>

	</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,
				checked:false,
				goodsName:'',
				receivePrivate:'',
				receiveCity:'',
				receiveArea:'',
				minimumVolume:'',
				basis:'',
				buyer:'',
				unitPrice:'',
				receiveWarehouse:'',
				procurementPlanType:'',
				procurementPlan:'',
				identityAuthenticationInfo: {
					pageSize: 10,
					currentPage: 1,
					commonId: "",
					
					
				},
			};
		},
		onShow(){
			this.getList()
		},
		onLoad(options) {
			this.goodsName = options.goodsName
			this.receivePrivate = options.receivePrivate
			this.receiveCity = options.receiveCity
			this.receiveArea = options.receiveArea
			this.minimumVolume = options.minimumVolume
			this.buyer = options.buyer
			this.basis = options.basisPrice
			this.unitPrice = options.unitPrice
			this.receiveWarehouse = options.receiveWarehouse
			this.procurementPlanType = options.procurementPlanType
			this.procurementPlan=options.procurementPlanNo
		},
		computed: {
			...mapState(['hasLogin', 'userInfo'])
		},
		methods: {
			getList() {
				this.identityAuthenticationInfo.commonId = this.userInfo.id
				this.$api.doRequest('get', '/identityAuthenticationInfo/selectIdentityAuthenticationInfo', {
						pageSize: 10,
						currentPage: 1,
						commonId: this.userInfo.id
					}, '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) {
				// if (index == 1) {
					if(item.customerTypeFlag==1){
						uni.navigateTo({
						url: `/pageD/myRelease/buyGrain?id=${item.id}&customerName=${item.customerName}`
					})
					}else{
						uni.navigateTo({
							url: `/pageD/myRelease/buyGrain?id=${item.id}&customerName=${item.compName}`
						})
					}
					
					},
				// } else {
				// 	uni.navigateTo({
				// 		url: `/pageD/identity/driverIdentityLook`
				// 	})
				

			// }
		}
	}
</script>

<style>
	.center {
		padding: 10px 20px;
	}

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

	.company {
		font-size: 16px;
		margin-top: 10px;
	}

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

	.info {
		line-height: 20px;
	}

	.but {
		right: 3px;
		float: right;
	}
</style>
