<template>
	<view class="todo-page" v-bind:style="{paddingBottom:paddingBottom+'px'}">
		<view  class="card">
			<view class="background"></view>
			<u--form labelPosition="left" labelWidth="auto" labelAlign="center" :model="model" class="demo-ruleForm">
				<u-form-item label="发起时间：" prop="LAUNCH_TIME" borderBottom>
					<u--input v-model="model.LAUNCH_TIME" border="none" slot="right" inputAlign="right" disabled
						disabledColor="#ffffff" fontSize="14px"></u--input>
				</u-form-item>
				<u-form-item label="发起部门	：" prop="Nav_LaunchDepartment" borderBottom>
					<u--input v-if="model.Nav_LaunchDepartment" v-model="model.Nav_LaunchDepartment.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_LaunchUser" v-model="model.Nav_LaunchUser.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-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-if="model.Nav_User" 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-model="model.depName" 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>
		</view>
		<u-sticky offset-top="20">
			<view class="sub-form">
				<view class="sub-form-wrap" style="margin: 10px;">
					<u--form labelPosition="left" labelWidth="auto" labelAlign="center" errorType="border-bottom"
						ref="sForm">
						<u-collapse :border="false" accordion>
							<view style="padding: 8px 0px;" 
								v-for="(item, index) in model.Nav_TrainRecordList">
								<u-collapse-item :title="index + 1 + '. '+item.THREE_LEVEL_SAFE_TRAIN_TYPE">
									<u-form-item label="开始时间：" prop="START_TIME" borderBottom>
										<u--input disabled disabledColor="#fff" v-model="item.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-model="item.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-model="item.TAINNING_ADDR"
											border="none" slot="right" inputAlign="right" fontSize="14px"></u--input>
									</u-form-item>
									<u-form-item label="组织部门：" prop="Nav_Department" borderBottom>
										<u--input disabled disabledColor="#fff" v-model="item.Nav_Department.NAME"
											border="none" slot="right" inputAlign="right" fontSize="14px"></u--input>
									</u-form-item>
									<u-form-item label="考核人：" prop="Nav_User" borderBottom>
										<u--input disabled disabledColor="#fff" v-model="item.Nav_User.NAME"
											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-model="item.TRAINNING_TIME"
											border="none" slot="right" inputAlign="right" fontSize="14px"></u--input>
									</u-form-item>
									<u-form-item label="培训老师：" prop="TEACHER" borderBottom>
										<u--input disabled disabledColor="#fff" v-model="item.TEACHER"
											border="none" slot="right" inputAlign="right" fontSize="14px"></u--input>
									</u-form-item>
									<u-form-item label="培训形式：" prop="TRAIN_MODEL" borderBottom>
										<u--input disabled disabledColor="#fff" v-model="item.TRAIN_MODEL"
											border="none" slot="right" inputAlign="right" fontSize="14px"></u--input>
									</u-form-item>
									<u-form-item label="考核结果：" prop="EXAMINATION_RESULTS" borderBottom>
										<u--input disabled disabledColor="#fff" v-model="item.EXAMINATION_RESULTS"
											border="none" slot="right" inputAlign="right" fontSize="14px"></u--input>
									</u-form-item>
									<u-form-item label="考核分数：" prop="SCORE" borderBottom>
										<u--input disabled disabledColor="#fff" v-model="item.SCORE"
											border="none" slot="right" inputAlign="right" fontSize="14px"></u--input>
									</u-form-item>
									<u-form-item label="考核内容：" prop="Nav_Content" borderBottom>
										
									</u-form-item>
									<u--textarea autoHeight disabled disabledColor="#fff" v-model="item.Nav_Content.NAME"
										border="none"></u--textarea>
								</u-collapse-item>
							</view>
						</u-collapse>
					</u--form>
				</view>
			</view>
		</u-sticky>
		<view class="bottom-button">
			<u-button type="primary" class="bottom" v-if='isLoadOK&&tableKey==1&&!isApprove'  @click="onTableBtnAgree" color="#3d4b70">签到</u-button>
			<u-button type="primary" class="bottom" v-if='isLoadOK&&tableKey==1&&isApprove' @click="onTableBtnApprove" color="#3d4b70">审阅</u-button>
		</view>
	</view>
</template>

