<template>
	<view class="todo-page">
		<view class="card">
			<view class="background"></view>
			<view>
				<u--form labelPosition="left" labelWidth="auto" labelAlign="center" :model="model" :rules="rules"
					ref="wForm" errorType="border-bottom" class="demo-ruleForm">
					<u-form-item required label="培训名称" prop="NAME" borderBottom>
						<u--input v-model="model.NAME" border="none" slot="right" inputAlign="right" fontSize="14px"
							placeholder="请输入培训名称"></u--input>
					</u-form-item>
					<u-form-item required label="培训类型" prop="Nav_TrainType.NAME" borderBottom
						@click="handleChange('Nav_TrainType','')">
						<u--input v-if="model.Nav_TrainType" v-model="model.Nav_TrainType.NAME" placeholder="请选择培训类型"
							border="none" inputAlign="right" disabled disabledColor="#fff" fontSize="14px"></u--input>
						<u-icon style="margin-left: 4px;" slot="right" name="arrow-down" size="12">
						</u-icon>
					</u-form-item>
					<u-form-item label="培训性质" prop="IN_OUT_SHOW" borderBottom
						@click="handleShowSheet({title: '培训性质', name: 'TrainInOut'})">
						<u--input :value="model.IN_OUT_SHOW" placeholder="请选择培训性质" border="none" inputAlign="right"
							disabled disabledColor="#fff" fontSize="14px"></u--input>
						<u-icon style="margin-left: 4px;" slot="right" name="arrow-down" size="12"></u-icon>
					</u-form-item>
					<u-form-item required label="培训级别" prop="LEVEL_SHOW" borderBottom
						@click="handleShowSheet({title: '层级', name: 'FMDepartmentType'})">
						<u--input :value="model.LEVEL_SHOW" placeholder="请选择层级" border="none" inputAlign="right"
							disabled disabledColor="#fff" fontSize="14px"></u--input>
						<u-icon style="margin-left: 4px;" slot="right" name="arrow-down" size="12"></u-icon>
					</u-form-item>
					<u-form-item label="开始时间" required prop="TRAIN_START_TIME" borderBottom
						@click="showCheckDate({ name: 'TRAIN_START_TIME'})">
						<u--input disabledColor="#fff" v-model="model.TRAIN_START_TIME" disabled placeholder="请选择开始时间"
							suffixIcon="arrow-down" suffixIconStyle="font-size:12px" fontSize="14px" border="none"
							customStyle="margin:0px;display:flex;padding:3px 0px" inputAlign="right">
						</u--input>
					</u-form-item>
					<u-form-item label="结束时间" required prop="TRAIN_END_TIME" borderBottom
						@click="showCheckDate({name: 'TRAIN_END_TIME'})">
						<u--input disabledColor="#fff" v-model="model.TRAIN_END_TIME" disabled placeholder="请选择结束时间"
							suffixIcon="arrow-down" suffixIconStyle="font-size:12px" fontSize="14px" border="none"
							inputAlign="right" customStyle="margin:0px;display:flex;padding:3px 0px">
						</u--input>
					</u-form-item>
					<u-form-item label="签到开始时间" prop="DT_START_SIGN" borderBottom
						@click="showCheckDate({name: 'DT_START_SIGN'})">
						<u--input disabledColor="#fff" v-model="model.DT_START_SIGN" disabled placeholder="请选择签到开始时间"
							suffixIcon="arrow-down" suffixIconStyle="font-size:12px" fontSize="14px" border="none"
							inputAlign="right" customStyle="margin:0px;display:flex;padding:3px 0px">
						</u--input>
					</u-form-item>
					<!-- <u-form-item label="是否触发培训通知反馈" required prop="ISSENDNOTICE" borderBottom >
						<u--input disabledColor="#fff" v-model="model.ISSENDNOTICE" disabled placeholder="请选择是否触发培训通知" suffixIcon="arrow-down" suffixIconStyle="font-size:12px" fontSize="14px" border="none"
							inputAlign="right" customStyle="margin:0px;display:flex;padding:3px 0px">
						</u--input>
					</u-form-item> -->
					<u-form-item v-if="isAdd==1" label="是否触发培训通知反馈：" prop="ISSENDNOTICE" borderBottom>
						<u-switch v-model="model.ISSENDNOTICE" @change="changeSwitch($event,'ISSENDNOTICE')"
							border="none" slot="right" inputAlign="right"></u-switch>
					</u-form-item>
					<u-form-item required label="培训地点" prop="TRAIN_ADDR" borderBottom>
						<u--input v-model="model.TRAIN_ADDR" border="none" slot="right" inputAlign="right"
							fontSize="14px" placeholder="请填写培训地点"></u--input>
					</u-form-item>
					<u-form-item required label="培训学时" prop="HOURS" borderBottom>
						<u--input v-model="model.HOURS" type="number" border="none" slot="right" placeholder="请填写培训学时"
							inputAlign="right" fontSize="14px"></u--input>
					</u-form-item>
					<u-form-item required label="培训老师" prop="Nav_UserTeacher.NAME" borderBottom
						@click="handleChange('Nav_UserTeacher','')">
						<u--input v-model="(model.Nav_UserTeacher||{}).NAME" border="none" placeholder="请选择培训老师"
							inputAlign="right" fontSize="14px"></u--input>
						<u-icon style="margin-left: 4px;" slot="right" name="arrow-down" size="12">
						</u-icon>
					</u-form-item>
					<u-form-item required label="培训形式" prop="TRAINTYPE_SHOW" borderBottom
						@click="handleShowSheet({title: '培训形式', name: 'TrainType'})">
						<u--input v-model="model.TRAINTYPE_SHOW" placeholder="请选择培训形式" border="none" inputAlign="right"
							disabled disabledColor="#fff" fontSize="14px"></u--input>
						<u-icon style="margin-left: 4px;" slot="right" name="arrow-down" size="12"></u-icon>
					</u-form-item>
					<u-form-item required label="考核方式" prop="CHECKTYPE_SHOW" borderBottom
						@click="handleShowSheet({title: '培训形式', name: 'PlanCheckType'})">
						<u--input v-model="model.CHECKTYPE_SHOW" placeholder="请选择考核方式" border="none" inputAlign="right"
							disabled disabledColor="#fff" fontSize="14px"></u--input>
						<u-icon style="margin-left: 4px;" slot="right" name="arrow-down" size="12">
						</u-icon>
					</u-form-item>
					<u-form-item class="custom-form-item" label="培训课件" prop="DetailPost" borderBottom
						@click="handleQuerySelect({ formIndex: 'Nav_ListCour', isMultiple: true})">
						<view slot="right" class="custom-form-item-right">
							<view class="multi">
								<u--text v-for="(i, k) in model.Nav_ListCour" :key="k" class="item"
									:text="k + 1 + '. ' + i.Nav_Cour.NAME" :size="14"></u--text>
							</view>
							<u-icon class="icon" name="arrow-down" size="12">
							</u-icon>
						</view>
					</u-form-item>
					<u-form-item class="custom-form-item" label="培训内容" prop="DetailPost" borderBottom
						@click="handleQuerySelect({ formIndex: 'Nav_TrainContentList', isMultiple: true})">
						<view slot="right" class="custom-form-item-right">
							<view class="multi">
								<u--text v-for="(i, k) in model.Nav_TrainContentList" :key="k" class="item"
									:text="k + 1 + '. ' + i.Nav_Point.NAME" :size="14"></u--text>
							</view>
							<u-icon class="icon" name="arrow-down" size="12">
							</u-icon>
						</view>
					</u-form-item>
					<u-form-item label="培训安排及要求" prop="TRAIN_PLAN" borderBottom>
					</u-form-item>
					<u--textarea required v-model="model.TRAIN_PLAN" border="surround"></u--textarea>
					<u-form-item label="是否需要培训效果评估" prop="NEED_EVALUATION" borderBottom
						@click="handleShowSheet({title: '是否需要培训效果评估', name: 'SETrainNeedSuvey'})">
						<u--input :value="model.NEED_EVALUATION_SHOW" placeholder="请选择" border="none" inputAlign="right"
							disabled disabledColor="#fff"></u--input>
						<u-icon style="margin-left: 4px;" slot="right" name="arrow-down" size="12"></u-icon>
					</u-form-item>
					<u-form-item label="是否触发培训记录" prop="CREATE_NOTIFY_RECORD" borderBottom>
						<u-switch inactiveColor="rgb(230, 230, 230)" size="24" space="4"
							v-model="model.CREATE_NOTIFY_RECORD" @change="changeSwitch($event,'CREATE_NOTIFY_RECORD')"
							border="none" slot="right" inputAlign="right"></u-switch>
					</u-form-item>
					<u-form-item required label="记录人员" prop="Nav_RecordUser.NAME" borderBottom
						@click="handleChange('Nav_RecordUser','')">
						<u--input v-if="model.Nav_RecordUser" v-model="model.Nav_RecordUser.NAME" placeholder="记录人员"
							border="none" inputAlign="right" disabled disabledColor="#fff"></u--input>
						<u-icon style="margin-left: 4px;" slot="right" name="arrow-down" size="12">
						</u-icon>
					</u-form-item>
					<view class="upload-title">附件</view>
					<full-upload v-model="model.Nav_Files" :isShowBtn='true' :listProp='listPropUpload'
						:listPropVal='listPropValUpload'></full-upload>
					<u-form-item required label="培训人员">
						<u-icon name="man-add" @click="handleShowUserSelector()" size="24" color="#3d9cff"
							slot="right"></u-icon>
					</u-form-item>
					<!-- <view v-show="!!model.Nav_TrainUserList.length" class="tag-view">
						<uni-tag class="tag" v-for="(i, k) in model.Nav_TrainUserList.filter(i => !i.IS_DELETED)"
							:key="k" :inverted="true" :text="i.NAME" type="primary" />
					</view> -->
					<view v-show="!!model.Nav_TrainUserList.length" class="tag-view">
						<uni-tag class="tag" v-for="(i, k) in model.Nav_TrainUserList.filter(i => !i.IS_DELETED)"
							:key="k" :inverted="true" :text="i.Nav_User.NAME" type="primary" />
					</view>
				</u--form>
			</view>
		</view>
		<query-selector :show="showPopup" :lists="Lists" @close="handleClosePopup" @search="handleSearch"
			@select="handleSelected" />
		<u-picker :show="comPickerInfo.showSheet" :columns="comPickerInfo.columns" @confirm="onConfirmPicker"
			:defaultIndex="[0]" @close="closePicker" @cancel="closePicker" keyName="NAME"></u-picker>
		<view class="bottom-button">
		</view>
		<u-datetime-picker :show="dateTimePickerInfo.showCheckDate" mode="datetime"
			v-model='dateTimePickerInfo.defaultDateTime' :formatter="formatter" @confirm="handleCheckDate"
			@close="dateTimePickerInfo.showCheckDate = false;"
			@cancel="dateTimePickerInfo.showCheckDate = false;"></u-datetime-picker>
		<query-selector :multiple="qsCom.isMultiple" :total="curTotal" :show="qsCom.show" :lists="qsCom.lists"
			@close="onCloseQS" @search="onSearchQS" @select="onSelectedQS" :defaultChecked="qsCom.defaultChecked" />
		<people-selector :defaultChecked="peopleSelectOption.defaultChecked" :show="peopleSelectOption.showSelector"
			@select="handleSelectorPeople" @close="peopleSelectOption.showSelector = false">
		</people-selector>
		<view class="bottom-button">
			<u-button type="primary" @click="submit" color="#3d4b70">提交</u-button>
		</view>
	</view>
