<template>
	<view class="todo-page">
		<view class="background"></view>
		<view class="card" v-if="stepsPageList === 0">
			<!-- <uni-card margin="0" :is-shadow="true"> -->
			<u--form labelPosition="left" labelWidth="auto" labelAlign="center" :model="dataModel" class="demo-ruleForm" ref="wForm" errorType="border-bottom">
				<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="CONTEXT" borderBottom v-if="dataModel.IS_PUBLISH==9">
					</u-form-item>
					<u--textarea v-html="dataModel.CONTEXT" border="surround" v-if="dataModel.IS_PUBLISH==9"
						disabled></u--textarea> -->
				<u-form-item label="监测时间" prop="SET_TIME" borderBottom>
					<u--input v-model="dataModel.SET_TIME" disabled disabledColor="#ffffff" placeholder="请输入监测时间" border="none" inputAlign="right" fontSize="14px">
					</u--input>
				</u-form-item>
				<u-form-item label="监测班组" prop="DepartmentName" borderBottom>
					<u--input v-model="dataModel.Nav_Department.NAME" disabled disabledColor="#ffffff" placeholder="请输入监测部门" border="none" inputAlign="right" fontSize="14px"></u--input>
				</u-form-item>
				<!-- <u-form-item label="监测人员" prop="UserName" borderBottom>
						<u--input v-model="dataModel.Nav_User.NAME" disabled disabledColor="#ffffff" placeholder="请输入监测人员" border="none"
							inputAlign="right"></u--input>
					</u-form-item> -->
				<u-form-item label="监测年度" prop="YEAR" borderBottom>
					<u--input v-model="dataModel.YEAR" disabled disabledColor="#ffffff" placeholder="请输入年度" border="none" inputAlign="right" fontSize="14px">
					</u--input>
				</u-form-item>
				<!-- <u-form-item label="部门层级" prop="DEPARTMENT_TYPE_SHOW" borderBottom>
					<u--input v-model="dataModel.DEPARTMENT_TYPE_SHOW" disabled disabledColor="#ffffff" placeholder="请输入部门层级" border="none" inputAlign="right" fontSize="14px">
					</u--input>
				</u-form-item> -->
				<u-form-item label="监测周期" prop="ASSESSMENT_CYCLE_SHOW" borderBottom>
					<u--input v-model="dataModel.ASSESSMENT_CYCLE_SHOW" disabled disabledColor="#ffffff" border="none" inputAlign="right" fontSize="14px"></u--input>
					<!-- <u-icon style="margin-left: 4px;" slot="right" name="arrow-down">
					</u-icon> -->
				</u-form-item>
				<u-form-item label="监测人员" prop="UserName" borderBottom @click="handleShowSheet({title: '监测人员', name: 'UserNames'})">
					<u--input v-model="dataModel.UserNames" disabled disabledColor="#ffffff" placeholder="请输入监测人员" border="none" inputAlign="right" fontSize="14px"></u--input>
					<u-icon style="margin-left: 4px;" name="arrow-down" size="12"></u-icon>
				</u-form-item>
			</u--form>
			<!-- </uni-card> -->
		</view>
		<view style="padding: 10px 16px;" v-if="stepsPageList === 0" class="bottom-button">
			<u-button type="primary" :disabled="isLoadOK" @click="stepAdd" color="#3d4b70">下一步</u-button>
		</view>
		<view class="card" v-if="stepsPageList === 1">
			<!-- <view class="sub-form-wrap"> -->
			<!-- 	<view class="sub-form-btns">
					<view class="sub-form-btn" @click="handleAddUser">
						<u-icon class="icon" name="plus-circle" color="#3c9cff" size="21"></u-icon>
						<u--text type="primary" text="新增作业人员"></u--text>
					</view>
				</view> -->
			<u--form labelPosition="left" labelWidth="auto" labelAlign="center" errorType="border-bottom" ref="sForm1" class="sub-form">
				<uni-collapse :border="false" accordion ref="collapse">
					<!-- <view v-for="(item, index) in dataModel.Nav_Details" :key="index"> -->
					<uni-collapse-item title-border="none" :border="false" v-for="(item, index) in dataModel.Nav_Details.filter(i => !i.IS_DELETED)" :key="index">
						<template v-slot:title>
							<view class="uni-collapse-item__title-box">
								<view class="uni-collapse-item__title-text">
									{{index+1+'.'+item['Nav_Department'].NAME+'-'+item['Nav_User'].NAME}}
								</view>
								<view @click.stop style="margin-right: 10px;">
									<u-icon @click="handleDelRowBefore(item)" name="trash" color="#ff4d4f" size="21" style="margin-right: 10px;"></u-icon>
									<!-- <u-icon name="arrow-down" size="12"></u-icon> -->
								</view>
							</view>
						</template>
						<view class="content" style="padding: 0px 10px;">
							<u-form-item required label="被考核组织" prop="ChildDepartName" borderBottom @click="handleShowSheet({title: '被考核组织', name: 'SubDep'},item)">
								<u--input fontSize="14px" disabled disabledColor="#fff" v-model="item['Nav_Department'].NAME" border="none" inputAlign="right"></u--input>
								<u-icon style="margin-left: 4px;" name="arrow-down" size="12"></u-icon>
							</u-form-item>
							<u-form-item label="被考核人员" prop="ChildUserName" borderBottom @click="handleShowSheet({title: '被考核人员', name: 'SubName'},item)">
								<u--input fontSize="14px" disabled disabledColor="#fff" v-model="item['Nav_User'].NAME" border="none" inputAlign="right"></u--input>
								<u-icon style="margin-left: 4px;" name="arrow-down" size="12"></u-icon>
							</u-form-item>
							<u-form-item label="岗位" prop="ChildUserName" borderBottom>
								<u--input fontSize="14px" disabled disabledColor="#fff" v-model="item['Nav_User'].Nav_Person.Nav_Post.NAME" border="none" inputAlign="right" v-if="item.Nav_Person&&item.Nav_Person.Nav_Post&&item.Nav_Person.Nav_Post.NAME"></u--input>
							</u-form-item>
							<u-form-item label="安全生产目标与指标" prop="UserNames" borderBottom>
								<u-button text="新增" type="primary" @click="handleAdd(item)" size="small" style="margin-left: 40px;"></u-button>
							</u-form-item>
							<uni-collapse :border="false" accordion @change="handleHeight">
								<!-- <view v-for="(item1, index1) in item.Nav_Contents" :key="index1"> -->
								<uni-collapse-item title-border="none" :border="false" v-for="(item1, index1) in item.Nav_Contents.filter(i => !i.IS_DELETED)" :key="'d'+index1" style="padding: 0px 10px;">
									<template v-slot:title>
										<view class="uni-collapse-item__title-box">
											<view class="uni-collapse-item__title-text">
												{{index+1+'-'+(index1+1)+'.'+item1.NAME}}
											</view>
											<view @click.stop style="margin-right: 10px;">
												<u-icon @click="handleDelRowBefore(item1)" name="trash" color="#ff4d4f" size="21" style="margin-right: 10px;"></u-icon>
												<!-- <u-icon name="arrow-down" size="12"></u-icon> -->
											</view>
										</view>
									</template>
									<view class="content" style="padding: 0px 0px 0px 10px;">
										<u-form-item required label="安全生产指标考核项目" prop="YEAR" borderBottom>
											<u--input v-model="item1.NAME" disabledColor="#ffffff" placeholder="请输入项目" border="none" inputAlign="right" fontSize="14px">
											</u--input>
										</u-form-item>
										<u-form-item required label="分数" prop="YEAR" borderBottom>
											<u--input v-model="item1.SCORE" disabledColor="#ffffff" placeholder="请输入分数" border="none" inputAlign="right" fontSize="14px">
											</u--input>
										</u-form-item>
										<u-form-item label="考核认定评分办法" prop="YEAR" borderBottom>
											<u--input v-model="item1.METHOD" disabledColor="#ffffff" placeholder="请输入办法" border="none" inputAlign="right" fontSize="14px">
											</u--input>
										</u-form-item>
										<u-form-item label="考核检查情况" prop="YEAR">
											<!-- <u--input v-model="item1.CONTENT" disabledColor="#ffffff" placeholder="请输入考核检查情况" border="none" inputAlign="right" fontSize="14px">
											</u--input> -->
										</u-form-item>
										<u--textarea v-model="item1.CONTENT" placeholder="请输入内容"></u--textarea>
										<u-form-item label="改进措施" prop="YEAR">
											<!-- <u--input v-model="item1.MEASURES" disabledColor="#ffffff" placeholder="请输入改进措施" border="none" inputAlign="right" fontSize="14px">
											</u--input> -->
										</u-form-item>
										<u--textarea v-model="item1.MEASURES" placeholder="请输入内容"></u--textarea>
										<u-form-item required label="得分" prop="YEAR" borderBottom>
											<u--input v-model="item1.RESULT_SCORE" disabledColor="#ffffff" placeholder="请输入得分" border="none" inputAlign="right" fontSize="14px">
											</u--input>
										</u-form-item>
									</view>
								</uni-collapse-item>
								<!-- </view> -->
							</uni-collapse>

						</view>

					</uni-collapse-item>
					<!-- </view> -->
				</uni-collapse>
				<u-button text="新增" type="primary" @click="handleAdds"></u-button>
			</u--form>
			<!-- </view> -->
		</view>

		<!-- <u-sticky offset-top="20">
			<view class="sub-form">
				<uni-collapse :border="false" accordion>
					<uni-card margin="0" spacing="0" padding="0" :is-shadow="true">
						<uni-collapse-item title="考核明细">
							<view class="sub-form-wrap" style="height: 500px; overflow: auto">
								<u--form labelPosition="left" labelWidth="auto" labelAlign="center" :model="subDataModel" ref="sForm2" errorType="border-bottom">
									<u-swipe-action>
										<u-swipe-action-item style="margin-bottom: 16px;" :options="options" v-for="(item, index) in dataModel.Nav_Details">
											<uni-card margin="0" spacing="0" :is-shadow="false" style="margin-bottom: 10px;">
												<u-form-item label="被考核组织" prop="ChildDepartName" borderBottom>
													<u--input disabled disabledColor="#fff" v-model="item['Nav_Department'].NAME" border="none" inputAlign="right"></u--input>

												</u-form-item>
												<u-form-item label="被考核人员" prop="ChildUserName" borderBottom>
													<u--input disabled disabledColor="#fff" v-model="item['Nav_User'].NAME" border="none" inputAlign="right"></u--input>

												</u-form-item>
												<u-form-item label="安全生产目标与指标" prop="UserNames" borderBottom>
												</u-form-item>
												<u--textarea autoHeight type="textarea" v-html="item.UserNames" border="none" inputAlign="left">
												</u--textarea>
											</uni-card>
										</u-swipe-action-item>
									</u-swipe-action>
								</u--form>
							</view>
						</uni-collapse-item>
					</uni-card>
				</uni-collapse>
			</view>
		</u-sticky> -->
		<u-modal :show="showDelModalIndex >= 0" @confirm="confirmDel" title="确认删除？"></u-modal>
		<query-selector :multiple="selectorInfo.isMultiple" :show="selectorInfo.showPopup" :title="selectorInfo.title" :lists="selectorInfo.dataLists" :defaultChecked="selectorInfo.defaultChecked" @search="handleSearch"
			@select="handleSelected" @close="selectorInfo.showPopup=false" :total="selectorInfo.totalCount" />

		<u-picker :show="comPickerInfo.showSheet" :columns="comPickerInfo.columns" @confirm="onConfirmPicker" @close="closePicker" @cancel="closePicker" keyName="NAME"></u-picker>
		<!-- <view class="bottom-button">
			<button type="primary" @click="submit">提交</button>
		</view> -->
		<view style="padding: 10px 16px;display: flex;flex-direction: row;" v-if="stepsPageList === 1" class="bottom-button">
			<u-button type="primary" @click="stepReduce" color="#3d4b70" :plain="true" style="margin-right: 5px;">上一步</u-button>
			<u-button type="primary" @click="submit" color="#3d4b70" style="margin-left: 5px;">提交</u-button>
		</view>
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex'
	import {
		extendFilterGroup,
		extendGroupRule,
		extendInclude,
		extendOrder,
		extendRule,
		guid,
		initFilter,
		initFilterGroup,
		extendIgnoreDataRule
	} from '../../../../utils/common'
	import {
		getRequest,
		saveMonitorAssessment
	} from '../../../../services/apply/subPages/SCPT/PTServices'
	import {
		getUserLists,
		getDepartmentLists
	} from '../../../../services/apply/FOServices/FOServices.js'
	import config from '../../../../config/common'
	import {
		getEnum
	} from '../../../../services/common';

	export default {
		data() {
			return {
				ID: null,
				TaskID: null,
				tableKey: 0,
				curTotal: 0,
				isLoadOK: true,
				showDelModalIndex: undefined,
				stepsPageList: 0,
				listISORNOT: [], //是否涉及
				userLists: [],
				dataModel: {
					UserNames: '',
					SET_TIME: null,
					Nav_Department: {
						NAME: ''
					},
					Nav_Details: {
						Nav_User: {
							NAME: '',
							Nav_Person: {
								Nav_Post: {
									NAME: ''
								}
							}
						}

					},
					Nav_User: {
						NAME: ''
					},
				},
				subDataModel: {
					Nav_MonitorUser: {
						Nav_User: {
							NAME: '',
							CODE: '',
						},
					}
				},
				options: [{
					text: '删除',
					style: {
						backgroundColor: '#f56c6c'
					}
				}],
				comPickerInfo: {
					showSheet: false,
					columns: [],
					isMultiple: false,
					totalCount: 0,
					title: '',
					dataIndex: undefined,
					formIndex: undefined,
					name: ''
				},
				currentOperateUser: {},
				showPopup: false,
				selectorInfo: {
					name: 'user',
					isMultiple: false,
					showPopup: false,
					totalCount: 0,
					title: '考核结果选择',
					dataItem: {},
					index: 0,
					columns: [],
					dataLists: [],
					defaultText: '',
					defaultChecked: []
				},
				// rules: {
				// 	'YEAR': {
				// 		type: 'string',
				// 		required: true,
				// 		trigger: ['blur', 'change']
				// 	},
				// },
			}
		},
		onLoad(opt) {
			this.getEnums(opt)
		},
		methods: {
			getEnums(opt) {
				var dataParm = {
					'name': "PTAssessmentCycleEnums"
				}
				getEnum(dataParm).then(res => {
					this.listISORNOT = res
					this.handleGetLicenseGet(opt)
				})
			},
			handleGetLicenseGet(opt) {
				this.TaskID = opt.taskID ? opt.taskID : null;
				this.ID = opt.ID ? opt.ID : null;
				const orgId = uni.getStorageSync('orgId')
				const json = initFilter(orgId, "", "")
				extendRule(json, 'ID', 1, opt.ID)
				// TODO: id 未获取
				getRequest(json, "/PT/PTMonitorAssessment/GetEdit").then(res => {
					this.dataModel = res
					if (res.DEPARTMENT_TYPE == 0) {
						res.DEPARTMENT_TYPE_SHOW = '部门'
					} else if (res.DEPARTMENT_TYPE == 1) {
						res.DEPARTMENT_TYPE_SHOW = '车间'
					} else if (res.DEPARTMENT_TYPE == 2) {
						res.DEPARTMENT_TYPE_SHOW = '班组'
					} else {
						res.DEPARTMENT_TYPE_SHOW = '公司'
					}
					res.ASSESSMENT_CYCLE_SHOW = this.listISORNOT.find(item => item.ID === res.ASSESSMENT_CYCLE).NAME || '';
					// if (res.ASSESSMENT_CYCLE == 10) {
					// 	res.ASSESSMENT_CYCLE_SHOW = '年度'
					// } else if (res.ASSESSMENT_CYCLE == 20) {
					// 	res.ASSESSMENT_CYCLE_SHOW = '季度'
					// } else if (res.ASSESSMENT_CYCLE == 30) {
					// 	res.ASSESSMENT_CYCLE_SHOW = '月度'
					// } else {
					// 	res.ASSESSMENT_CYCLE_SHOW = '请选择'
					// }
					//数据组装
					let UsersName = ''
					if (res.Nav_MonitorUser.length > 0) {
						res.Nav_MonitorUser.forEach((item, i) => {
							if (item.Nav_User.NAME != null) {
								UsersName += item.Nav_User.NAME
							}
						})
					}
					this.dataModel.UserNames = UsersName
					if (res.Nav_Details && res.Nav_Details.length > 0) {
						for (let i = 0; i < res.Nav_Details.length; i++) {
							// let strconfirmFiles = ''
							let details = res.Nav_Details[i];
							// if (details.Nav_Contents && details.Nav_Contents.length > 0) {
							// 	for (let j = 0; j < details.Nav_Contents.length; j++) {
							// 	let depart=details.Nav_Contents[j].NAME;
							// 	strconfirmFiles += (strconfirmFiles.length > 0 ? "</br>" : "") + depart;
							// 	details.UserNames = strconfirmFiles
							// 	}
							// }
							if (details.USER_ID == null) {
								details.Nav_User = {
									NAME: '',
									Nav_Person: {
										Nav_Post: {
											NAME: ''
										}
									}
								}
							}
							if (details.DEPARTMENT_ID == null) {
								details.Nav_Department = {
									NAME: ''
								}
							}
						}
					}
					this.isLoadOK = false
				})
			},
			async handleShowSheet(p, item) {
				const validDetails = this.dataModel.Nav_Details.filter(i => !i.IS_DELETED);
				const index = validDetails.indexOf(item);
				const realIndex = this.dataModel.Nav_Details.findIndex(item => item === validDetails[index]);
				const orgId = uni.getStorageSync('orgId')
				const json = initFilter(orgId, "", "", 0, p.pageIndex ?? 1)

				let dataSelect = []
				var defaultChecked = []
				this.selectorInfo.isMultiple = false
				if (p.val) {
					const tempGroup = initFilterGroup(false);
					extendGroupRule(tempGroup, 'NAME', 9, p.val)
					extendFilterGroup(json, tempGroup);
				}
				json.Sort = "NAME"
				// json.Order = 1
				json.Limit = 20
				if (p.pageIndex) {
					json.Start = (p.pageIndex - 1) * json.Limit;
				}
				if (p.name == 'UserNames' || p.name == 'SubName') {

					if (p.name == 'UserNames') {
						extendInclude(json, "Nav_Department")
						extendRule(json, 'ENABLE_STATUS', 1, '0')
						this.selectorInfo.isMultiple = true
						const depId = this.dataModel.DEPARTMENT_ID
						if (depId != undefined && depId != '')
							extendRule(json, 'DEPARTMENT_ID', 1, depId);
					}

					if (p.name == 'SubName') {
						extendInclude(json, "Nav_Person.Nav_Post")
						const depId = this.dataModel.Nav_Details[realIndex].DEPARTMENT_ID
						if (depId != undefined && depId != '')
							extendRule(json, 'DEPARTMENT_ID', 1, depId);
					}

					dataSelect = await getUserLists(json).then(res => {
						this.selectorInfo.totalCount = res.TotalCount
						if (res != undefined && res.Data != undefined && res.Data.length > 0) {
							for (let i = 0; i < res.Data.length; i++) {
								res.Data[i].name = res.Data[i].NAME
								res.Data[i].code = res.Data[i].CODE
							}
						}
						return res.Data
					})
				} else if (p.name == 'SubDep') {
					dataSelect = await getDepartmentLists(json).then(res => {
						this.selectorInfo.totalCount = res.TotalCount
						if (res != undefined && res.Data != undefined && res.Data.length > 0) {
							for (let i = 0; i < res.Data.length; i++) {
								res.Data[i].name = res.Data[i].NAME
								res.Data[i].code = res.Data[i].CODE
							}
						}
						return res.Data
					})
				}

				if (defaultChecked == null)
					defaultChecked = []
				if (dataSelect.length) {
					this.selectorInfo = {
						itemData: p.itemData != undefined ? p.itemData : this.selectorInfo
							.itemData, //itemData: p.itemData,  搜索的时候  p.itemData为空  赋值修改 为 她自己本身 this.selectorInfo.itemData
						isMultiple: this.selectorInfo.isMultiple,
						totalCount: this.selectorInfo.totalCount,
						showPopup: true,
						title: p.title,
						name: p.name,
						dataLists: dataSelect,
						defaultChecked: defaultChecked,
						realIndex: realIndex,
						item: item
					}
				} else {
					// 暂无数据
				}
			},
			handleSearch(val, pageIndex) {
				var p = {
					name: this.selectorInfo.name,
					title: this.selectorInfo.title,
					val: val,
					pageIndex: pageIndex
				}
				this.handleShowSheet(p, this.selectorInfo.item)
			},
			handleSelected(e) {
				this.selectorInfo.showPopup = false
				if (this.selectorInfo.name == 'UserNames') { //作业人员
					let listUsers = []
					let UsersName = ''

					if (this.dataModel.Nav_MonitorUser != null && this.dataModel.Nav_MonitorUser.length > 0) {
						//如果有数据 数据删除
						this.dataModel.Nav_MonitorUser.forEach(e => {
							e.IS_DELETED = true
							listUsers.push(e)
						})
					}

					if (e.length > 0) {
						e.forEach((item, i) => {
							if (item.NAME != null) {
								if (i > 0) {
									UsersName += ' '
								}
								listUsers.push({
									ID: guid(),
									USER_ID: item.ID,
									IS_DELETED: false,
									ORG_ID: this.ORG_ID,
									Nav_User: e[i]
								})
								UsersName += item.NAME
							}
						})
					}
					this.dataModel.Nav_MonitorUser = listUsers
					this.dataModel.UserNames = UsersName


				} else if (this.selectorInfo.name == 'SubName') {
					this.dataModel.Nav_Details[this.selectorInfo.realIndex].Nav_User = e
					this.dataModel.Nav_Details[this.selectorInfo.realIndex].USER_ID = e.ID
					// this.dataModel.Nav_Details[this.selectorInfo.realIndex].Nav_User.Nav_Person.Nav_Post.NAME = ''
				} else if (this.selectorInfo.name == 'SubDep') {
					this.dataModel.Nav_Details[this.selectorInfo.realIndex].Nav_Department = e
					this.dataModel.Nav_Details[this.selectorInfo.realIndex].DEPARTMENT_ID = e.ID
				}

			},
			stepAdd() {
				this.stepsPageList = this.stepsPageList + 1

			},
			stepReduce() {
				this.stepsPageList = this.stepsPageList - 1
			},
			closePicker() {
				this.comPickerInfo = {
					showSheet: false,
					columns: [],
					title: '',
					name: '',
					dataIndex: undefined,
					formIndex: undefined
				}
			},
			handleSearchUser(val, pageIndex) {
				const orgId = uni.getStorageSync('orgId')
				const json = initFilter(orgId, "", "NAME", '', pageIndex)
				extendInclude(json, "Nav_Department")
				extendRule(json, 'ENABLE_STATUS', 1, '0')
				if (val !== 'init') {
					const tempGroup = initFilterGroup(false);
					extendGroupRule(tempGroup, 'NAME', 9, val)
					extendFilterGroup(json, tempGroup);
				}
				json.Limit = 20
				if (pageIndex) {
					json.Start = (pageIndex - 1) * 20;
				}

				getUserLists(json).then(res => {
					if (res.IsSuccessful) {
						this.userLists = res.Data.map(i => {
							return {
								...i,
								name: i.NAME,
								code: i.CODE
							}
						})
						this.curTotal = res.TotalCount
					}
				})
			},
			handleSelectedUser(val) {
				this.showPopup = false
				this.lists = []
				const result = this.dataModel.Nav_MonitorUser.map((obj) => {
					const {
						Nav_User
					} = obj
					if (Nav_User.CODE === this.currentOperateUser.CODE) {
						return Object.assign({}, obj, {
							Nav_User: val,
						})
					}
					return obj
				})

				this.dataModel.Nav_MonitorUser = result
			},
			handleAdd(item) {
				const validDetails = this.dataModel.Nav_Details.filter(i => !i.IS_DELETED);
				const index = validDetails.indexOf(item);
				const realIndex = this.dataModel.Nav_Details.findIndex(item => item === validDetails[index]);
				this.dataModel.Nav_Details[realIndex].Nav_Contents.push({
					NAME: '',
					SCORE: '',
					METHOD: '',
					CONTENT: '',
					MEASURES: '',
					RESULT_SCORE: '',
					IS_DELETED: false,
					ID: guid(),
					MONITOR_ASSESSMENT_DETAIL_ID: this.dataModel.Nav_Details[realIndex].ID
				})

			},
			handleAdds() {
				this.dataModel.Nav_Details.push({
					IS_DELETED: false,
					Nav_Department: {
						NAME: ''
					},
					Nav_User: {
						NAME: '',
						Nav_Person: {
							Nav_Post: {
								NAME: ''
							}
						}
					},
					Nav_Contents: []

				})

			},
			handleHeight() {
				this.$nextTick(() => {
					setTimeout(() => {
						this.$refs.collapse.resize();
					}, 500)
				});
			},
			handleClosePopup() {
				this.showPopup = false
			},
			handleChangeUser(user) {
				this.currentOperateUser = user
				this.showPopup = true
				this.handleSearchUser('init')
			},
			handleAddUser() {
				const identifyUser = JSON.parse(JSON.stringify(this.subDataModel.Nav_MonitorUser))
				this.dataModel.Nav_MonitorUser.unshift(identifyUser)
				// this.dataModel.Nav_Person.unshift(this.subDataModel)
			},
			handleDelRowBefore(item) {
				item.IS_DELETED = true
				// let indexNotDel = 1
				// this.model.Nav_Users.forEach((e, i) => {
				// 	if (!e.IS_DELETED) {
				// 		e.ROW_NO = indexNotDel
				// 		indexNotDel++
				// 	}
				// })
				this.$forceUpdate()
			},
			confirmDel() {
				this.dataModel.Nav_MonitorUser.splice(this.showDelModalIndex, 1)
				this.showDelModalIndex = undefined
			},
			onConfirmPicker(e) {
				const {
					name,
					dataIndex,
					formIndex
				} = this.comPickerInfo
				if (name === "ASSESSMENT_CYCLE") {
					this.dataModel.ASSESSMENT_CYCLE = e.value[0].ID
					this.dataModel.ASSESSMENT_CYCLE_SHOW = e.value[0].NAME
				}

				this.comPickerInfo.showSheet = false
			},
			submit() {
				if (this.dataModel.Nav_Details.length > 0) {
					for (let item of this.dataModel.Nav_Details.filter(i => !i.IS_DELETED)) {
						if (!item.Nav_Department.NAME) {
							uni.$showErrorInfo('被考核组织不能为空！')
							return
						}
						if (item.Nav_Contents.filter(i => !i.IS_DELETED).length == 0) {
							uni.$showErrorInfo('安全生产指标考核项目不能为空！')
							return
						}
						if (item.Nav_Contents.length > 0) {
							for (let item1 of item.Nav_Contents.filter(i => !i.IS_DELETED)) {
								if (!item1.NAME) {
									uni.$showErrorInfo('安全生产指标考核项目不能为空！')
									return
								}
								if (!item1.SCORE) {
									uni.$showErrorInfo('分数不能为空！')
									return
								}
								if (!item1.RESULT_SCORE) {
									uni.$showErrorInfo('得分不能为空！')
									return
								}
							}
						}

					}
				}
				this.modelEdit = JSON.parse(JSON.stringify(this.dataModel))
				// const ele = this.$refs
				// ele['wForm'].validate().then(res => {
				this.modelEdit.PUBLISH = "SaveAndNotify";
				delete this.modelEdit.Nav_Department
				delete this.modelEdit.Nav_User
				this.modelEdit.Nav_Details.map(item => {
					delete item.Nav_User
					delete item.Nav_Department
				})
				this.modelEdit.Nav_MonitorUser.map(item => {
					delete item.Nav_User
					// delete item.Nav_Department
				})
				if (this.TaskID == null || this.TaskID == '') {
					this.modelEdit.TaskID = '00000000-0000-0000-0000-000000000000'
				} else {
					this.modelEdit.TaskID = this.TaskID
				}

				this.modelEdit.ID = this.ID;
				this.modelEdit.ORG_ID = uni.getStorageSync('orgId')
				saveMonitorAssessment(this.modelEdit).then(res => {
					uni.$showMsgFunc('操作成功!', () => {
						uni.navigateBack()
					}, 'success', 1000)
				})
				// }).catch(err => {
				// 	uni.$showErrorInfo('请检查必填项，必填项不能为空')
				// })
			},
			uploadFilePromise(url) {
				const appInfoData = uni.getStorageSync('appInfo')
				const userId = appInfoData?.User?.ID || ''
				const orgId = uni.getStorageSync('orgId')
				const tenant = uni.getStorageSync('Tenant') || ''
				const remoteUrl = config.serviceHost('/PF/File/UploadFile')
				return new Promise((resolve, reject) => {
					uni.uploadFile({
						url: remoteUrl,
						filePath: url,
						fileList: url,
						name: 'file',
						formData: {
							OrgId: orgId
						},
						header: {
							Tenant: tenant,
							userid: userId
						},
						success: (res) => {
							if (res.statusCode === 200) {
								const uploadResult = JSON.parse(res.data)
								if (uploadResult.IsSuccessful) {
									resolve(uploadResult.Data)
								}
							}
						}
					});
				})
			},
		}
	}
</script>

<style scoped>
	@import url("../../../../style/css/newTemplate.css");
	/* @import url("../../../../style/css/editTemplate.css"); */
	/* 
	.page-wrap {
		padding: 16px 16px 166px;
	}

	.card {
		margin-bottom: 18px;
	}

	.sub-form {
		margin-bottom: 16px;
	}

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

	.upload-title {
		color: #303133;
		font-size: 15px;
		line-height: 22px;
		padding: 8px 0;
	}

	.page-wrap>>>.u-upload__button {
		margin-bottom: 0;
	} */
</style>