<template>
	<view class="page-wrap">
		<uni-card margin="0" :is-shadow="true">
			<u--form labelPosition="left" labelWidth="auto" labelAlign="center" :model="model">
				<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"></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"></u--input>
				</u-form-item>
				<u-form-item label="培训级别：" prop="LEVEL" borderBottom>
					<u--input v-model="model.LEVEL" border="none" slot="right" inputAlign="right" disabled
						disabledColor="#ffffff"></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"></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"></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"></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"></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"></u--input>
				</u-form-item>
				<u-form-item label="培训形式：" prop="" borderBottom>
					<u--input v-if="model.Nav_Notify" v-model="model.TRAIN_MODEL" border="none" inputAlign="right"
						disabled disabledColor="#ffffff"></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.Nav_TrainCheckType.NAME" border="none"
						slot="right" inputAlign="right" disabled disabledColor="#ffffff"></u--input>
				</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>
				<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"></u--input>
				</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" borderBottom>
				</u-form-item>
				<rich-text autoHeight v-html="model.Users" border="none" disabled></rich-text>
				
				<button type="primary" class="bottom" v-if='isLoadOK&&tableKey!=1&&model.Nav_Notify.Nav_TrainCheckType.NAME=="笔试"' @click="openTest(model.ID)">查看试卷</button>
			</u--form>
		</uni-card>
		<view class="bottom-button">
			<button type="primary" class="bottom" v-if='isLoadOK&&tableKey==1&&model.STATUS==1' @click="onTableBtnAgree">签到</button>
			<button type="primary" class="bottom" v-if='isLoadOK&&tableKey==1&&model.STATUS==2' @click="onTableBtnAudit">审核</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 {
				model: {},
				TaskID: "",
				tableKey: '0',
				isLoadOK: false,
				ORG_ID : uni.getStorageSync('orgId'),
				listPropUpload: ['RECORD_ID'],
				listPropValUpload: [],
			}
		},
		onLoad(option) {
			this.model.ID = option.ID;
			this.TaskID = option.taskID;
			this.tableKey = option.tableKey ? option.tableKey : '0'
			this.loadData()
		},
		methods: {
			loadData() {
				const json = initFilter(this.ORG_ID, "", "", 1)
				extendRule(json, 'ID', 1, this.model.ID);
				extendInclude(json, 'Nav_Notify.Nav_LaunchDepartment');
				extendInclude(json, 'Nav_Notify.Nav_LaunchUser');
				extendInclude(json, 'Nav_Notify.Nav_TrainType');
				extendInclude(json, 'Nav_Notify.Nav_TrainCheckType');
				extendInclude(json, 'Nav_Notify.Nav_TrainContentList');
				extendInclude(json, 'Nav_Notify.Nav_TrainContentList.Nav_Point');
				extendInclude(json, 'Nav_Users.Nav_User');
				extendInclude(json, 'Nav_Files.Nav_ImgFile.Nav_File');
				getRequest(json, "/SE/TrainRecord/Get").then(res => {
					this.model = res
					//数据组装
					let trainContent = '';
					let MissUsers = '';
					let LeaveUsers = '';
					let Users = '';
					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.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(0, 16);
					this.model.TRAINCONTENT = trainContent;
					this.model.MissUsers = MissUsers;
					this.model.LeaveUsers = LeaveUsers;
					this.model.Users = Users;
					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) {
				uni.navigateTo({
					url: '/pages/apply/subPages/SE/7answerPageEdit?ID=' + id
				})
			},
			onTableBtnAgree() {
				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");
</style>