</template>

<script>
	import {
		extendFilterGroup,
		extendGroupRule,
		extendInclude,
		extendOrder,
		extendRule,
		guid,
		initFilter,
		initFilterGroup,
		transformData
	} from '../../../../utils/common'
	import {
		getRequest,
	} from '../../../../services/apply/FOServices/FOServices';
	import {
		getEnum,
		GetEnumAnyOrder
	} from '../../../../services/common';
	export default {
		data() {
			return {
				Lists: [],
				listPropUpload: ['NOTIFY_ID'],
				listPropValUpload: [],
				model: {
					Nav_TrainUserList: [],
					ORG_ID: "",
					Nav_Files: [],
					NEED_EVALUATION_SHOW: "",
					NEED_EVALUATION: "",
					CREATE_NOTIFY_RECORD: true,
					IN_OUT_SHOW: '',
					IN_OUT: '',
				},
				options: [{
					text: '删除',
					style: {
						backgroundColor: '#f56c6c'
					}
				}],
				rules: {
					'NAME': {
						type: 'string',
						required: true,
						trigger: ['blur', 'change'],
						message: '请填写培训名称'
					},
					'Nav_TrainType.NAME': {
						type: 'string',
						required: true,
						trigger: ['blur', 'change'],
						message: '请选择培训类型'
					},
					'LEVEL_SHOW': {
						type: 'string',
						required: true,
						trigger: ['blur', 'change'],
						message: '请选择培训级别'
					},
					'TRAIN_START_TIME': {
						type: 'string',
						required: true,
						trigger: ['blur', 'change'],
						message: '请选择开始时间'
					},
					'TRAIN_END_TIME': {
						type: 'string',
						required: true,
						trigger: ['blur', 'change'],
						message: '请选择结束时间'
					},

					'TRAIN_ADDR': {
						type: 'string',
						required: true,
						trigger: ['blur', 'change'],
						message: '请填写培训地点'
					},
					'HOURS': {
						type: 'number',
						required: true,
						trigger: ['blur', 'change'],
						message: '请填写培训学时'
					},
					'Nav_UserTeacher.NAME': {
						type: 'string',
						required: true,
						trigger: ['blur', 'change'],
						message: '请填写培训老师'
					},
					'TRAINTYPE_SHOW': {
						type: 'string',
						required: true,
						trigger: ['blur', 'change'],
						message: '请选择培训形式'
					},
					'CHECKTYPE_SHOW': {
						type: 'string',
						required: true,
						trigger: ['blur', 'change'],
						message: '请选择考核方式'
					},
				},
				comPickerInfo: {
					showSheet: false,
					columns: [],
					title: '',
					dataIndex: undefined,
					formIndex: undefined,
					name: ''
				},
				showPopup: false,
				tableKey: '0',
				TaskID: '',
				isLoadOK: false,
				isAdd: 0,
				CheckDate1: false,
				CheckDate2: false,
				ORG_ID: uni.getStorageSync('orgId'),
				curTotal: 0,
				qsCom: {
					show: false,
					lists: [],
					defaultChecked: [],
					formIndex: undefined,
					isMultiple: false,
				},
				peopleSelectOption: {
					showSelector: false,
					value: null,
					index: 0,
					defaultChecked: []
				},
				dateTimePickerInfo: {
					showCheckDate: false,
					dataIndex: undefined,
					defaultDateTime: uni.$u.timeFormat(new Date(), 'yyyy-mm-dd hh:MM'),
					value: '',
					name: ''
				},
				formatter: null,
				enumsData: {}, // 存储所有枚举数据（键：枚举名称，值：处理后的枚举列表）
				enumsText: {}, // 存储枚举文本列表（用于下拉选择等场景）
			}
		},
		onLoad(option) {
			this.TaskID = option.taskID ? option.taskID : '';
			this.model.ID = option.ID ? option.ID : '';
			this.tableKey = option.tableKey ? option.tableKey : '0';
			this.fetchEnums(['TrainType', 'PlanCheckType', 'FMDepartmentType', 'TrainInOut', 'SETrainNeedSuvey']);
			this.isAdd = option.isAdd

		},
		methods: {
			fetchEnums(enumNames) {

				var dataParm = {
					'name': enumNames.join('|')
				}
				GetEnumAnyOrder(dataParm).then(res => {
					let newd = transformData(res, enumNames)
					this.enumsData = newd[0];
					// 生成文本列表（如需要）
					this.enumsText = newd[1]
					if (this.isAdd != 1) {
						this.loadData();
					} else {
						this.isAdd = 1;
						this.model.ID = guid();
						this.model.CREATE_NOTIFY_RECORD = true;
						this.model.IN_OUT_SHOW = this.enumsData['TrainInOut'][0].name
						this.model.IN_OUT = this.enumsData['TrainInOut'][0].code
						this.model.ISSENDNOTICE = true
					}
				})
			},
			changeSwitch(e, prop) {
				if (prop == 'ISSENDNOTICE') {
					this.model.ISSENDNOTICE = e;
				} else {
					this.model.CREATE_NOTIFY_RECORD = e;
				}
			},

			//时间start
			//显示时间控件
			showCheckDate(p) {
				if (p.name === 'TRAIN_START_TIME') {
					if (this.model.TRAIN_START_TIME == null) {
						this.model.TRAIN_START_TIME = uni.$u.timeFormat(new Date(),
							'yyyy-mm-dd hh:MM')
					}
					this.dateTimePickerInfo = {
						showCheckDate: true,
						dataIndex: p.dataIndex,
						defaultDateTime: this.model.TRAIN_START_TIME,
						name: p.name
					}
				} else if (p.name === 'TRAIN_END_TIME') {
					if (this.model.TRAIN_END_TIME == null) {
						this.model.TRAIN_END_TIME = uni.$u.timeFormat(new Date(),
							'yyyy-mm-dd hh:MM')
					}
					this.dateTimePickerInfo = {
						showCheckDate: true,
						dataIndex: p.dataIndex,
						defaultDateTime: this.model.TRAIN_END_TIME,
						name: p.name
					}
				} else if (p.name === 'DT_START_SIGN') {
					if (this.model.DT_START_SIGN == null) {
						this.model.DT_START_SIGN = uni.$u.timeFormat(new Date(),
							'yyyy-mm-dd hh:MM')
					}
					this.dateTimePickerInfo = {
						showCheckDate: true,
						dataIndex: p.dataIndex,
						defaultDateTime: this.model.DT_START_SIGN,
						name: p.name
					}
				}
			},
			handleCheckDate(e) {
				const {
					name,
					dataIndex
				} = this.dateTimePickerInfo
				if (name === 'TRAIN_START_TIME') {
					this.model.TRAIN_START_TIME = uni.$u.timeFormat(e.value, 'yyyy-mm-dd hh:MM')
					// this.model.DT_START_SIGN =uni.$u.timeFormat(new Date(e.value - 5 * 60 * 1000), 'yyyy-mm-dd hh:MM');
				} else if (name === 'TRAIN_END_TIME') {
					this.model.TRAIN_END_TIME = uni.$u.timeFormat(e.value, 'yyyy-mm-dd hh:MM')
				} else if (name === 'DT_START_SIGN') {
					this.model.DT_START_SIGN = uni.$u.timeFormat(e.value, 'yyyy-mm-dd hh:MM')
				}

				//如果开始结束时间都有 默认处理 培训学时
				if (this.model.TRAIN_START_TIME && this.model.TRAIN_END_TIME) {
					this.model.HOURS = ((new Date(this.model.TRAIN_END_TIME).getTime() - new Date(this.model
						.TRAIN_START_TIME).getTime()) / 1000 / 60 / 45.0).toFixed(1)
				}


				this.dateTimePickerInfo.showCheckDate = false
			},
			//时间end
			//单选start
			handleChange(title, item) {
				this.currentOperate = item;
				this.currSearchType = title;
				this.showPopup = true;
				this.handleSearch('init');
			},
			handleSearch(val) {
				const json = initFilter(this.ORG_ID, "", "NAME")
				json.Limit = 20
				if (val !== 'init') {
					const tempGroup = initFilterGroup(false);
					extendGroupRule(tempGroup, 'NAME', 9, val)
					extendFilterGroup(json, tempGroup);
				}
				if (this.currSearchType == "Nav_TrainType") {
					getRequest(json, "/SE/TrainTypeEnum/OrderPaged").then(res => {
						this.Lists = res.map(i => {
							return {
								...i,
								name: i.NAME,
							}
						})
					})
				} else if (this.currSearchType == "Nav_TrainCheckType") {
					getRequest(json, "/SE/TrainCheckTypeEnum/OrderPaged").then(res => {
						this.Lists = res.map(i => {
							return {
								...i,
								name: i.NAME,
							}
						})
					})
				} else if (this.currSearchType == "Nav_RecordUser" || this.currSearchType == "Nav_UserTeacher") {
					getRequest(json, "/FM/FMUser/OrderPagedUseful").then(res => {
						this.Lists = res.map(i => {
							return {
								...i,
								name: i.NAME,
							}
						})
					})
				}
			},
			handleSelected(val) {
				this.showPopup = false;
				this.Lists = [];
				if (this.currSearchType == 'Nav_TrainType') {
					this.model.Nav_TrainType = val;
					this.model.TRAIN_TYPE = val.ID;
				} else if (this.currSearchType == 'Nav_TrainCheckType') {
					this.model.Nav_TrainCheckType = val;
					this.model.CHECK_TYPE_ID = val.ID;
				} else if (this.currSearchType == 'Nav_RecordUser') {
					this.model.Nav_RecordUser = val;
					this.model.RECORD_USER_ID = val.ID;
				} else if (this.currSearchType == 'Nav_UserTeacher') {
					this.model.Nav_UserTeacher = val;
					this.model.USER_ID_TEACHER = val.ID;
					this.model.TRAIN_TEACHER = val.NAME
				}
			},
			handleClosePopup() {
				this.showPopup = false
			},
			//单选end
			//多选start
			async handleQuerySelect(opt) {
				let column = await this.handleGet(opt, 'init')
				var defaultChecked = []
				if (opt.formIndex == 'Nav_TrainContentList') {
					if (this.model.Nav_TrainContentList != null && this.model.Nav_TrainContentList.length > 0)
						this.model.Nav_TrainContentList.forEach(e => {
							defaultChecked.push(e.Nav_Point)
						})
				} else if (opt.formIndex == 'Nav_ListCour') {
					if (this.model.Nav_ListCour != null && this.model.Nav_ListCour.length > 0)
						this.model.Nav_ListCour.forEach(e => {
							defaultChecked.push(e.Nav_Cour)
						})
				}
				if (column && column.length) {
					this.qsCom = {
						show: true,
						name: opt.NAME,
						formIndex: opt.formIndex,
						isMultiple: opt.isMultiple,
						lists: column,
						defaultChecked: defaultChecked
					}
				}
			},
			async onSearchQS(val, pi) {
				const result = await this.handleGet(this.qsCom, val, pi)
				this.qsCom.lists = result.map(i => {
					return {
						...i,
						name: i.NAME,
						NAME: i.NAME,
						id: i.ID
					}
				})
			},
			async handleGet(opt, value, pageIndex) {
				var api = (opt.formIndex == 'Nav_TrainContentList') ? '/SE/TestEnumPoint/OrderPaged' :
					'/SE/Coursewearlibrary/OrderPaged'
				const json = initFilter(this.ORG_ID, '', "", 0, pageIndex || 1)
				if (value !== 'init') {
					const tempGroup = initFilterGroup(false);
					extendGroupRule(tempGroup, 'NAME', 9, value)
					extendFilterGroup(json, tempGroup);
				}
				json.Limit = 20
				if (pageIndex) {
					json.Start = (pageIndex - 1) * 20;
				}
				let result = []
				const raw = await getRequest(json, api).then(res => {
					this.curTotal = res.TotalCount
					return res
				})
				result = raw.map(item => {
					return {
						...item,
						name: item?.NAME,
						POINT_ID: item?.ID
					}
				})
				return result
			},
			onSelectedQS(val) {
				const {
					formIndex,
				} = this.qsCom
				//formIndex  Nav_ListCour  Nav_TrainContentList
				if (formIndex == 'Nav_TrainContentList') {
					this.model.Nav_TrainContentList = [];
					val.forEach(item => {
						let obj = {
							POINT_ID: item.ID,
							Nav_Point: {
								ID: item.ID,
								NAME: item.NAME
							},
							ID: guid(),
							NOTIFY_ID: this.model.ID,
							ORG_ID: this.ORG_ID,
						}
						this.model.Nav_TrainContentList.push(obj);
					})
				} else if (formIndex == 'Nav_ListCour') {
					this.model.Nav_ListCour = [];
					val.forEach(item => {
						let obj = {
							COURSEWEARLIBRARY_ID: item.ID,
							Nav_Cour: {
								ID: item.ID,
								NAME: item.NAME
							},
							ID: guid(),
							NOTIFY_ID: this.model.ID,
							ORG_ID: this.ORG_ID,
						}
						this.model.Nav_ListCour.push(obj);
					})
				}
				this.qsCom.show = false
				this.qsCom.defaultChecked = []
			},
			onCloseQS() {
				this.qsCom = {
					show: false,
					lists: [],
					formIndex: undefined,
					isMultiple: false,
					dataIndex: undefined
				}
			},
			//多选end
			//人员多选start
			handleShowUserSelector() {
				this.peopleSelectOption = {
					showSelector: true,
					value: this.model,
					defaultChecked: this.model.Nav_TrainUserList.map(i => {
						return {
							...i,
							NAME: i.Nav_User.NAME,
							USER_ID: i.Nav_User.ID,
						}
					})
				}
			},
			handleSelectorPeople(e) {
				this.model.Nav_TrainUserList = e.map(i => {
					return {
						USER_ID: i.USER_ID,
						ID: i.ID || guid(),
						NOTIFY_ID: this.model.ID,
						ORG_ID: this.ORG_ID,
						IS_DELETED: i.IS_DELETED,
						NAME: i.NAME,
						Nav_User: {
							NAME: i.NAME,
							ID: i.USER_ID
						}
					}
				})
			},
			//人员多选end
			loadData() {
				const json = initFilter(this.ORG_ID, "", "")
				if (this.listPropValUpload.length == 0) {
					this.listPropValUpload.push(this.model.ID)
				}
				extendInclude(json, "Nav_TrainContentList.Nav_Point")
				extendInclude(json, "Nav_LaunchDepartment")
				extendInclude(json, "Nav_TrainType")
				extendInclude(json, "Nav_UserTeacher")
				extendInclude(json, "Nav_RecordUser")
				extendInclude(json, "Nav_TrainContentList")
				extendInclude(json, "Nav_TrainUserList.Nav_User")
				extendInclude(json, "Nav_TrainUserList")
				extendInclude(json, "Nav_Files.Nav_ImgFile")
				// TODO: id 未获取
				extendRule(json, 'ID', 1, this.model.ID)
				getRequest(json, "/SE/TrainNotify/Get").then(res => {
					this.model = res
					// ISSENDNOTICE
					this.model.LEVEL_SHOW = res.LEVEL !== undefined ? this.enumsData['FMDepartmentType'].find(
						item => item.code === res.LEVEL)?.name : '';
					this.model.TRAINTYPE_SHOW = res.TRAINTYPE !== undefined ? this.enumsData['TrainType'].find(
						item => item.code === res.TRAINTYPE)?.name : '';
					this.model.CHECKTYPE_SHOW = res.CHECKTYPE !== undefined ? this.enumsData['PlanCheckType'].find(
						item => item.code === res.CHECKTYPE)?.name : '';
					this.model.IN_OUT_SHOW = res.IN_OUT !== undefined ? this.enumsData['TrainInOut'].find(item =>
						item.code === res.IN_OUT)?.name : '';
					this.model.NEED_EVALUATION_SHOW = res.NEED_EVALUATION !== undefined ? this.enumsData[
						'SETrainNeedSuvey'].find(item => item.code === res.NEED_EVALUATION)?.name : '';
				})
			},
			closePicker() {
				this.comPickerInfo = {
					showSheet: false,
					columns: [],
					title: '',
					name: '',
					dataIndex: undefined,
					formIndex: undefined
				}
			},
			async handleShowSheet(p, index) {
				let column = []
				this.levelIndex = index;
				column = this.enumsData[p.name]
				if (column.length) {
					this.comPickerInfo = {
						showSheet: true,
						title: p.title,
						name: p.name,
						formIndex: p.formIndex,
						columns: [column]
					}
				} else {
					// 暂无数据
				}
			},
			onConfirmPicker(e) {
				const {
					name,
					formIndex
				} = this.comPickerInfo
				if (name == 'TrainType') {
					this.model.TRAINTYPE_SHOW = e.value[0].name
					this.model.TRAINTYPE = this.enumsData['TrainType'][e.indexs[0]].code
				} else if (name == 'PlanCheckType') {
					this.model.CHECKTYPE_SHOW = e.value[0].name
					this.model.CHECKTYPE = this.enumsData['PlanCheckType'][e.indexs[0]].code
				} else if (name == 'FMDepartmentType') {
					this.model.LEVEL_SHOW = e.value[0].name
					this.model.LEVEL = this.enumsData['FMDepartmentType'][e.indexs[0]].code
				} else if (name == 'SETrainNeedSuvey') {
					this.model.NEED_EVALUATION_SHOW = e.value[0].name
					this.model.NEED_EVALUATION = this.enumsData['SETrainNeedSuvey'][e.indexs[0]].code
				} else if (name == 'TrainInOut') {
					this.model.IN_OUT_SHOW = e.value[0].name
					this.model.IN_OUT = this.enumsData['TrainInOut'][e.indexs[0]].code
				}



				this.comPickerInfo.showSheet = false
			},
			transLevel(level) {
				if (level == 0) {
					return '部门 ';
				}
				if (level == 1) {
					return '车间 ';
				}
				if (level == 2) {
					return '班组 ';
				}
				if (level == 3) {
					return '公司 ';
				}
			},
			submit() {
				const ele = this.$refs
				ele['wForm'].validate().then(res => {
					this.modelEdit = JSON.parse(JSON.stringify(this.model))
					this.modelEdit.PUBLISH = "SaveAndNotify";
					if (this.TaskID != "") {
						this.modelEdit.TaskID = this.TaskID;
					}
					if (this.modelEdit.ORG_ID == "") {
						this.modelEdit.ORG_ID = this.ORG_ID;
					}
					this.modelEdit.Nav_TrainUserList.forEach(item => {
						item.Nav_User = null;
					});
					this.modelEdit.TRAIN_START_TIME = uni.$u.timeFormat(this.modelEdit.TRAIN_START_TIME,
						'yyyy-mm-dd hh:MM:ss');
					this.modelEdit.TRAIN_END_TIME = uni.$u.timeFormat(this.modelEdit.TRAIN_END_TIME,
						'yyyy-mm-dd hh:MM:ss');
					this.modelEdit.Nav_UserTeacher = null;
					this.modelEdit.Nav_TrainType = null;
					this.modelEdit.Nav_TrainCheckType = null;
					this.modelEdit.Nav_RecordUser = null;
					this.modelEdit.Nav_Files.forEach(item => {
						if (item.NOTIFY_ID == undefined) {
							item.NOTIFY_ID = this.modelEdit.ID;
						}
						if (item.ORG_ID == undefined) {
							item.ORG_ID = this.modelEdit.ORG_ID;
						}
					});
					getRequest(this.modelEdit, "/SE/SETrainNotify/FullUpdate").then(res => {
						if (res) {
							uni.$showMsgFunc('操作成功!', () => {
								uni.navigateBack()
							}, 'success', 1000)
						}
					})
				}).catch(err => {
					uni.$showErrorInfo(err[0].message)
				})
			},

		}
	}
</script>

<style scoped>
	/* @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 140px 16px;
		/* border: 1px solid #EBEEF5; */
		padding: 20px 30px 80px 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;
	}

	.bottom-button {
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
		padding: 10px 16px;
		box-sizing: border-box;
		background: #edf1fd;
		z-index: 999;
	}

	/*定制表单右边*/
	.custom-form-item>>>.item__body__right__content__icon {
		width: 100%;
	}

	.custom-form-item-right {
		padding-left: 15px;
		display: flex;
	}

	.custom-form-item-right .item {
		/*white-space: nowrap;*/
		/*overflow: hidden;*/
		/* justify-content: flex-end !important; */
	}

	.custom-form-item-right .multi {
		width: 100%;
		flex: 1;
	}

	.custom-form-item-right .icon {
		width: 16px;
		margin-left: 10px;
	}
</style>