<template>
	<view style="position: relative;" class="view-box">
		<view class="box">
			<view class="box-img">
				<image style="width: 100rpx; height: 50rpx;;" src='https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Test/Upload/Goods/1653464014000_713.png' mode="aspectFill"></image>
			</view>
			<view class="box-bg">
				<input class="uni-input inputM" style='margin-left: 10px;margin-top: 5px;' v-model="rules.StuName"
					placeholder="请输入学员姓名" maxlength="5" />
			</view>
			<view class="box-bg">
				<view>性别</view>
				<view class="xingbie">
					<text v-for="(item, i) in goodsist" :key="i" @click="gende(item,i)"
						:class="[index==i?'gender':'gender2'] ">{{item.name}}</text>
				</view>
			</view>
			<view class="box-bg" @click="calendar()">
				<input class="uni-input inputM" style='margin-left: 10px;margin-top: 5px;' v-model="rules.StuBirth"
					placeholder="公历生日" />
				<view>
					<u-icon name="arrow" color="#9F9F9F" size="20"></u-icon>
				</view>
			</view>
			<view class="box-bg">
				<input type="number" class="uni-input inputM" style='margin-left: 10px;margin-top: 5px;'
					v-model="rules.StuTel" placeholder="请输入手机号" maxlength="11" />
			</view>
			<view class="box-bg">
				<input class="uni-input inputM" style='margin-left: 10px;margin-top: 5px;' v-model="rules.BaseCondition"
					placeholder="就读学校" />
				<view>
					<u-icon @click="school()" name="arrow" color="#9F9F9F" size="20"></u-icon>
				</view>
			</view>
			<view class="box-bg" @click="gradess()">
				<input maxlength="0" readonly="readonly" class="uni-input inputM"
					style='margin-left: 10px;margin-top: 5px;' v-model="rules.DemandPoint" placeholder="就读年级" />
				<view>
					<u-icon name="arrow" color="#9F9F9F" size="20"></u-icon>
				</view>
			</view>
			<view class="box-bg" @click="community()">
				<input maxlength="0" class="uni-input inputM" readonly="readonly"
					style='margin-left: 10px;margin-top: 5px;' v-model="rules.School_Id" placeholder="报名校区" />
				<view>
					<u-icon name="arrow" color="#9F9F9F" size="20"></u-icon>
				</view>
			</view>
			<view class="box-bg">
				<input class="uni-input inputM" style='margin-left: 10px;margin-top: 5px;'
					v-model="rules.ConsultingResults" placeholder="如何知道进阶思维" />
			</view>
			<!-- 日历弹窗 -->
			<uni-calendar v-show="show"  ref="calendar" :insert="false" @confirm="confirm" @close="close"  />
		</view>
		<!-- 学校弹窗 -->
		<u-popup v-model="show2" mode="right" length="80%">
			<view class="school-bg">
				<text>
					<!-- <u-icon name="arrow-left" size="20"></u-icon> -->
					<text class="school font24">选择就读学校</text>
				</text>
			</view>
			<!-- <view class="search">
				<u-search placeholder="请输入名称" v-model="keyword"></u-search>
			</view> -->
			<scroll-view scroll-y="true" style="height:100%;">
				<view class="list" :class="[actuve==i?'list2':'']" v-for="(item, i) in schoollist" :key="i"
					@click="masklist(item.Content,i)">
					<view>
						{{item.Content}}
					</view>
					<view v-if="actuve==i">
						<u-icon name="success" size="20"></u-icon>
					</view>
				</view>
			</scroll-view>
		</u-popup>
		<!-- 年级弹窗 -->
		<u-popup v-model="show3" mode="bottom" length="auto">
			<scroll-view scroll-y="true" style="height:400rpx;">
				<view v-for="(item, i) in DemandPoint" :key="i">
					<view class="list" :class="[actuve3==i?'list2':'']" @click="grades(item.Content,i)">
						<view>{{item.Content}}</view>
						<view v-if="actuve3==i">
							<u-icon name="success" size="20"></u-icon>
						</view>
					</view>

				</view>
			</scroll-view>
		</u-popup>
		<!-- 校区弹窗 -->
		<u-popup v-model="show4" mode="right" length="80%">
			<view class="school-bg">
				<text>
					<!-- <u-icon name="arrow-left" size="20"></u-icon> -->
					<text class="school font24">选择校区</text>
				</text>
			</view>
			<!-- <view class="search">
				<u-search placeholder="请输入名称" v-model="keyword"></u-search>
			</view> -->
			<scroll-view scroll-y="true" style="height:100%;">
				<view class="list" :class="[actuve2==i?'list2':'']" v-for="(item, i) in campus" :key="i"
					@click="masklist2(item,i)">
					<view>
						{{item.SName}}
					</view>
					<view v-if="actuve2==i">
						<u-icon name="success" size="20"></u-icon>
					</view>
				</view>
			</scroll-view>
		</u-popup>
		<!-- 提交 -->
		<view class="submit-box" @click="submit()">
			<view class="submit-bo2">提交</view>
		</view>
	</view>
