<template>
	<view class="page-wrap" v-bind:style="{paddingBottom:paddingBottom+'px'}">
		<uni-card margin="0" :is-shadow="true">
			<u--form labelPosition="left" labelWidth="auto" labelAlign="center" :model="model">
				<u-form-item label="发起时间：" prop="LAUNCH_TIME" borderBottom>
					<u--input v-model="model.LAUNCH_TIME" border="none" slot="right" inputAlign="right" disabled
						disabledColor="#ffffff"></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"></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"></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"></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"></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"></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"></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"></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"></u--input>
				</u-form-item>
			</u--form>
		</uni-card>
		<u-sticky offset-top="20">
			<view class="sub-form">
				<view class="sub-form-wrap">
					<u--form labelPosition="left" labelWidth="auto" labelAlign="center" errorType="border-bottom"
						ref="sForm">
						<u-collapse :border="false" accordion>
							<uni-card style="margin-bottom: 16px;" margin="0" spacing="0" :is-shadow="false"
								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"></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"></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"></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"></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"></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"></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"></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"></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"></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"></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>
							</uni-card>
						</u-collapse>
					</u--form>
				</view>
			</view>
		</u-sticky>
		<view class="bottom-button">
			<button type="primary" class="bottom" v-if='isLoadOK&&tableKey==1&&!isApprove' @click="onTableBtnAgree">签到</button>
			<button type="primary" class="bottom" v-if='isLoadOK&&tableKey==1&&isApprove' @click="onTableBtnApprove">审阅</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.Nav_File');
				extendInclude(json, 'Nav_TrainRecordList.Nav_TrainSignatureFile.Nav_ImgFile.Nav_File');
				extendInclude(json, 'Nav_User.Nav_UserSignFiles.Nav_ImgFile.Nav_File');
				getRequest(json, "/SE/SEThreeLevelSafeEduCard/Get").then(res => {
					if(res.STATUS==5){
						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 == 1) {
								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");

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