<script>
	import {
		initFilter,
		extendRule,
		extendInclude
	} 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'
	export default {
		data() {
			return {
				ID:"",
				model: {},
				TaskID: "",
				tableKey: '0',
				isLoadOK: false,
				paddingBottom: '170',
				orgId: uni.getStorageSync('orgId'),
				isApprove:false
			}
		},
		onLoad(option) {
			this.ID = option.ID;
			this.TaskID = option.taskID;
			this.tableKey = option.tableKey ? option.tableKey : '0'
			this.loadData()
		},
		methods: {
			loadData() {
				const json = initFilter(this.orgId, "", "CODE", 1)
				extendRule(json, 'ID', 1, this.ID);
				extendInclude(json, 'Nav_LaunchDepartment');
				extendInclude(json, 'Nav_LaunchUser');
				extendInclude(json, 'Nav_Department');
				extendInclude(json, 'Nav_Post');
				extendInclude(json, 'Nav_User.Nav_Department.Nav_Parent.Nav_Parent');
				extendInclude(json, 'Nav_TrainRecordList.Nav_User');
				extendInclude(json, 'Nav_TrainRecordList.Nav_Department');
				extendInclude(json, 'Nav_TrainRecordList.Nav_Content');
				extendInclude(json, 'Nav_TrainRecordList.Nav_TrainRecordFile.Nav_ImgFile');
				extendInclude(json, 'Nav_TrainRecordList.Nav_TrainSignatureFile.Nav_ImgFile');
				extendInclude(json, 'Nav_User');
				getRequest(json, "/SE/SEThreeLevelSafeEduCard/Get").then(res => {
					let currUserId=uni.getStorageSync('appInfo')?.User?.ID;
					if(res.STATUS>=5&&res.USER_ID!=currUserId){
						this.isApprove=true;
					}
					
					res.Nav_TrainRecordList = res.Nav_TrainRecordList.sort((a, b) => {
						return a.THREE_LEVEL_SAFE_TRAIN_TYPE - b.THREE_LEVEL_SAFE_TRAIN_TYPE
					});
					res.Nav_TrainRecordList = res.Nav_TrainRecordList.filter(t => t.SCORE != undefined);
					if (res.Nav_TrainRecordList && res.Nav_TrainRecordList.length > 0) {
						for (let i = 0; i < res.Nav_TrainRecordList.length; i++) {
							res.Nav_TrainRecordList[i].TRAIN_MODEL = this.returnModel(res.Nav_TrainRecordList[i].TRAIN_MODEL);
							res.Nav_TrainRecordList[i].EXAMINATION_RESULTS = res.Nav_TrainRecordList[i].EXAMINATION_RESULTS==0?"不合格":"合格";
							if (res.Nav_TrainRecordList[i].THREE_LEVEL_SAFE_TRAIN_TYPE == 0) {
								res.Nav_TrainRecordList[i].THREE_LEVEL_SAFE_TRAIN_TYPE = "公司级";
							}else if (res.Nav_TrainRecordList[i].THREE_LEVEL_SAFE_TRAIN_TYPE == 2) {
								res.Nav_TrainRecordList[i].THREE_LEVEL_SAFE_TRAIN_TYPE = "部门级";
							}else if (res.Nav_TrainRecordList[i].THREE_LEVEL_SAFE_TRAIN_TYPE == 3) {
								res.Nav_TrainRecordList[i].THREE_LEVEL_SAFE_TRAIN_TYPE = "班组级";
							}
						}
					}
					this.model = res
					let trainContent = '';

					let top = res.Nav_Department?.Nav_Parent?.Nav_Parent?.NAME;
					if (top != undefined) {
						this.model.depName = top + "/" + res.Nav_Department?.Nav_Parent?.NAME + "/" + res
							.Nav_Department?.NAME
					} else {
						this.model.depName = res.Nav_Department?.Nav_Parent?.NAME + "/" + res.Nav_Department?.NAME
					}
					this.model.IN_TIME = this.model.IN_TIME.substring(0, 10);
					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 '公司 ';
				}
			},
			onTableBtnAgree() {
				const json = initFilter(this.orgId)
				json.Parameter1 = this.ID;
				json.Parameter2 = this.TaskID;
				getRequest(json, "/SE/SEThreeLevelSafeTrainRecord/PersonalAgree").then(res => {
					if (res) {
						uni.$showMsgFunc('操作成功!', () => {
							uni.navigateBack()
						}, 'success', 1000)
					}
				})
			},
			onTableBtnApprove() {
				const json = initFilter(this.orgId)
				json.Parameter1 = this.ID;
				json.Parameter2 = this.TaskID;
				getRequest(json, "/SE/SEThreeLevelSafeEduCard/Approve").then(res => {
					if (res) {
						uni.$showMsgFunc('操作成功!', () => {
							uni.navigateBack()
						}, 'success', 1000)
					}
				})
			}
		},
		computed: {

		}
	}
</script>

<style>
	/* @import url("@/style/css/editTemplate.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 40px 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;
	}
	.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;
	}
	.sub-form {
		margin: 20px 16px 140px 16px;
		/* padding: 10px; */
		background-color: #ffffff;
		border-radius: 10px;
	}
	.sub-form>>>.u-form-item__body__left__content__label {
		font-size: 14px;
		color: #8e8b9c;
		/* justify-content: flex-start; */
	}
	.sub-form>>>.u-textarea__field {
		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;
	}
	/* .sub-form>>>.u-form-item__body__left__content {
		margin-right: 10px;
	} */
</style>