<style lang="scss" scoped>
	.bindsale  {
		width: 100%;
		// height: 100vh;
		background-color: #FAFAFA;
		.box{
			width: 100%;
			padding: 0 15px;
		}
		.box-item{
			width: 100%;
			margin-top: 40rpx;
			
		}
		.box-item-top{
			display: flex;
			align-items: center;
			font-size: 24rpx;
			color: #111111;
			
		}
		.imgstb{
			width: 11px;
			height: 15px;
			margin-right: 5px;
		}
		
		.box-item-b{
			width:100%;
			height:55px;
			border-bottom:1px solid #E2E2E2;
			display: flex;
			align-items: center;
			justify-content: space-between;
			input{
				margin-left: 15px;
			}
		}
		.yanbtn{
			width: 170rpx;
			height: 60rpx;
			border-radius: 4px;
			display: flex;
			align-items: center;
			justify-content: center;
			border: 1px solid #E2E2E2;
			font-size: 24rpx;
			color: #40766E;
		}
		.tijiao{
			width: 100%;
			height: 40px;
			background: #40766E;
			border-radius: 4px;
			margin-top: 100px;
			font-size: 14px;
			color: #FFFFFF;
			display: flex;
			align-items: center;
			justify-content: center;
		}
	}
	.successStatus{
		width: 700rpx;
		// height: 449rpx;
		background-color: #FFF;
		margin-top: 60rpx;
		box-shadow: 0rpx 6rpx 30rpx 0rpx rgba(139, 115, 64, 0.06);
		border-radius: 12rpx;
		padding-top: 50rpx;
		.info{
			margin: 0 auto;
			text-align: center;
			margin-bottom: 30rpx;
			font-family: PingFang SC;
		}
		.headimg{
			width: 140rpx;
			height: 140rpx;
			border-radius: 50%;
			background-color: #eee;
			overflow: hidden;
		}
		.name{
			font-size: 40rpx;
			font-weight: bold;
			color: #111111;
		}
		.work{
			font-size: 22rpx;
			font-weight: 500;
		}
		.department{
			width: 140rpx;
			height: 40rpx;
			background-color: #40766E;
			color: #FFFFFF;
			border-radius: 8rpx;
			line-height: 38rpx;
			font-size: 22rpx;
			font-weight: 500;
			padding: 0 20rpx;
		}
		.knowBtn{
			width: 620rpx;
			height: 80rpx;
			background-color: #40766E;
			border-radius: 8rpx;
			font-size: 28rpx;
			font-weight: 500;
			color: #FFFFFF;
			position: fixed;
			left: 50%;
			transform: translateX(-50%);
			bottom: 90rpx;
			text-align: center;
			line-height: 78rpx;
		}
	}
</style>
<template>
	<div  class='bindsale'>
		<view class="box" v-if="isBindSell===0">
			<view style="font-size: 40rpx;color: #111111;margin-top: 40rpx;">请完成销售绑定验证</view>
			<!-- <view style="font-size: 24rpx;color: #999999;margin-top: 20rpx;">请获取验证码进行绑定</view> -->
			<view class="box-item" style="margin-top: 70rpx;">
				<view class="box-item-top">
					<image src="https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Static/Jhdianhua.png" class="imgstb"></image>
					<text>账号</text>
				</view>
				<view class="box-item-b">
					<input type="number" v-model="addMsg.EduSellAccount" placeholder="请输入你的账号">
				</view>
			</view>
			<view class="box-item">
				<view class="box-item-top">
					<image src="https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Static/Jhyanzm.png" class="imgstb"></image>
					<text>密码</text>
				</view>
				<view class="box-item-b" >
					<input  password v-model="addMsg.password" placeholder="请输入你的密码">
					<!-- <view class="yanbtn"  @click="getCode">{{show == true?btntext:daojis}}</view> -->
				</view>
			</view>
			<view class="box-item">
				<view class="box-item-top">
					<image src="https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Static/Jhyanzm.png" class="imgstb"></image>
					<text>身份</text>
				</view>
				<view class="box-item-b" >
					<u-radio-group v-model="addMsg.EduType">
						<u-radio shape="circle" :name="1">内部员工</u-radio>
						<u-radio shape="circle" :name="2">学生</u-radio>
					</u-radio-group>
				</view>
			</view>
			<view class="tijiao" @click="tj()">
				提交绑定
			</view>
		</view>
		<view v-if="isBindSell===1" style="width: 100%;display: flex;flex-direction: column;align-items: center;">
			<!-- <image src="https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Static/Jhrenzcg.png" style="width: 300rpx;height: 324rpx;margin-top: 256rpx;"></image> -->
			<!-- <text style="font-size: 20px;color: #111111;margin-top: 53px;">验证成功  成为学员</text> -->
			<view class="successStatus">
				<view class="headimg info" v-if="sellInfo.Type==1">
					<image style="width: 100%;height: 100%;" :src="sellInfo.UserIcon" mode="aspectFill"></image>
				</view>
				<view class="info name">
					{{sellInfo.EmployeeName}}
				</view>
				<view class="info work">
					{{sellInfo.PostName}}
				</view>
				<view class="info department" v-if="sellInfo.Type==1">
					{{sellInfo.DeptName}}
				</view>
				<view class="info work">
					<text v-if="sellInfo.Type==1" style="margin-left:20rpx">内部员工</text>
					<text v-if="sellInfo.Type==2" style="margin-left:20rpx">学生</text>
				</view>
				<view class="knowBtn" @click="gbAuth">
					我知道了
				</view>
			</view>
		</view>
		<auth v-if="showAuth" @changeuserinfo="reloadUserinfo" @gbAuth= 'gbAuth'></auth>
	</div>
