<template>
	<view class="todo-page" v-bind:style="{paddingBottom:paddingBottom+'px'}">
		<view class="card">
			<view class="background"></view>
			<view>
				<u--form labelPosition="left" labelWidth="auto" labelAlign="center" :model="model" class="demo-ruleForm">
					<u-form-item label="发起部门：" prop="Nav_LaunchDepartment" borderBottom>
						<u--input v-if="model.Nav_NewUser" v-model="model.Nav_NewUser.Nav_Department.NAME" border="none" slot="right" inputAlign="right" disabled disabledColor="#ffffff" fontSize="14px"></u--input>
					</u-form-item>
					<u-form-item label="发起人：" prop="Nav_LaunchUser.NAME" borderBottom>
						<u--input v-if="model.Nav_NewUser" v-model="model.Nav_NewUser.Nav_User.NAME" border="none" slot="right" inputAlign="right" disabled disabledColor="#ffffff" fontSize="14px"></u--input>
					</u-form-item>
					<u-form-item label="培训层级：" prop="START_TIME" borderBottom>
						<u--input disabled disabledColor="#fff" v-if="model.Nav_NewUser" v-model="model.Nav_NewUser.TRAIN_STATUS_NAME" border="none" slot="right" inputAlign="right" fontSize="14px"></u--input>
					</u-form-item>
					<u-form-item label="开始时间：" prop="START_TIME" borderBottom>
						<u--input disabled disabledColor="#fff" v-if="model.Nav_NewUser" v-model="model.Nav_NewUser.START_TIME" border="none" slot="right" inputAlign="right" fontSize="14px"></u--input>
					</u-form-item>
					<u-form-item label="结束时间：" prop="END_TIME" borderBottom>
						<u--input disabled disabledColor="#fff" v-if="model.Nav_NewUser" v-model="model.Nav_NewUser.END_TIME" border="none" slot="right" inputAlign="right" fontSize="14px"></u--input>
					</u-form-item>


					<u-form-item label="培训地点：" prop="TAINNING_ADDR" borderBottom>
						<u--input disabled disabledColor="#fff" v-if="model.Nav_NewUser" v-model="model.Nav_NewUser.TAINNING_ADDR" border="none" slot="right" inputAlign="right" fontSize="14px"></u--input>
					</u-form-item>
					<u-form-item label="培训学时：" prop="TRAINNING_TIME" borderBottom>
						<u--input disabled disabledColor="#fff" v-if="model.Nav_NewUser" v-model="model.Nav_NewUser.TRAINNING_TIME" border="none" slot="right" inputAlign="right" fontSize="14px"></u--input>
					</u-form-item>
					<u-form-item label="培训老师：" prop="TEACHER">
						<!-- <u--input disabled disabledColor="#fff" v-if="model.Nav_NewUser" v-model="model.Nav_NewUser.TEACHER" border="none" slot="right" inputAlign="right" fontSize="14px"></u--input> -->
					</u-form-item>
					<view class="tag-view" v-if="model.Nav_NewUser&&model.Nav_NewUser.Nav_Teachers">
						<view v-for="(i, k) in model.Nav_NewUser.Nav_Teachers.filter(i => !i.IS_DELETED)">
							<u-tag plain class="tag" :key="k" :inverted="true" :text="i.Nav_User.NAME" type="primary" />
						</view>

					</view>
					<u-form-item label="培训形式：" prop="TRAIN_MODEL" borderBottom>
						<u--input disabled disabledColor="#fff" v-if="model.Nav_NewUser" v-model="model.Nav_NewUser.TRAINTYPE_NAME" border="none" slot="right" inputAlign="right" fontSize="14px"></u--input>
					</u-form-item>
					<u-form-item label="培训内容：" prop="Nav_Content">
					</u-form-item>
					<u--textarea autoHeight disabled disabledColor="#fff" v-if="model.Nav_NewUser" v-model="model.Nav_NewUser.Nav_Content.NAME" border="none"></u--textarea>
					<u-form-item label="附件" prop="CHECKSTANDARD">
					</u-form-item>
					<full-upload v-if="model.Nav_NewUser" v-model="model.Nav_NewUser.Nav_Files" :isShowBtn='false' :listProp='listPropUpload' :listPropVal='listPropValUpload'></full-upload>
				</u--form>
				<u--form labelPosition="left" labelWidth="auto" labelAlign="center" :model="model" class="demo-ruleForm">

					<u-form-item label="工号	：" prop="Nav_User" borderBottom>
						<u--input v-if="model.Nav_User" v-model="model.Nav_User.CODE" border="none" slot="right" inputAlign="right" disabled disabledColor="#ffffff" fontSize="14px"></u--input>
					</u-form-item>
					<u-form-item label="姓名：" prop="Nav_User.NAME" borderBottom>
						<u--input v-if="model.Nav_User" v-model="model.Nav_User.NAME" border="none" slot="right" inputAlign="right" disabled disabledColor="#ffffff" fontSize="14px"></u--input>
					</u-form-item>
					<u-form-item label="身份证号	：" prop="Nav_User" borderBottom>
						<u--input v-model="model.ID_CARD_NUMBER" border="none" slot="right" inputAlign="right" disabled disabledColor="#ffffff" fontSize="14px"></u--input>
					</u-form-item>
					<u-form-item label="入职时间	：" prop="IN_TIME" borderBottom>
						<u--input v-model="model.IN_TIME" border="none" inputAlign="right" disabled disabledColor="#ffffff" fontSize="14px"></u--input>
					</u-form-item>


					<u-form-item label="部门：" prop="depName" borderBottom>
						<u--input v-if="model.Nav_Department" v-model="model.Nav_Department.NAME" border="none" slot="right" inputAlign="right" disabled disabledColor="#ffffff" fontSize="14px"></u--input>
					</u-form-item>
					<u-form-item label="岗位：" prop="Nav_Post.NAME" borderBottom>
						<u--input v-if="model.Nav_Post" v-model="model.Nav_Post.NAME" border="none" slot="right" inputAlign="right" disabled disabledColor="#ffffff" fontSize="14px"></u--input>
					</u-form-item>

					<u-form-item label="考核分数：" prop="SCORE" borderBottom>
						<u--input disabled disabledColor="#fff" v-model="model.SCORE" border="none" slot="right" inputAlign="right" fontSize="14px"></u--input>
					</u-form-item>
					<u-form-item label="考核结果：" prop="EXAMINATION_RESULTS" borderBottom>
						<u--input v-if="model.EXAMINATION_RESULTS&&model.SCORE" disabled disabledColor="#fff" v-model="model.EXAMINATION_RESULTS_NAME" border="none" slot="right" inputAlign="right"
							fontSize="14px"></u--input>
					</u-form-item>
					<u-form-item label="附件" prop="CHECKSTANDARD">
					</u-form-item>
					<full-upload v-model="model.Nav_Files" :isShowBtn='false' :listProp='listPropUpload' :listPropVal='listPropValUpload'></full-upload>


				</u--form>
			</view>
		</view>
		<view class="bottom-button">
			<u-button type="primary" v-if='isLoadOK&&tableKey==1' @click="onTableBtnAgree" color="#3d4b70">签到</u-button>
		</view>
	</view>
