<template>
	<view class="page-wrap">
		<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="NAME" borderBottom>
						<u--input v-if="model.Nav_Notify" v-model="model.Nav_Notify.NAME" border="none" slot="right"
							inputAlign="right" disabled disabledColor="#ffffff" fontSize="14px"></u--input>
					</u-form-item>
					<u-form-item label="培训编号：" prop="CODE" borderBottom>
						<u--input v-if="model.Nav_Notify" v-model="model.Nav_Notify.CODE" 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_Notify" v-model="model.Nav_Notify.Nav_TrainType.NAME" border="none"
							slot="right" inputAlign="right" disabled disabledColor="#ffffff" fontSize="14px"></u--input>
					</u-form-item>
					<u-form-item label="培训级别：" prop="LEVEL" borderBottom>
						<u--input v-if="model.Nav_Notify" v-model="model.Nav_Notify.LEVEL_SHOW" border="none"
							slot="right" inputAlign="right" disabled disabledColor="#ffffff" fontSize="14px"></u--input>
					</u-form-item>
					<u-form-item label="组织部门：" prop="Nav_Notify.Nav_LaunchDepartment.NAME" borderBottom>
						<u--input v-if="model.Nav_Notify" v-model="model.Nav_Notify.Nav_LaunchDepartment.NAME"
							border="none" slot="right" inputAlign="right" disabled disabledColor="#ffffff"
							fontSize="14px"></u--input>
					</u-form-item>
					<u-form-item label="培训时间：" prop="TRAIN_TIME" borderBottom>
						<u--input v-model="model.TRAIN_TIME" border="none" inputAlign="right" disabled
							disabledColor="#ffffff" fontSize="14px"></u--input>
					</u-form-item>
					<u-form-item label="培训地点：" prop="Nav_Notify.TRAIN_ADDR" borderBottom>
						<u--input v-if="model.Nav_Notify" v-model="model.Nav_Notify.TRAIN_ADDR" border="none"
							slot="right" inputAlign="right" disabled disabledColor="#ffffff" fontSize="14px"></u--input>
					</u-form-item>
					<u-form-item label="培训学时：" prop="Nav_Notify.HOURS" borderBottom>
						<u--input v-if="model.Nav_Notify" v-model="model.Nav_Notify.HOURS" border="none" slot="right"
							inputAlign="right" disabled disabledColor="#ffffff" fontSize="14px"></u--input>
					</u-form-item>
					<u-form-item label="培训老师：" prop="Nav_Notify.TRAIN_TEACHER" borderBottom>
						<u--input v-if="model.Nav_Notify" v-model="model.Nav_Notify.TRAIN_TEACHER" border="none"
							slot="right" inputAlign="right" disabled disabledColor="#ffffff" fontSize="14px"></u--input>
					</u-form-item>
					<u-form-item label="培训形式：" prop="" borderBottom>
						<u--input v-if="model.Nav_Notify" v-model="model.Nav_Notify.TRAINTYPE_SHOW" border="none"
							inputAlign="right" disabled disabledColor="#ffffff" fontSize="14px"></u--input>
					</u-form-item>
					<u-form-item label="考核方式：" prop="Nav_TrainCheckType.NAME" borderBottom>
						<u--input v-if="model.Nav_Notify" v-model="model.Nav_Notify.CHECKTYPE_SHOW" border="none"
							slot="right" inputAlign="right" disabled disabledColor="#ffffff" fontSize="14px"></u--input>
					</u-form-item>
					<u-form-item label="培训课件：" prop="trainCour" borderBottom>
						<u-textarea autoHeight v-html="model.trainCour" border="none" disabled></u-textarea>
					</u-form-item>
					<u-form-item label="培训内容：" prop="TRAINCONTENT" borderBottom>
						<u-textarea autoHeight v-html="model.TRAINCONTENT" border="none" disabled></u-textarea>
					</u-form-item>

					<u-form-item label="请假人员：" prop="LeaveUsers" borderBottom>
						<u-textarea autoHeight v-html="model.LeaveUsers" border="none" disabled></u-textarea>
					</u-form-item>
					<u-form-item label="缺席人员：" prop="MissUsers" borderBottom>
						<u-textarea autoHeight v-html="model.MissUsers" border="none" disabled></u-textarea>
					</u-form-item>
					<u-form-item label="培训人员：" prop="Users">
					</u-form-item>
					<rich-text autoHeight v-html="model.Users" border="none" disabled
						style="font-size: 14px;"></rich-text>
					<!-- 					<view style="margin-top: 10px;">
						<u-button type="primary" class="bottom" v-if='isLoadOK&&tableKey!=1&&model.Nav_Notify.CHECKTYPE == 51' @click="openTest(model.ID)">查看试卷</u-button>
					</view> -->
					<view class="upload-title">附件</view>
					<full-upload v-model="model.Nav_Files" :listProp='listPropUpload' :listPropVal='listPropValUpload'
						:isShowBtn="false"></full-upload>
					<u-form-item label="审阅意见：" prop="TRAIN_PLAN" borderBottom>
						<u--input v-model="model.STATUS>2?'已阅':''" border="none" slot="right" inputAlign="right"
							disabled disabledColor="#ffffff" fontSize="14px"></u--input>
					</u-form-item>
					<u-form-item label="合格率：" prop="Nav_TrainCheckType.NAME" borderBottom>
						<u--input v-model="passRate" border="none" inputAlign="right" disabled disabledColor="#ffffff"
							fontSize="14px"></u--input>
					</u-form-item>
				</u--form>
				<u--form labelPosition="left" labelWidth="auto" labelAlign="center" :model="model" class="demo-ruleForm"
					v-if="model.Nav_Users">
					<view style="position: relative;">

						<view style="position: absolute;left: -10px;color: #3d4b70;top: -3px;">*</view>
					</view>

					<view
						style="font-size: 15px; font-weight: bold;color: #3d4b70;margin-bottom: 10px;margin-top: 20px;">
						培训签到表</view>
					<uni-collapse :border="false" accordion>
						<view v-for="(item, index) in model.Nav_Users.filter(it=>it.OK)" :key="index">
							<uni-collapse-item title-border="none" :border="false">
								<template v-slot:title>
									<view class="uni-collapse-item__title-box">
										<view class="uni-collapse-item__title-text">
											{{item.Nav_User?index+1+'.'+item.Nav_User.NAME:index+1+'.'}}
										</view>
									</view>
								</template>
								<view class="content" style="padding: 0px 0px 0px 10px;">

									<u-form-item label="部门" prop="HIDDEN_PLACE" border-bottom>
										<u--input v-model="item.DEPARTMENT_NAME" disabled disabledColor="#ffffff"
											inputAlign="right" fontSize="14px" border="none">
										</u--input>
									</u-form-item>
									<u-form-item label="工号" prop="HIDDEN_PLACE" border-bottom>
										<u--input v-model="(item.Nav_User||{}).CODE" disabled disabledColor="#ffffff"
											inputAlign="right" fontSize="14px" border="none">
										</u--input>
									</u-form-item>
									<u-form-item label="岗位" prop="HIDDEN_PLACE" border-bottom>
										<u--input v-model="item.POST_NAME" disabled disabledColor="#ffffff"
											inputAlign="right" fontSize="14px" border="none">
										</u--input>
									</u-form-item>
									<u-form-item label="分数" prop="HIDDEN_PLACE" border-bottom
										v-if='model.Nav_Notify.CHECKTYPE == 51||model.Nav_Notify.CHECKTYPE == 56||model.Nav_Notify.CHECKTYPE == 81'>
										<u--input v-model="item.SCORE" disabled disabledColor="#ffffff"
											inputAlign="right" fontSize="14px" border="none">
										</u--input>
									</u-form-item>
									<u-form-item label="查看试卷" prop="HIDDEN_PLACE">
									</u-form-item>
									<view v-if="!signable">
										<view v-if="isLoadOK&&model.Nav_Notify.CHECKTYPE&&isCHECKTYPE">
											<u-button type="primary" class="bottom"
												v-if='model.Nav_Notify.CHECKTYPE == 51'
												@click="openTest(model.ID,item.USER_ID)">查看试卷</u-button>
											<full-upload v-model="item.Nav_Files" :listProp='listPropUpload'
												:listPropVal='listPropValUpload' :isShowBtn="false"
												v-else></full-upload>
										</view>
										<view v-else>
											<u-button type="primary" class="bottom"
												@click="openTest(model.ID,item.USER_ID)">查看试卷</u-button>
										</view>
									</view>

									<u-form-item label="电子签名" prop="CHECKSTANDARD">
									</u-form-item>
									<view v-if="model.Nav_User&&model.Nav_User.FILE_PATH">
										<image style="width: 150px;height: 60px;"
											:src="imgurl+model.Nav_User.FILE_PATH">
										</image>
									</view>

								</view>


							</uni-collapse-item>
						</view>
					</uni-collapse>

				</u--form>
			</view>
			<view class="bottom-button"
				v-if='isLoadOK&&tableKey==1&&(model.STATUS==1||(model&&model.Nav_Users&&model.Nav_Users.find(e=>e.USER_ID==this.userId&&e.IS_RESEND==true)!=null ))'>
				<u-button type="primary" class="bottom" color="#3d4b70" @click="onTableBtnAgree"
					:disabled="isAgree">签到</u-button>
			</view>
			<view class="bottom-button"
				v-if='isLoadOK&&tableKey==1&&model.STATUS==40&&model.USER_ID_APPROVE==this.userId'>
				<u-button type="primary" class="bottom" color="#3d4b70" @click="onTableBtnAudit">审阅</u-button>
			</view>
		</view>
	</view>
