<template>
	<view class="page-wrap">
		<view class="background"></view>
		<view class="card">
			<u--form labelPosition="left" labelWidth="auto" labelAlign="center" :model="model" class="demo-ruleForm">
				<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;">基本信息</view>
				<u-form-item label="培训名称：" prop="NAME" borderBottom>
					<u--input v-if="model.Nav_Parent" v-model="model.Nav_Parent.NAME" border="none"  inputAlign="right" disabled disabledColor="#ffffff" fontSize="14px"></u--input>
				</u-form-item>
				<u-form-item label="项目名称" prop="Nav_Parent.Nav_Project.NAME" borderBottom>
					<u--input v-if="model.Nav_Parent&&model.Nav_Parent.Nav_Project" disabled disabledColor="#ffffff" v-model="model.Nav_Parent.Nav_Project.NAME" border="none" inputAlign="right"
						fontSize="14px"></u--input>
				</u-form-item>
				<u-form-item label="外包单位名称" prop="Nav_Parent.Nav_Project.UNIT_NAME" borderBottom>
					<u--input v-if="model.Nav_Parent&&model.Nav_Parent.Nav_Project" disabled disabledColor="#ffffff" v-model="model.Nav_Parent.Nav_Project.UNIT_NAME" border="none" inputAlign="right"
						fontSize="14px"></u--input>
				</u-form-item>
				<u-form-item label="培训部门：" prop="Nav_Parent.Nav_LaunchDepartment.NAME" borderBottom>
					<u--input v-if="model.Nav_Parent&&model.Nav_Parent.Nav_Department" v-model="model.Nav_Parent.Nav_Department.NAME" border="none"  inputAlign="right" disabled disabledColor="#ffffff"
						fontSize="14px"></u--input>
				</u-form-item>
				<u-form-item label="培训老师：" prop="Nav_Parent.TRAIN_TEACHER" borderBottom>
					<u--input v-if="model.Nav_Parent&&model.Nav_Parent.Nav_User" v-model="model.Nav_Parent.Nav_User.NAME" border="none"  inputAlign="right" disabled disabledColor="#ffffff"
						fontSize="14px"></u--input>
				</u-form-item>
				<u-form-item label="培训形式" borderBottom>
					<u--input disabled disabledColor="#ffffff" v-model="model.TRAIN_TYPE_SHOW" border="none" inputAlign="right" fontSize="14px"></u--input>
				</u-form-item>
				<u-form-item label="培训地点：" prop="Nav_Parent.TRAIN_ADDR" borderBottom>
					<u--input v-if="model" v-model="model.TRAIN_ADDR" border="none"  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.START_TIME" border="none" 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.END_TIME" border="none" inputAlign="right" disabled disabledColor="#ffffff" fontSize="14px"></u--input>
				</u-form-item>
				<u-form-item label="培训学时：" prop="Nav_Parent.HOURS" borderBottom>
					<u--input v-if="model" v-model="model.TOTAL_TIME" border="none"  inputAlign="right" disabled disabledColor="#ffffff" fontSize="14px"></u--input>
				</u-form-item>
				<u-form-item label="培训内容：" prop="TRAIN_CONTENT">

				</u-form-item>
				<u-textarea autoHeight v-html="model.TRAIN_CONTENT" border="none" disabled></u-textarea>

				<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="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&&model.IS_CREATE_TEST&&false' @click="openTest(model.ID)">查看试卷</button>
			</u--form>
			<u--form labelPosition="left" labelWidth="auto" labelAlign="center" errorType="border-bottom" ref="sForm" class="sub-form" style="margin-top: 10px;">
				<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;">培训人员</view>
				<uni-collapse :border="false" accordion>
					<view v-for="(item, index) in model.Nav_Users" :key="index">
						<uni-collapse-item :title="item.Nav_User.NAME  + ' 分数：' + item.SCORE+'【'+transEXAMINATION_RESULTS(item.EXAMINATION_RESULTS) +'】'">
							<view style="margin: 0px 10px;">
								<u-form-item label="姓名:" prop="Nav_User.NAME" borderBottom>
									<u--input disabled disabledColor="#fff" fontSize="14px" v-model="item.Nav_User.NAME" border="none" inputAlign="right"></u--input>
								</u-form-item>
								<u-form-item label="性别:" prop="Nav_User.NAME" borderBottom>
									<u--input disabled disabledColor="#fff" fontSize="14px" v-model="item.Nav_User.SEX" border="none" inputAlign="right"></u--input>
								</u-form-item>
								<u-form-item label="手机号:" prop="Nav_User.NAME" borderBottom>
									<u--input disabled disabledColor="#fff" fontSize="14px" v-model="item.Nav_User.PHONE" border="none" inputAlign="right"></u--input>
								</u-form-item>
								<u-form-item label="考核结果:" prop="EXAMINATION_RESULTS_SHOW" borderBottom>
									<u--input disabled disabledColor="#fff" fontSize="14px" v-model="item.EXAMINATION_RESULTS_SHOW" border="none" inputAlign="right"></u--input>
								</u-form-item>
								<u-form-item label="分数:" prop="SCORE" borderBottom>
									<u--input disabled disabledColor="#fff" fontSize="14px" v-model="item.SCORE" border="none" inputAlign="right"></u--input>
								</u-form-item>
								<u-form-item label="查看试卷:" prop="Nav_User.NAME" borderBottom @click="openTest(item.ID,item.USER_ID)">
									<u--input disabled disabledColor="#fff" fontSize="14px" border="none" inputAlign="right"></u--input>
									<u-icon style="margin-left: 4px;" name="arrow-right" size="12"></u-icon>
								</u-form-item>
								<u-form-item label="附件:" prop="SCORE">
									<!-- <u--input disabled disabledColor="#fff" fontSize="14px" v-model="item.SCORE" border="none" inputAlign="right"></u--input> -->
								</u-form-item>
								<full-upload v-model="item.Nav_Files" :listProp='listPropUpload' :listPropVal='listPropValUpload' :isShowBtn="false"></full-upload>

							</view>

						</uni-collapse-item>
					</view>
				</uni-collapse>
			</u--form>
		</view>
		<view class="bottom-button">
			<u-button color="#3d4b70" type="primary" class="bottom" v-if='isLoadOK&&tableKey==1&&isView' @click="onTableBtnAgree" :disabled="isAgree">确认</u-button>
			<!--审核 =》 WB008_CONFIRMPAGE 审阅 -->
			<u-button color="#3d4b70" type="primary" class="bottom" v-if='isLoadOK&&tableKey==1&&isApprove' @click="onTableBtnAudit">审阅</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'
	import {
		SubmitTrainRecord
	} from '../../../../services/apply/subPages/scWB';
	export default {
		data() {
			return {
				model: {
					Nav_Parent: {
						NAME: '',
						Nav_Project: {
							NAME: '',
							UNIT_NAME: '',
						},
						Nav_Department: {
							NAME: '',
						}
					},
					Nav_Users: [{
						SCORE: 0,
						EXAMINATION_RESULTS: '',
						EXAMINATION_RESULTS_SHOW: '',
						Nav_User: {
							NAME: ''
						}
					}]

				},
				TaskID: "",
				tableKey: '0',
				isLoadOK: false,
				ORG_ID: uni.getStorageSync('orgId'),
				listPropUpload: ['RECORD_ID'],
				listPropValUpload: [],
				isAgree: false,
				isApprove: false,
				isView: false,
				formCode: ''
			}
		},
		onLoad(option) {
			this.ID = option.ID
			this.model.ID = option.ID;
			this.TaskID = option.taskID;
			this.tableKey = option.tableKey ? option.tableKey : '0'
			this.formCode = option.FORMCODE ? option.FORMCODE : ''
			this.loadData()
		},
		methods: {
			transEXAMINATION_RESULTS(EXAMINATION_RESULTS) {
				if (EXAMINATION_RESULTS == 0) {
					return ' 不合格';
				}
				if (EXAMINATION_RESULTS == 1) {
					return ' 合格';
				}
			},
			loadData() {
				const json = initFilter(this.ORG_ID, this.model.ID, null, null, null)
				// extendRule(json, 'ID', 1, this.model.ID);
				extendInclude(json, 'Nav_Parent.Nav_User');
				extendInclude(json, 'Nav_Parent.Nav_Department');
				extendInclude(json, 'Nav_Parent.Nav_Project');
				extendInclude(json, 'Nav_Files.Nav_ImgFile');
				getRequest(json, "/WB/WBOutsourceTrainRecord/GetPersonCheck").then(res => {
					this.model = res
					//数据组装
					let Users = '';
					let users0 = res.Nav_Users;
					if (users0 && users0.length > 0) {
						for (let i = 0; i < users0.length; i++) {
							if (users0[i].SIGN_STATUS !== 1) {
								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 + " 分数:" + users0[i].SCORE + "</view></br>";
							} else {
								Users += (Users.length > 0 ? " " : "") +
									"<text style='padding:5px;line-height:30px;white-space:nowrap;'>" +
									users0[i].Nav_User.NAME + " 分数:" + users0[i].SCORE + "</text></br>";
							}
						}
					}
					if (res.TRAIN_TYPE.indexOf('1') > -1 && res.TRAIN_TYPE.indexOf('2') > -1) {
						this.Traintype = 3
						this.model.TRAIN_TYPE_SHOW = '线上、线下'
					} else if (res.TRAIN_TYPE.indexOf('1') > -1) {
						this.Traintype = 1
						this.model.TRAIN_TYPE_SHOW = '线上'
					} else if (res.TRAIN_TYPE.indexOf('2') > -1) {
						this.Traintype = 2
						this.model.TRAIN_TYPE_SHOW = '线下'
					}
					this.model.TRAIN_TIME = this.model.START_TIME?.substring(0, 16) + "~" + this
						.model.END_TIME?.substring(0, 16);
					this.model.Users = Users
					this.model.Nav_Users.forEach(e => {
						e.EXAMINATION_RESULTS_SHOW = this.transEXAMINATION_RESULTS(e.EXAMINATION_RESULTS)
					})
					if (res.STATUS >= 3 && this.formCode !== 'SE050_SHOWPRINT' && this.tableKey !== undefined) {
						this.isApprove = true
					}
					let userid = uni.getStorageSync('appInfo').User.ID
					if (res.STATUS == 1 && res.Nav_Users.find(it => it.USER_ID == userid)) {
						this.isView = true

					}
					this.isLoadOK = true;

				})
			},
			openTest(id,userid) {
				uni.navigateTo({
					url: '1WBanswerPageEdit?ID=' + id+ "&USER_ID=" + userid
				})
			},
			onTableBtnAgree() {
				this.isAgree = true;
				const json = initFilter(this.ORG_ID, "", "", 1)
				json.Keyword = this.ID;
				json.Parameter1 = this.TaskID;
				getRequest(json, "/WB/WBOutsourceTrainRecord/SignIn").then(res => {
					if (res) {
						uni.$showMsgFunc('操作成功!', () => {
							uni.navigateBack()
						}, 'success', 1000)
					}
				})
			},
			onTableBtnAudit() {
				const json = initFilter(this.ORG_ID, this.ID)
				json.Parameter1 = this.TaskID;
				SubmitTrainRecord(json).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");
</style>