</template>

<script>
	var testCmd = "";
	var postMsg = {};
	export default {
		data() {
			return {
				u: {},
				School_Id: '', //要传的校区id
				schoollist: [], //学校
				DemandPoint: [], //班级
				campus: [], //校区
				Type: '',
				communitys: false,
				actuve: -1,
				actuve2: -1,
				actuve3: -1,
				show: false, //日历
				show2: false, //学校
				show3: false, //年级
				show4: false, //社区
				mode: 'date',
				rules: {
					StuName: '',
					StuSex: '0',
					StuBirth: '',
					BaseCondition: '',
					DemandPoint: '',
					School_Id: '',
					StuTel: '',
					ConsultingResults: ''
				},
				goodsist: [{
						name: '男',
						id: '0',
					},
					{
						name: '女',
						id: "1"
					}
				],
				index: 0
			}
		},
		created() {
			this.u = uni.getStorageSync("mall_UserInfo");
		},
		methods: {
			// 提交表单
			registered() {
				let that = this;
				testCmd = "/api/WeChatPublic/CreateMallStudent";//WeChatPublic/CreateStudent
				postMsg = {
					OpenId: that.u.OpenId, //	openId	是	[string]		查看
					UnionId: that.u.Unoinid,
					StuSex: that.rules.StuSex, //	学生性别 0男 1女	是	[string]		查看
					StuName: that.rules.StuName, //	学生姓名	是	[string]		查看
					StuBirth: that.rules.StuBirth, //	学生生日	是	[string]		查看
					StuTel: that.rules.StuTel, //	手机号码	是	[string]		查看
					BaseCondition: that.rules.BaseCondition, //	就读学校	是	[string]		查看
					DemandPoint: that.rules.DemandPoint, //	班级	是	[string]		查看
					ConsultingResults: that.rules.ConsultingResults, //	如何知道进阶思维	是	[string]		查看
					School_Id: that.School_Id, //	校区	是	[string]	
					// School_Id: that.rules.School_Id, //	校区	是	[string]	
					Group_Id: "100001"
				};
				that.requestJJSWAdmin(testCmd, postMsg,
					(res) => {
						if (res.data.Code == 1) {
							// uni.showToast({
							// 	title: '提交成功',
							// 	icon: 'exception',
							// 	duration: 2000
							// });
							uni.navigateBack({
								delta: 1
							});
						} else {
							uni.showToast({
								title: res.data.Message,
								position: 'bottom',
								icon: 'none',
								duration: 2000
							});
						}
					}
				);
			},
			initlist() {
				let that = this;
				that.requestJJSWAdmin(testCmd, postMsg,
					(res) => {
						if (postMsg.Type == 1) {
							that.schoollist = res.data.Data
						} else if (postMsg.Type == 2) {
							that.DemandPoint = res.data.Data
						} else if (that.show4) {
							that.campus = res.data.Data
						}
					}
				);
			},
			submit() {
				let patt = /^[1][3-9][\d]{9}/
				if (this.rules.StuName == '') {
					uni.showToast({
						title: '请填写姓名',
						position: 'bottom',
						icon: 'none',
						duration: 2000
					});
				} else if (this.rules.StuTel == '') {
					uni.showToast({
						title: '请输入手机号',
						position: 'bottom',
						icon: 'none',
						duration: 2000
					});
				} else if (!patt.test(this.rules.StuTel)) {
					uni.showToast({
						title: '请输入正确的手机号码',
						position: 'bottom',
						icon: 'none',
						duration: 2000
					});
				} else {
					this.registered()
				}
			},
			confirm(e) {
				console.log(e);
				this.show = false
				this.rules.StuBirth = e.fulldate
			},
			gende(item, i) {
				this.index = i
				this.rules.StuSex = item.id
			},
			calendar() {
				this.show = true
				this.$refs.calendar.open();
			},
			close() {
				this.show = false
				console.log('弹窗关闭');
			},
			// 学校
			school() {
				testCmd = "/api/WeChatPublic/GetStuSchoolClass";
				postMsg = {
					Type: 1
				};
				this.initlist()
				this.show2 = true
			},
			masklist(item, i) {
				this.actuve = i
				this.rules.BaseCondition = item
				this.show2 = false
			},
			gradess() {
				testCmd = "/api/WeChatPublic/GetStuSchoolClass";
				postMsg = {
					Type: 2
				};
				this.initlist()
				this.show3 = true
			},
			// 年级
			grades(item, i) {
				this.actuve3 = i
				this.rules.DemandPoint = item
				this.show3 = false
			},
			community() {
				testCmd = "/api/WeChatPublic/GetSchoolList";
				postMsg = {
					Group_Id: ""
				};
				this.initlist()
				this.show4 = true
			},
			masklist2(item, i) {
				this.actuve2 = i
				this.rules.School_Id = item.SName
				this.School_Id = item.SId
				this.show4 = false
			},
		},
	}