</template>

<script>
	import {
		initFilter,
		extendRule,
		extendInclude,
		transformData
	} from '../../../../utils/common'
	import {
		getRequest,
	} from '../../../../services/apply/FOServices/FOServices'
	import {
		GetEnumAnyOrder
	} from '../../../../services/common';
	import '../../../../utils/showMsg.js'
	import config from '../../../../config/common'
	export default {
		data() {
			return {
				ID: "",
				listPropUpload: [],
				listPropValUpload: [],
				model: {},
				TaskID: "",
				tableKey: '0',
				isLoadOK: false,
				paddingBottom: '170',
				orgId: uni.getStorageSync('orgId'),
				enumsData: {}, // 存储所有枚举数据（键：枚举名称，值：处理后的枚举列表）
				enumsText: {} // 存储枚举文本列表（用于下拉选择等场景）
			}
		},
		onLoad(option) {
			this.ID = option.ID;
			this.TaskID = option.taskID;
			this.tableKey = option.tableKey ? option.tableKey : '0'
			this.fetchEnums(['SEThreeLevelSafeTrainType', 'TrainType', 'SEExaminationResultsEnum']);
		},
		methods: {
			fetchEnums(enumNames) {
				var dataParm = {
					'name': enumNames.join('|')
				}
				GetEnumAnyOrder(dataParm).then(res => {
					let newd = transformData(res, enumNames)
					this.enumsData = newd[0];
					// 生成文本列表（如需要）
					this.enumsText = newd[1]
					this.loadData();
				})
			},
			loadData() {
				const json = initFilter(this.orgId, "", "CODE", 1)
				extendRule(json, 'ID', 1, this.ID);
				extendInclude(json, 'Nav_NewUser.Nav_Department');
				extendInclude(json, 'Nav_NewUser.Nav_User');
				extendInclude(json, 'Nav_NewUser.Nav_Content');
				extendInclude(json, 'Nav_NewUser.Nav_Files.Nav_ImgFile');
				extendInclude(json, 'Nav_NewUser.Nav_Teachers.Nav_User');
				extendInclude(json, 'Nav_User');
				extendInclude(json, 'Nav_Department');
				extendInclude(json, 'Nav_Post');
				extendInclude(json, 'Nav_Files.Nav_ImgFile');
				getRequest(json, "/SE/NewUserDetail/Get").then(res => {
					let currUserId = uni.getStorageSync('appInfo')?.User?.ID;
					this.model = res
					this.model.IN_TIME = this.model.IN_TIME.substring(0, 10);
					if (this.model.Nav_NewUser) {
						this.model.Nav_NewUser.TRAIN_STATUS_NAME = res.Nav_NewUser.TRAIN_STATUS !== undefined ? this.enumsData['SEThreeLevelSafeTrainType'].find(item => item.code === res.Nav_NewUser.TRAIN_STATUS)
							.name : '';
						this.model.Nav_NewUser.TRAINTYPE_NAME = res.Nav_NewUser.TRAINTYPE !== undefined ? this.enumsData['TrainType'].find(item => item.code === res.Nav_NewUser.TRAINTYPE).name : '';

					}
					this.model.EXAMINATION_RESULTS_NAME = res.EXAMINATION_RESULTS !== undefined ? this.enumsData['SEExaminationResultsEnum'].find(item => item.code === res.EXAMINATION_RESULTS).name : '';
					this.isLoadOK = true;
				})
			},
			returnModel(level) {
				let str = '';
				if (level == undefined) {
					return str;
				}
				if (level.indexOf('1') >= 0) {
					str += '讲授法 ';
				}
				if (level.indexOf('2') >= 0) {
					str += '视听法 ';
				}
				if (level.indexOf('3') >= 0) {
					str += '研讨法 ';
				}
				if (level.indexOf('4') >= 0) {
					str += '演示法 ';
				}
				return str;
			},
			onTableBtnAgree() {
				const json = initFilter(this.orgId)
				json.Parameter1 = this.ID;
				json.Parameter2 = this.TaskID;
				json.Parameter3 = this.model.EDU_CARD_ID;
				getRequest(json, "/SE/SENewUsers/PersonalAgree").then(res => {
					if (res) {
						uni.$showMsgFunc('操作成功!', () => {
							uni.navigateBack()
						}, 'success', 1000)
					}
				})
			},
		},
	}