</template>
<script>
	import {
		initFilter,
		extendRule,
		extendInclude,
		getArryPropShow,
		transformData
	} from '../../../../utils/common'
	import {
		getRequest,
	} from '../../../../services/apply/FOServices/FOServices'
	import '../../../../utils/showMsg.js'
	import color from '../../../../uni_modules/uview-ui/libs/config/color'
	import config from '../../../../config/common'
	import {
		getEnum,
		GetEnumAnyOrder
	} from '../../../../services/common';
	export default {
		data() {
			return {
				imgurl: config.uni_app_web_api_url + ':5199',
				model: {},
				TaskID: "",
				tableKey: '0',
				isLoadOK: false,
				ORG_ID: uni.getStorageSync('orgId'),
				listPropUpload: ['RECORD_ID'],
				listPropValUpload: [],
				isAgree: false,
				enumsData: {}, // 存储所有枚举数据（键：枚举名称，值：处理后的枚举列表）
				enumsText: {}, // 存储枚举文本列表（用于下拉选择等场景）
				signable: false,
				userId: uni.getStorageSync('appInfo').User.ID,
				passRate: '100%',
				isCHECKTYPE: true
			}
		},
		onLoad(option) {
			this.model.ID = option.ID;
			this.TaskID = option.taskID;
			this.tableKey = option.tableKey ? option.tableKey : '0'
			this.fetchEnums(['TrainType', 'PlanCheckType', 'FMDepartmentType']);

		},
		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.ORG_ID, "", "", 1)
				extendRule(json, 'ID', 1, this.model.ID);
				extendInclude(json, 'Nav_Notify');
				extendInclude(json, "Nav_Notify.Nav_ListCour.Nav_Cour")
				extendInclude(json, 'Nav_Notify.Nav_TrainContentList.Nav_Point');
				extendInclude(json, 'Nav_Notify.Nav_LaunchDepartment');
				extendInclude(json, 'Nav_Notify.Nav_LaunchUser');
				extendInclude(json, 'Nav_Notify.Nav_TrainType');
				extendInclude(json, 'Nav_Users.Nav_User');
				extendInclude(json, 'Nav_Files.Nav_ImgFile');
				extendInclude(json, 'Nav_Users.Nav_Files.Nav_ImgFile');
				extendInclude(json, 'Nav_Papers');
				getRequest(json, "/SE/TrainRecord/Get").then(res => {
					this.model = res
					//数据组装
					let trainContent = '';
					let trainCour = '';
					let MissUsers = '';
					let LeaveUsers = '';
					let Users = '';

					if (res.Nav_Notify.Nav_ListCour && res.Nav_Notify.Nav_ListCour.length > 0) {
						trainCour = getArryPropShow(res.Nav_Notify.Nav_ListCour, 'Nav_Cour.NAME', "<br/>")
					}
					if (res.Nav_Notify.Nav_TrainContentList && res.Nav_Notify.Nav_TrainContentList.length > 0) {
						for (let i = 0; i < res.Nav_Notify.Nav_TrainContentList.length; i++) {
							trainContent += (i + 1) + "." + res.Nav_Notify.Nav_TrainContentList[i].Nav_Point.NAME +
								"<br/>"
						}
					}
					let users0 = res.Nav_Users.filter(t => t.STATUS == 0);
					let users1 = res.Nav_Users.filter(t => t.STATUS == 1);
					let users2 = res.Nav_Users.filter(t => t.STATUS == 2);
					if (users1 && users1.length > 0) {
						for (let i = 0; i < users1.length; i++) {
							LeaveUsers += users1[i].Nav_User.NAME +
								"<br/>"
						}
					} else {
						LeaveUsers = "无";
					}
					if (users2 && users2.length > 0) {
						for (let i = 0; i < users2.length; i++) {
							MissUsers += users2[i].Nav_User.NAME +
								"<br/>"
						}
					} else {
						MissUsers = "无";
					}
					if (users0 && users0.length > 0) {
						for (let i = 0; i < users0.length; i++) {
							if (!users0[i].OK) {
								Users += (Users.length > 0 ? " " : "") +
									"<view style='color:#E35D58;background-color:rgba(227,93,88,0.2);padding:5px;line-height:30px;white-space:nowrap;'>" +
									users0[i].Nav_User.NAME + "</view>";
							} else {
								Users += (Users.length > 0 ? " " : "") +
									"<text style='padding:5px;line-height:30px;white-space:nowrap;'>" +
									users0[i].Nav_User.NAME + "</text>";
							}

						}
					}
					this.model.Nav_Notify.LEVEL_SHOW = res.Nav_Notify.LEVEL !== undefined ? this.enumsData[
						'FMDepartmentType'].find(item => item.code === res.Nav_Notify.LEVEL)?.name : '';
					this.model.Nav_Notify.TRAINTYPE_SHOW = res.Nav_Notify.TRAINTYPE !== undefined ? this.enumsData[
						'TrainType'].find(item => item.code === res.Nav_Notify.TRAINTYPE)?.name : '';
					this.model.Nav_Notify.CHECKTYPE_SHOW = res.Nav_Notify.CHECKTYPE !== undefined ? this.enumsData[
						'PlanCheckType'].find(item => item.code === res.Nav_Notify.CHECKTYPE)?.name : '';
					this.model.TRAIN_MODEL = this.returnModel(this.model.Nav_Notify.TRAIN_MODEL);
					// this.model.LEVEL = this.transLevel(this.model.Nav_Notify.LEVEL);
					this.model.TRAIN_TIME = this.model.Nav_Notify.TRAIN_START_TIME?.substring(0, 16) + "~" + this
						.model.Nav_Notify
						.TRAIN_END_TIME?.substring(8, 16);
					this.model.TRAINCONTENT = trainContent;
					this.model.trainCour = trainCour;
					this.model.MissUsers = MissUsers;
					this.model.LeaveUsers = LeaveUsers;
					this.model.Users = Users;
					let passRateThis = 0
					let userAll = res.Nav_Users.filter(e => e.STATUS == 0 && e.ENABLE_STATUS == 0 && e
						.EXAMINATION_RESULTS != null)
					let userPass = res.Nav_Users.filter(e => e.STATUS == 0 && e.ENABLE_STATUS == 0 && e
						.EXAMINATION_RESULTS != null && e.EXAMINATION_RESULTS == 1)
					if (userAll && userAll.length > 0 && userPass && userPass.length > 0) {
						passRateThis = (userPass.length / userAll.length).toFixed(4) * 100;
					}
					this.passRate = passRateThis + '%'
					this.isCHECKTYPE = this.model.Nav_Notify.CHECKTYPE == 51 || this.model.Nav_Notify.CHECKTYPE ==
						56 || this.model.Nav_Notify.CHECKTYPE == 81

					this.signable = res.STATUS == 1 && res.Nav_Users && res.Nav_Users.find(it => it.USER_ID ===
						this.userId) && (this.tableKey == "1")
					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;
			},
			transLevel(level) {
				if (level == 0) {
					return '部门 ';
				}
				if (level == 1) {
					return '车间 ';
				}
				if (level == 2) {
					return '班组 ';
				}
				if (level == 3) {
					return '公司 ';
				}
			},
			openTest(id, userid) {
				uni.navigateTo({
					url: '/pages/apply/subPages/SE/7answerPageEdit?ID=' + id + '&userID=' + userid
				})
			},
			onTableBtnAgree() {
				this.isAgree = true;
				const json = initFilter(this.ORG_ID, "", "", 1)
				json.Keyword = this.model.ID;
				json.Parameter1 = this.TaskID;
				getRequest(json, "/SE/SETrainRecord/SignIn").then(res => {
					if (res) {
						uni.$showMsgFunc('操作成功!', () => {
							uni.navigateBack()
						}, 'success', 1000)
					}
				})
			},
			onTableBtnAudit() {
				const json = initFilter(this.ORG_ID, "", "", 1)
				json.Keyword = this.model.ID;
				json.Parameter1 = this.TaskID;
				getRequest(json, "/SE/SETrainRecord/Submit").then(res => {
					if (res) {
						uni.$showMsgFunc('操作成功!', () => {
							uni.navigateBack()
						}, 'success', 1000)
					}
				})
			}
		},
		computed: {

		}
	}
</script>

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

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

	.page-wrap {
		overflow: hidden;

	}

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

	.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;
	}

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