<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="PLAN_YEAR" borderBottom>
					<u--input v-model="model.PLAN_YEAR" border="none" slot="right" inputAlign="right" disabled
						disabledColor="#ffffff"></u--input>
				</u-form-item>
				<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.NAME" 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="PLAN_NAME" borderBottom>
					<u--input v-model="model.PLAN_NAME" border="none" slot="right" inputAlign="right" disabled
						disabledColor="#ffffff"></u--input>
				</u-form-item>
				<u-form-item label="培训目标：" prop="TRAIN_GOAL" borderBottom>
				</u-form-item>
				<rich-text autoHeight v-model="model.TRAIN_GOAL" border="none"></rich-text>
				<u-form-item label="实施要求：" prop="IMPLEMENT_REQUIREMENT" borderBottom>
					<u--input v-model="model.IMPLEMENT_REQUIREMENT" border="none" inputAlign="right" disabled
						disabledColor="#ffffff"></u--input>
				</u-form-item>

				<u-form-item label="发送部门：" prop="yearDepartment" borderBottom>
					<u--input v-html="yearDepartment" 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_YearTrainPlanDetail">
								<u-collapse-item
									:title="index + 1 + '. ' + item.MOON+'月 | '+ item.NAME+' | '+item.Content">
									<u-form-item label="培训月份" prop="MOON" borderBottom>
										<u--input disabled disabledColor="#fff" v-html="item.MOON" border="none"
											slot="right"></u--input>
									</u-form-item>
									<u-form-item label="培训类型" prop="Nav_TrainTypeEnum.NAME" borderBottom>
										<u--input disabled disabledColor="#fff" v-html="item.Nav_TrainTypeEnum.NAME"
											border="none" slot="right"></u--input>
									</u-form-item>
									<u-form-item label="培训名称" prop="NAME" borderBottom>
										<u--input disabled disabledColor="#fff" v-html="item.NAME" border="none"
											slot="right"></u--input>
									</u-form-item>
									<u-form-item label="培训内容" prop="Content" borderBottom>
										<u--input disabled disabledColor="#fff" v-html="item.Content" border="none"
											slot="right"></u--input>
									</u-form-item>
									<u-form-item label="培训级别" prop="LEVEL" borderBottom>
										<u--input disabled disabledColor="#fff" v-html="item.LEVEL" border="none"
											slot="right"></u--input>
									</u-form-item>
									<u-form-item label="培训对象" prop="OBJECT" borderBottom>
										<u--input disabled disabledColor="#fff" v-html="item.OBJECT" border="none"
											slot="right"></u--input>
									</u-form-item>
									<u-form-item label="培训地点" prop="ADDRESS" borderBottom>
										<u--input disabled disabledColor="#fff" v-html="item.ADDRESS" border="none"
											slot="right"></u--input>
									</u-form-item>
									<u-form-item label="培训形式" prop="TRAIN_MODEL" borderBottom>
										<u--input disabled disabledColor="#fff" v-html="item.TRAIN_MODEL" border="none"
											slot="right"></u--input>
									</u-form-item>
									<u-form-item label="培训教材" prop="TEACHING_MATERIAL" borderBottom>
										<u--input disabled disabledColor="#fff" v-html="item.TEACHING_MATERIAL"
											border="none" slot="right"></u--input>
									</u-form-item>
									<u-form-item label="培训老师" prop="TEACHER" borderBottom>
										<u--input disabled disabledColor="#fff" v-html="item.TEACHER" border="none"
											slot="right"></u--input>
									</u-form-item>
									<u-form-item label="考核方式" prop="Nav_TrainCheckTypeEnum" borderBottom>
										<u--input disabled disabledColor="#fff"
											v-html="item.Nav_TrainCheckTypeEnum.NAME" border="none"
											slot="right"></u--input>
									</u-form-item>
									<u-form-item label="责任部门" prop="Nav_ResponsibilityDep" borderBottom>
										<u--input disabled disabledColor="#fff" v-html="item.Nav_ResponsibilityDep.NAME"
											border="none" slot="right"></u--input>
									</u-form-item>
									<u-form-item label="责任人" prop="Nav_ResponsibilityUser" borderBottom>
										<u--input disabled disabledColor="#fff"
											v-html="item.Nav_ResponsibilityUser.NAME" border="none"
											slot="right"></u--input>
									</u-form-item>
								</u-collapse-item>
							</uni-card>
						</u-collapse>
					</u--form>
				</view>
			</view>
		</u-sticky>
		<audit-process :show="showAudit" @close="handleCloseAudit" :dataSource="auditData" />
		<check-action v-if="isLoadOK && tableKey === '1'&&isAudit==='true' " :okApi="okApi" :refuseApi="refuseApi"
			:dataSource="$store.state.auditModel"></check-action>
		<view class="bottom-button">
			<button type="primary" class="bottom" v-if='isLoadOK&&tableKey==1&&!isAudit'
				@click="onTableBtnAgree">确认</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: {},
				isAudit: false,
				TaskID: "",
				tableKey: '0',
				isLoadOK: false,
				paddingBottom: '170',
				auditData: [],
				showAudit: false,
				yearDepartment: '',
				orgId: uni.getStorageSync('orgId')
			}
		},
		onLoad(option) {
			this.model.ID = option.ID;
			this.TaskID = option.taskID;
			this.tableKey = option.tableKey ? option.tableKey : '0';
			this.isAudit = option.isAudit;
			this.okApi = option.okApi;
			this.refuseApi = option.refuseApi;
			this.loadData();
		},
		methods: {
			loadData() {
				const json = initFilter(this.orgId, "", "", 1)
				extendRule(json, 'ID', 1, this.model.ID);
				extendInclude(json, 'Nav_LaunchDepartment');
				extendInclude(json, 'Nav_LaunchUser');
				extendInclude(json, 'Nav_YearTrainPlanDepartment.Nav_Department');
				extendInclude(json, 'Nav_Files.Nav_ImgFile.Nav_File');
				extendInclude(json, 'Nav_YearTrainPlanDetail.Nav_TrainTypeEnum');
				extendInclude(json, 'Nav_YearTrainPlanDetail.Nav_YearTrainPlanContent.Nav_TestEnumPoint');
				extendInclude(json, 'Nav_YearTrainPlanDetail.Nav_TrainCheckTypeEnum');
				extendInclude(json, 'Nav_YearTrainPlanDetail.Nav_ResponsibilityDep');
				extendInclude(json, 'Nav_YearTrainPlanDetail.Nav_ResponsibilityUser');
				getRequest(json, "/SE/YearTrainPlan/Get").then(res => {
					res.Nav_YearTrainPlanDetail.sort((a,b)=>{return a.MOON-b.MOON});
					this.model = res
					let strUserFiles = [{
						url: '',
						name: ''
					}]
					if (res.Nav_YearTrainPlanDepartment && res.Nav_YearTrainPlanDepartment.length > 0) {
						for (let i = 0; i < res.Nav_YearTrainPlanDepartment.length; i++) {
							this.yearDepartment += (i + 1) + "." + res.Nav_YearTrainPlanDepartment[i]
								.Nav_Department.NAME + " "
						}
					}
					if (this.model.Nav_YearTrainPlanDetail && this.model.Nav_YearTrainPlanDetail.length > 0) {
						for (let i = 0; i < this.model.Nav_YearTrainPlanDetail.length; i++) {
							this.model.Nav_YearTrainPlanDetail[i].TRAIN_MODEL = this.returnModel(this.model
								.Nav_YearTrainPlanDetail[i].TRAIN_MODEL);
							this.model.Nav_YearTrainPlanDetail[i].Content = this.fmtPlanContentList(this.model
								.Nav_YearTrainPlanDetail[i]);
							this.model.Nav_YearTrainPlanDetail[i].LEVEL = this.transLevel(this.model
								.Nav_YearTrainPlanDetail[i].LEVEL);
						}
					}
					if (res.Nav_Files && res.Nav_Files.length > 0) {
						for (let i = 0; i < res.Nav_Files.length; i++) {
							strUserFiles.push({
								url: config.uni_app_web_source_url + res.Nav_Files[i]
									.Nav_ImgFile.Nav_File.FILE_PATH,
								name: res.Nav_Files[i].Nav_ImgFile.FILE_NAME
							})
						}
					}
					this.model.Nav_Files = strUserFiles;
					this.model.LEVEL = this.transLevel(this.model.LEVEL);
					this.model.TRAIN_TIME = this.model.TRAIN_START_TIME?.substring(0, 16) + "~" + this.model
						.TRAIN_END_TIME?.substring(0, 16);
					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 '公司 ';
				}
			},
			fmtPlanContentList(item) {
				if (!item || !item.Nav_YearTrainPlanContent)
					return '';
				let ret = [];
				for (let it of item.Nav_YearTrainPlanContent) {
					if (it.Nav_TestEnumPoint && it.Nav_TestEnumPoint.NAME)
						ret.push(it.Nav_TestEnumPoint.NAME);
				}
				return ret.join('、');
			},
			onTableBtnAgree(type) {
				let json = {
					ID: this.model.ID,
					TaskID: this.TaskID,
					ORG_ID: this.ORG_ID,
				};
				getRequest(json, "/HM/HMNoticeRelease/PersonalAgree").then(res => {
					if (res) {
						uni.$showMsgFunc('操作成功!', () => {
							uni.navigateBack()
						}, 'success', 1000)
					}
				})
			},
			loadAuditData() {
				const json = initFilter(this.orgId, this.model.ID, "CODE", 1)
				return new Promise((resolve, reject) => {
					getRequest(json, "/PF/Approve/GetApproveInfo").then(res => {
						if (res) {
							if (res && res[0].Nav_ApproveDetails.length > 0) {
								resolve(res)
							}
						} else {
							uni.showToast({
								title: '暂无审批数据',
								icon: 'none'
							})
						}
					}).catch(err => {
						reject(err)
					})
				})
			},
			handleCloseAudit() {
				this.showAudit = false
			}
		},
		async onNavigationBarButtonTap() {
			const res = await this.loadAuditData()
			if (res) {
				this.auditData = res
				this.showAudit = true
			}
		},
		computed: {

		}
	}
</script>

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