<template>
	<view class="page">
		<l-input hidden title="学年度" placeholder="请填写学年度" :value="queryData.AcademicYearNo" disabled right />
		<l-input hidden title="学期" placeholder="请填写学期" :value="queryData.Semester" disabled right />
		<l-input title="学号" placeholder="请填写学号" :value="queryData.StuNo" disabled right />
		<l-input title="姓名" placeholder="请填写姓名" :value="queryData.StuName" disabled right />
		<l-input title="年级" placeholder="请填写年级" :value="queryData.Grade" disabled right />
		<l-input hidden title="教师号" placeholder="请填写教师号" :value="queryData.EmpNo" disabled right />
		<l-input hidden title="系所码" placeholder="请填写系所码" :value="queryData.DeptNo" disabled right />
		<l-input title="系名" placeholder="请填写系名" :value="queryData.DeptName" disabled right />
		<l-input hidden title="专业码" placeholder="请填写专业码" :value="queryData.MajorNo" disabled right />
		<l-input title="专业名" placeholder="请填写专业名" :value="queryData.MajorName" disabled right />
		<l-input hidden title="所在行政班号" placeholder="请填写所在行政班号" :value="queryData.ClassNo" disabled right />
		<l-input title="班级名称" placeholder="请填写班级名称" :value="queryData.ClassName" disabled right />
		<l-input hidden title="课程号" placeholder="请填写课程号" :value="queryData.LessonNo" disabled right />
		<l-input title="课程名称" placeholder="请填写课程名称" :value="queryData.LessonName" disabled right />
		<l-input hidden title="课程类别码" placeholder="请填写课程类别码" :value="queryData.LessonSortNo" disabled right />
		<l-input title="课程类别" placeholder="请填写课程类别" :value="queryData.LessonSortName" disabled right />
		
		<l-input hidden title="教室码" placeholder="请填写教室码" :value="queryData.ClassRoomNo" disabled right />
		<l-input title="教室名称" placeholder="请填写教室名称" :value="queryData.ClassroomName" disabled right />
		<l-input title="原上课日期" placeholder="请填写原上课日期" :value="queryData.LessonDate" disabled right />
		<l-input title="上课时间" placeholder="请填写上课时间" :value="queryData.LessonTime" disabled right />
		<div class="lr-form-row">
			<l-select v-model="queryData.LeaveType" :range="dataSource.LeaveType" title="请假类型" placeholder="请选择" />
		</div>
		<view class="bg-white">
		  <l-textarea v-model="queryData.Remark" title="备注" placeholder="输入点什么..." />
		</view>
		<view class="btn" @click="tapBtn">
			提交
		</view>
	</view>
</template>

