<template>
	<view class="page">
		<l-input title="学年" placeholder="请填写学年" :value="data.AcademicYearNo" disabled right />
		<l-input title="学期" placeholder="请填写学期" :value="data.Semester" disabled right />
		<l-input title="课程编号" placeholder="请填写课程编号" :value="data.LessonNo" disabled right />
		<l-input title="课程名称" placeholder="请填写课程名称" :value="data.LessonName" disabled right />
		<l-input title="建课教师" placeholder="请填写建课教师" :value="data.EmpNo" disabled right />
		
		<l-input title="建课学校" placeholder="请填写建课学校" :value="data.F_SchoolId" disabled right />

		<l-input title="已报人数" placeholder="请填写已报人数" :value="data.StuNumOfApply" disabled right />
		<view class="btn" @click="fromBtn" v-show="showFlag">报名</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				keyValue: '', //列表页面传参
				data: {},
				param: {}, //列表页面传参-对象
				showFlag: true,
				// 数据源
				dataSource: {
					F_SchoolId: []
				},
			}
		},
		methods: {
			init() {
				//this.keyValue = this.GET_PARAM(); //获取页面传递参数
				// console.log(this.keyValue);

				this.param = this.GET_PARAM();
				//console.log(this.param);
				this.keyValue = this.param.keyValue;
				//审核中或者报名成功不显示报名按钮
				if (this.param.Status == 1 || this.param.Status == 2) {
					this.showFlag = false;
				}

				this.LOADING('加载数据中…');
				this.HTTP_GET('learun/LessonInfoOfElectiveOnline/form', this.keyValue, '加载数据时出错').then(res => {
					this.HIDE_LOADING();
					this.data = res.data;

				});
			},
			fromBtn() {
				var _postData = {}
				// let _this = this;
				let user = this.GET_GLOBAL('loginUser');;
				_postData.keyValue = this.keyValue;
				_postData.StuNo = user.account;
				this.LOADING('正在提交…');
				this.HTTP_POST('learun/LessonInfoOfElectiveOnline/SignInByMobile', _postData, '加载数据时出错').then((res, info,
					code) => {
					//console.log(res)
					if (res) { // 表单数据保存成功
						//判断队列结果
						let timer = setInterval(() => {
							this.HTTP_POST('learun/LessonInfoOfElectiveOnline/GetApplyResult', _postData,
								'报名状态').then(
								(dataresult) => {
									//console.log(dataresult)
									clearInterval(timer);
									if (!dataresult) return
									this.HIDE_LOADING();
									this.EMIT('LessonInfoOfElectiveOnline')
									this.TOAST(dataresult.msg);
									let timer2 = setTimeout(() => {
										clearTimeout(timer2);
										this.NAV_BACK();
									}, 2000);
								});
						}, 5000);
					}
				});

			}

		},
		created() {
			// 拉取加载列表和数据源
			Promise.all([
				this.FETCH_DATASOURCE('company').then(result => {
					this.dataSource.F_SchoolId = result.data.map(t => ({
						text: t.f_fullname,
						value: t.f_companyid
					}))
				}),
				() => {},
			]);
			
			this.init()
		}
	}
</script>

<style lang="less" scoped>
	.txt {
		line-height: 24px;
		font-size: 15px;
		background-color: #fff;
		padding: 10px 0 10px 15px;
	}

	.page {
		background-color: #fff;
		padding-bottom: 1px;
	}

	/deep/ .cu-form-group uni-textarea {
		height: auto;
	}

	.remarks {
		border-bottom: 0.5px solid #eee;
		padding-bottom: 10px;
	}

	.remarks textarea {
		width: 100%;
		padding: 0 15px;
	}
</style>