</script>

<style>
	.uni-input {
		margin-left: 0rpx !important;
	}

	.school {
		font-size: 22rpx;
	}

	.school.font24{
		font-size: 24rpx;
	}

	.search {
		margin-bottom: 20rpx;
	}

	.view-box {
		padding-top: 40rpx;
		background-color: #EEF1FA;
		min-height: 100vh;
	}

	.submit-box {
		/* margin-top: 50rpx; */
		width: 80%;
		display: flex;
		justify-content: center;
		font-size: 22rpx;
		color: #fff;
		position: fixed;
		bottom: 190rpx;
		left: 50%;
		transform: translate(-50%, 0%);
		background-color: #138BF9;
		border-radius: 10rpx;
		height: 60rpx;
		align-items: center;
	}

	.list2 {
		color: #138BF9;
	}
	
	.list {
		display: flex;
		justify-content: space-between;
		align-items: center;
		border-bottom: solid 1px #D9D9D9;
		padding:20rpx 0;
		padding-left: 20rpx;
		padding-right: 20rpx;
		font-size: 24rpx;
	}

	.box {
		width: 90%;
		border-radius: 10rpx;
		margin-top: 50rpx;
		background: #FFFFFF;
		padding-left: 20rpx;
		padding-right: 20rpx;
		margin: auto;
		padding-bottom: 80rpx;
		border-radius: 20rpx;
	}

	.school-bg {
		background-color: #EEF1FA;
		padding: 20rpx 0;
		display: flex;
		align-items: center;
		padding-left: 50rpx;
		margin-bottom: 20rpx;
	}

	.xingbie {
		width: 185rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.gender {
		border: 10rpx;
		background-color: #E5F3FE;
		width: 80rpx;
		height: 20px;
		display: inline-block;
		text-align: center;
		line-height: 20px;
		border-radius: 5rpx;
		font-size: 22rpx;
	}

	.gender2 {
		border: 10rpx;
		background-color: #5455;
		width: 80rpx;
		height: 20px;
		display: inline-block;
		text-align: center;
		line-height: 20px;
		border-radius: 5rpx;
		font-size: 22rpx;
	}

	.box-bg {
		border-radius: 10rpx;
		border: 1px solid #9F9F9F;
		margin-bottom: 20rpx;
		height: 60rpx;
		line-height: 60rpx;
		display: flex;
		align-items: center;
		padding-left: 20rpx;
		justify-content: space-between;
		padding-right: 20rpx;
	}

	.box-img {
		display: flex;
		justify-content: center;
		padding-top: 50rpx;
		margin-bottom: 20rpx;
	}
</style>