<script>
import moment from 'moment';
import get from 'lodash/get';
import set from 'lodash/set';
export default {
	data() {
		return {
			scheme: {
				DeptNo: {
					type: 'select',
					dataSource: '1',
					dataSourceId: 'BaseUser,f_realname,f_userid'
				},
				MajorNo: {
					type: 'select',
					dataSource: '1',
					dataSourceId: 'BaseUser,f_realname,f_userid'
				},
				ClassNo: {
					type: 'select',
					dataSource: '1',
					dataSourceId: 'BaseUser,f_realname,f_userid'
				},
				LessonNo: {
					type: 'select',
					dataSource: '1',
					dataSourceId: 'BaseUser,f_realname,f_userid'
				},
				LessonSortNo: {
					type: 'select',
					dataSource: '1',
					dataSourceId: 'BaseUser,f_realname,f_userid'
				},
				ClassRoomNo: {
					type: 'select',
					dataSource: '1',
					dataSourceId: 'BaseUser,f_realname,f_userid'
				}
			},
			dataSource: {
				DeptNo: [],
				MajorNo: [],
				ClassNo: [],
				LessonNo: [],
				LessonSortNo: [],
				ClassRoomNo: [],
				LeaveType: Object.values(this.GET_GLOBAL('dataDictionary').LeaveType).map(t => ({ value: t.value, text: t.text }))
			},
			pageInfo: null,
			data: {},
			userinfo: {},
			queryData: {
				AcademicYearNo: '',
				Semester: '',
				StuNo: '',
				StuName: '',
				Grade: '',
				EmpNo: '',
				DeptNo: '',
				DeptName: '',
				MajorNo: '',
				MajorName: '',
				ClassNo: '',
				ClassName: '',
				LessonNo: '',
				LessonName: '',
				LessonSortNo: '',
				LessonSortName: '',
				ClassRoomNo: '',
				ClassroomName: '',
				LessonDate: '',
				LessonTime: '',
				LeaveType: '',
				Remark: ''
			}
		};
	},
	methods: {
		init() {
			// console.log(this.dataSource.LeaveType)
			Promise.all([
				this.FETCH_DATASOURCE('CdDeptInfo').then(data => {
					// console.log(data)
					this.dataSource.DeptNo = data.data.map(t => ({
						text: t.deptname,
						value: t.deptno
					}));
				}),
				this.FETCH_DATASOURCE('CdMajorInfo').then(data => {
					// console.log(data)
					this.dataSource.MajorNo = data.data.map(t => ({
						text: t.majorname,
						value: t.majorno
					}));
				}),
				this.FETCH_DATASOURCE('bjsj').then(data => {
					// console.log(data)
					this.dataSource.ClassNo = data.data.map(t => ({
						text: t.classname,
						value: t.classno
					}));
				}),
				this.FETCH_DATASOURCE('LessonInfo').then(data => {
					// console.log(data)
					this.dataSource.LessonNo = data.data.map(t => ({
						text: t.lessonname,
						value: t.lessonno
					}));
				}),
				this.FETCH_DATASOURCE('CdLessonSort').then(data => {
					// console.log(data)
					this.dataSource.LessonSortNo = data.data.map(t => ({
						text: t.lessonsortname,
						value: t.lessonsortno
					}));
				}),
				this.FETCH_DATASOURCE('ClassRoomInfo').then(data => {
					// console.log(data)
					this.dataSource.ClassRoomNo = data.data.map(t => ({
						text: t.classroomname,
						value: t.classroomno
					}));
				}),
			
				() => {}
			]);
			
			this.userinfo = this.GET_GLOBAL('loginUser'); //获取登录信息
			this.pageInfo = this.GET_PARAM(); //获取页面传递参数
			
			// console.log(this.pageInfo);
			let _this = this;
			_this.LOADING('加载数据中…');
			_this.HTTP_GET('learun/adms/EducationalAdministration/StuAttendanceLeave/leaveform', {}, '加载数据时出错').then(res => {
				this.HIDE_LOADING();
				this.data = res;
				// console.log(res) 
				this.queryData.AcademicYearNo = this.pageInfo.AcademicYear;
				this.queryData.Semester = this.pageInfo.Semester;
				this.queryData.StuNo = res.StuNo;
				this.queryData.StuName = res.StuName;
				this.queryData.Grade = res.Grade;
				this.queryData.EmpNo = this.pageInfo.EmpNo;
				this.queryData.DeptNo = res.DeptNo;
				this.queryData.DeptName = this.displayListItem(res, 'DeptNo');
				this.queryData.MajorNo = res.MajorNo;
				this.queryData.MajorName = this.displayListItem(res, 'MajorNo');
				this.queryData.ClassNo = res.ClassNo;
				this.queryData.ClassName = this.displayListItem(res, 'ClassNo');
				this.queryData.Remark = '';
				this.queryData.LeaveType = '1';
				
				this.queryData.LessonNo = this.pageInfo.LessonNo;
				this.queryData.LessonName = this.displayListItem(this.pageInfo, 'LessonNo');
				
				this.queryData.LessonSortNo = this.pageInfo.LessonSortNo;
				this.queryData.LessonSortName = this.displayListItem(this.pageInfo, 'LessonSortNo');
				
				this.queryData.ClassRoomNo = this.pageInfo.ClassRoomNo;
				this.queryData.ClassroomName = this.displayListItem(this.pageInfo, 'ClassRoomNo');
				this.queryData.LessonDate = this.pageInfo.LessonDate;
				this.queryData.LessonTime = this.pageInfo.LessonTime;
				// console.log(res);
				// console.log(this.pageInfo);
				console.log(this.queryData);
			});
		},
		tapBtn() {
			let _postData = {
				keyValue: '',
				strEntity: JSON.stringify(this.queryData)
			}
			this.LOADING('保存数据中…');
			this.HTTP_POST('learun/adms/EducationalAdministration/StuAttendanceLeave/save', _postData, '加载数据时出错').then(res => {
				this.HIDE_LOADING();
				//console.log(res)
				if(res){
					this.TOAST('提交成功！');
					this.EMIT('timeTable',this.queryData.LessonDate);
					this.NAV_BACK();
				}
			});
		},
		// 显示列表中的标题项
		displayListItem(item, field) {
			const fieldItem = this.scheme[field];
			const value = item[field];
		
			switch (fieldItem.type) {
				case 'currentInfo':
				case 'organize':
					return fieldItem.dataType === 'time' ? value : get(this.GET_GLOBAL(fieldItem.dataType), `${value}.name`, '');
		
				case 'radio':
				case 'select':
					const selectItem = this.dataSource[field].find(t => t.value === String(value));
					return get(selectItem, 'text', '');
		
				case 'checkbox':
					if (!value || value.split(',').length <= 0) {
						return '';
					}
					const checkboxItems = value.split(',');
					return this.dataSource[field]
						.filter(t => checkboxItems.includes(t.value))
						.map(t => t.text)
						.join('，');
		
				case 'datetime':
					if (!value) {
						return '';
					}
					return moment(value).format(Number(fieldItem.dateformat) === 0 ? 'YYYY年 M月 D日' : 'YYYY-MM-DD HH:mm');
		
				default:
					return value === null || value === undefined ? '' : value;
			}
		}
	},
	created() {
		this.init();
	}
};
</script>

<style lang="less" scoped>

</style>