</template>

<script>
	
	
	import auth from "@/components/auth/index.vue";
	export default {
		components: {
			auth
		},
		data() {
			return {
				showAuth:false,
				u:{},
				mainColor: '',
				addMsg:{
					EduSellAccount:'',
					password:'',
					EduType:1,
				},
				btntext:'获取验证码',
				show: true,
				count: '',
				timer: null,
				daojis:'60s',
				isAttestationEdu:0,//学员是否认证了 0否1是
				isBindSell:0,//是否绑定了销售，0否1是
				sellInfo:{}
			}
		},
		onLoad(options) {
			this.u = uni.getStorageSync("mall_UserInfo");
			if (!this.u) {
			  this.u = {
				nickName: "未登录",
				avatarUrl: ""
			  };
			  this.showAuth = true;
			}	else{
				this.getBindStatus()
			}
			// let basedata =uni.getStorageSync("basedata")?uni.getStorageSync("basedata"):'';
			// this.isAttestationEdu = basedata.user_info.isAttestationEdu ? basedata.user_info.isAttestationEdu:0
		},
		created() {
			this.mainColor = this.$uiConfig.mainColor;
		},
		mounted() {
			let pageTitle = '绑定销售'
			let currentPages = getCurrentPages();
			let u = "/" + currentPages[currentPages.length - 1].route;
			let pages = wx.getStorageSync("basedata") ?
				wx.getStorageSync("basedata").bar_title : [];
				pages.forEach((x) => {
					if (x.value == u) {
						pageTitle = x.new_name ? x.new_name : x.name;
					}
				});
			uni.setNavigationBarTitle({
				title: pageTitle,
			});
		},
		methods: {
			
			// getCode(){
			// 	const TIME_COUNT = 60;
			// 	if(this.addMsg.StuTel==''){
			// 		uni.showToast({
			// 			title:'请输入手机号码',
			// 			icon:'none'
			// 		})
			// 		return
			// 	}
			// 	if(this.show==true){
			// 		if (!this.timer) {
			// 			this.getcodedata()//获取验证码
			// 		  this.count = TIME_COUNT;
			// 		  this.show = false;
			// 		  this.timer = setInterval(() => {
			// 		  if (this.count > 0 && this.count <= TIME_COUNT) {
			// 			 this.count--;
			// 			 this.daojis = this.count+'s'
			// 			} else {
			// 			 this.show = true;
			// 			 clearInterval(this.timer);
			// 			 this.timer = null;
			// 			 this.btntext = '重新获取'
			// 			 this.daojis = '60s'
			// 			}
			// 		  }, 1000)
			// 		 }
			// 	}else{
			// 		console.log('不能操作')
			// 	}
				 
			// },
			// getcodedata(){
			// 	this.request2({
			// 			url: '/api/AppletEducation/SendCodeByStudentInfo',
			// 			data: {StuTel:this.addMsg.StuTel}
			// 		},
			// 		res => {
			// 			if (res.resultCode == 1) {
			// 				uni.showToast({
			// 					title:'短信已发送,注意查收！',
			// 					icon:'none'
			// 				})
			// 			}
			// 		},
			// 		error=>{
			// 			this.show = true;
			// 			clearInterval(this.timer);
			// 			this.timer = null;
			// 			this.btntext = '重新获取'
			// 			this.daojis = '60s'
			// 		}
			// 	);
			// },
			//获取绑定状态
			getBindStatus(){
				this.request2({
						url: '/api/AppletEducation/GetBindEduSellInfo',
						data: {}
					},
					res => {
						console.log(295,res)
						if (res.resultCode == 1) {
							if(res.data.Id>0){
								this.sellInfo=res.data
								this.isBindSell=1
							}else{
								this.isBindSell=0
							}
						}
					},
					error=>{
						uni.hideLoading()
					}
				);
			},
			tj(){
				if (!this.u) {
				  this.u = {
					nickName: "未登录",
					avatarUrl: ""
				  };
				  this.showAuth = true;
				  uni.showToast({
				  	title:'请登录账号',
				  	icon:'none'
				  })
				  return
				}	
				if(this.addMsg.EduSellAccount==''){
					uni.showToast({
						title:'请输入账号',
						icon:'none'
					})
					return
				}
				if(this.addMsg.password==''){
					uni.showToast({
						title:'请输入密码',
						icon:'none'
					})
					return
				}
				uni.showLoading({
				    title: '认证中'
				});
				this.request2({
						url: '/api/AppletEducation/GetBindEduSell',
						data: this.addMsg
					},
					res => {
						uni.hideLoading()
						if (res.resultCode == 1) {
							uni.showToast({
								title:res.message,
								icon:'none'
							})
							this.getBindStatus()
							this.getHome()
						}
					},
					error=>{
						uni.hideLoading()
					}
				);
			},
			
			
			reloadUserinfo() {
			  this.u = uni.getStorageSync("mall_UserInfo");
			  // this.showAuth=false;
				this.getHome();
				this.getBindStatus();
			},
			//关闭登录窗口
			gbAuth(){
				uni.navigateBack()
			},
			getHome(){
				this.request2({
						url: "/api/Mall/GetHome",
						data: {page_id: 0,open_school: 0,StoreId: 0},
					},
					(res) => {
						uni.setStorageSync("basedata", res.data);
						let basedata = wx.getStorageSync("basedata")
						this.isAttestationEdu = basedata.user_info.isAttestationEdu ? basedata.user_info.isAttestationEdu:0
					},
					(error) => {}
				);
			},
		}
	};
</script>
