<template>
	<view class="page">
		<view class="content">
			<view class="checked" v-for="(item,index) in checkList">
				<view class="checked-box">
					<view class="checked-img">
						<image :src="item.img" mode=""></image>
					</view>
					<view class="checked-text">
						<view class="checked-name">{{item.nickname}}</view>
						<view class="checked-phone">{{item.phone}}</view>
					</view>
				</view>
				<!-- <radio value="1" :checked="xuanze==='1'" @click="checked('1')"></radio> -->
				<view class="">
					<radio @click="click(item,index)" :key="index" :checked="isChange == index" color="#6EAB4E">
					</radio>
				</view>
			</view>
		</view>
		<view class="button" @click="navJiedian()">
			确认
		</view>
	</view>
</template>
<script>
	// import {
	// 	getReferralList
	// } from '@/api/user.js';
	// import{ getReferralList}
	// import {
	// 	getChooseList
	// } from '@/api/user.js';
	import {
		getChooseList,
		addJiedian
		
	} from '@/api/user.js'
	export default {
		data() {
			return {
				parent_area:'',
				patent:'',
				uid: '',
				wuyue: [],
				isChange: -1, //单选
				checkList: [{
						img: '',
						name: '',
						phone: '',
					}
				]
			}
		},
		onLoad(option) {
			// this.getChoosesList()
			this.getla()
			console.log(option)
			this.parent_area = option.parent_area
			this.patent = option.patent
			
			
		},
		methods: {
			getla() {
				let obj = this
				getChooseList().then(res => {
					console.log(res, '11111')
					obj.checkList = res.data.data
				})
			},
			//判断当前index是否与ischange相等，再次点击取消
			click(item,index) {
				console.log(item,'item')
				this.uid = item.uid
				this.isChange = index
			},
			navJiedian(){
				if(this.uid == '') {
					return this.$api.msg('请选择用户')
				}
				console.log(this.patent,this.parent_area,'dddddddddddddddddddd')
				addJiedian({
					patent:this.patent ,
					parent_area: this.parent_area,
					uid: this.uid,
				}).then(res=>{
					this.$api.msg(res.msg)
					console.log(res,'11122344')
					this.$api.prePage().loadData()
					setTimeout(()=> {
						uni.navigateBack({})
					},1000)
					
				})
			
			}
		}
	}
</script>
<style lang="scss">
	page {
		padding: 0;
		margin: 0;
		height: 100%;
		background-color: #F8F6F6;

		.page {
			display: flex;
			flex-direction: column;
			align-items: center;
		}

		.button {
			margin-top: 60rpx;
			width: 699rpx;
			height: 90rpx;
			border-radius: 45px;
			text-align: center;
			line-height: 70rpx;
			height: 70rpx;
			background: #6EAB4E;
			font-size: 28rpx;
			font-weight: 500;
			color: #FFFFFF;


		}

		.content {
			width: 100%;
			display: flex;
			flex-wrap: nowrap;
			flex-direction: column;
			margin-top: 20rpx;
			background-color: #FFFFFF;

			.checked {
				height: 130rpx;
				margin: 0 30rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;

				.checked-box {
					display: flex;

					.checked-img {
						width: 80rpx;
						height: 80rpx;
						border-radius: 50%;
						overflow: hidden;

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

					.checked-text {
						margin-left: 20rpx;
						display: flex;
						flex-direction: column;
						justify-content: space-between;

						.checked-name {
							font-size: 30rpx;
							font-weight: 500;
							color: #3F454B;
						}

						.checked-phone {
							font-size: 22rpx;
							font-weight: 400;
							color: #999999;
						}
					}
				}
			}
		}
	}
</style>