</script>

<style>
	@import url("@/style/css/newTemplate.css");

	.todo-page {
		/* padding: 16px 16px 70px; */
	}

	.background {
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		bottom: 0;
		background: #edf1fd;
		z-index: -1;
	}

	.card {
		margin: 20px 16px 140px 16px;
		/* border: 1px solid #EBEEF5; */
		padding: 20px 30px 80px 30px;
		/* box-shadow: rgba(0, 0, 0, 0.08) 0px 0px 3px 1px; */
		background-color: #ffffff;
		border-radius: 10px;
	}

	.upload-title {
		font-size: 14px;
		color: #8e8b9c;
		line-height: 22px;
		padding: 8px 0px;
	}

	.demo-ruleForm>>>.u-form-item__body__left__content__label {
		font-size: 14px;
		color: #8e8b9c;
		/* justify-content: flex-start; */
	}

	.demo-ruleForm>>>.u-form-item__body__left__content__ {
		left: -11px;
		top: 0px
	}

	.demo-ruleForm>>>.u-textarea__field {
		font-size: 14px;
	}

	.demo-ruleForm>>>.u-cell__title-text {
		font-size: 14px;
	}

	.btn-wrap {
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
		box-sizing: border-box;
		padding: 16px;
		z-index: 1000;
		background: #fff;
		box-shadow: 0 -1px 2px 0 rgba(0, 0, 0, .05);
	}

	.buttons {
		margin-top: 10px;
		display: flex;
		justify-content: space-between;
	}

	.buttons .first-btn {
		margin-right: 20px;
	}

	.bottom-button {
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
		padding: 10px 16px;
		box-sizing: border-box;
		background: #edf1fd;
		z-index: 999;
	}
</style>