<template>
	<view class="content">
		<view class="" style="height: 20rpx;">

		</view>
		<view class="tab">
			<view class="bd-wrap flex">
				<view class="bg-name">
					姓名:
				</view>
				<view class="bg-val">
					<input type="text" value="" placeholder="请输入您的姓名" class="val-ipt" v-model="name" ref="name" />
				</view>
			</view>
			<view class="bd-wrap flex">
				<view class="bg-name">
					联系方式:
				</view>
				<view class="bg-val">
					<input type="text" value="" placeholder="请输入您的联系方式" class="val-ipt" v-model="phone" ref="phone" />
				</view>
			</view>
			<!-- <pickerAddress class="input" @change="onCityClick">{{addressDetail||'请选择地址'}}</pickerAddress> -->
			<view class="bd-wrap flex">
				<view class="bg-name">
					所在地区:
				</view>
				<view class="bg-val">
					<pickerAddress class="input" @change="onCityClick">{{address||'请选择地址'}}</pickerAddress>
				</view>
			</view>
			<view class="bd-wrap flex">
				<view class="bg-name">
					详细地址:
				</view>
				<view class="bg-val">
					<input type="text" value="" placeholder="请输入详细地址" class="val-ipt" v-model="addressDetail"
						ref="address" />
				</view>
			</view>
			<view class="bd-wrap flex">
				<view class="bg-name">
					店名或公司名称:
				</view>
				<view class="bg-val">
					<input type="text" value="" placeholder="请输入店名或公司名称" class="val-ipt" v-model="storename"
						ref="storenamae" />
				</view>
			</view>
			<view class="bd-wrap flex" v-if="!userInfo.spread_uid">
				<view class="bg-name">
					推荐人:
				</view>
				<view class="bg-val">
					<input type="text" value="" placeholder="请输入推荐人UID(可选填)" class="val-ipt" v-model="spread"
						ref="storenamae" />
				</view>
			</view>
			<view class="bd-wrap flex">
				<view class="bg-name">
					等级:
				</view>
				<view class="bg-val">
					<picker @change="bindLevelChange" :value="index" :range="levelList" mode="selector"
						range-key="name">
						<view class="val-ipt ">{{chooseLevel.name||'请选择等级'}}</view>
					</picker>
				</view>
			</view>

		</view>
		<view class="btm-btn" @click="enroll">
			提交申请
		</view>
	</view>
</template>
<script>
	import pickerAddress from '@/components/wangding-pickerAddress/wangding-pickerAddress.vue';
	import {
		enroll
	} from '@/api/index.js'
	import {
		getLevelList,
	} from '@/api/user.js'
	import {
		mapState,
		mapMutations
	} from 'vuex';
	export default {
		components: {
			pickerAddress
		},
		data() {
			return {
				levelList: [],
				index: 0,
				chooseLevel: '',
				name: '',
				phone: '',
				address: '',
				storename: '',
				spread: '',
				addressDetail: '',
				loading: false,
			};
		},
		onLoad(opt) {
			this.getLevelList()
		},
		onShow() {

		},
		onReachBottom() {

		},
		computed: {
			...mapState('user', ['userInfo'])
		},
		methods: {
			// 选中城市切换
			onCityClick({
				data
			}) {
				// let address = this.addressData.address;
				// address.province = data[0];
				// address.city = data[1];
				// address.district = data[2];
				this.address = data.join('-');
			},
			getLevelList() {
				getLevelList().then(res => {
					this.levelList = res.data
				})
			},
			bindLevelChange(e) {
				console.log(e)
				this.chooseLevel = this.levelList[e.detail.value]
			},
			enroll() {
				let that = this
				console.log('bin');
				if (that.loading) {
					return
				}
				if (that.name == '') {
					return that.$api.msg('请输入您的姓名')
				}
				if (that.phone == '') {
					return that.$api.msg('请输入您的联系方式')
				}
				console.log(that.chooseLevel, '123456');
				if (!that.chooseLevel) {
					return that.$api.msg('请选择你的等级')
				}
				that.loading = true
				enroll({
					uid: that.userInfo.uid,
					name: that.name,
					phone: that.phone,
					address: that.address,
					storename: that.storename,
					spread: that.spread,
					addressDetail: that.addressDetail,
					level: that.chooseLevel.id,
					level_name: that.chooseLevel.name
				}).then(res => {
					console.log(res);
					uni.showToast({
						title: '提交成功',
						duration: 2000
					});
					setTimeout(() => {
						uni.switchTab({
							url: '/pages/user/user'
						})
						that.loading = false
					}, 1500)

				}).catch(err => {
					console.log('err');
					that.loading = false
				})
			}
		}
	};
</script>
<style lang="scss" scoped>
	.tab {
		width: 690rpx;
		margin: auto;
		// height: 606rpx;
		background: #FFFFFF;
		border-radius: 10rpx;
	}

	.bd-wrap {
		width: 690rpx;
		// height: 100rpx;
		padding: 20rpx 0;
		background-color: #fff;
		border-bottom: 1px solid #f2f2f2;
		// line-height: 100rpx;
		font-size: 32rpx;
		position: relative;

		.code {
			position: absolute;
			width: 100rpx;
			height: 100rpx;
			right: 10rpx;
			color: #f64342;
			font-size: 23rpx;
		}

		.bg-name {
			width: 280rpx;
			height: 100%;
			padding-left: 20rpx;
		}

		.bg-val {
			width: 430rpx;
			height: 100%;

			.val-ipt {
				display: inline-block;
				width: 100%;
				height: 100%;
				// background-color: #009100;
				padding-left: 10rpx;

			}
		}
	}

	.btm-btn {
		margin: 105rpx auto 0;
		width: 654rpx;
		height: 82rpx;
		background: linear-gradient(180deg, #3C82E6, #5395F5);
		border-radius: 10rpx;
		font-size: 34rpx;
		font-weight: 500;
		color: #FFFFFF;
		text-align: center;
		line-height: 82rpx;
	}
</style>