<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="model" :rules="rules" ref="wForm" errorType="border-bottom" 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="Nav_Team.NAME" borderBottom>
					<u--input v-if="model.Nav_Team" disabledColor="#fff" v-model="model.Nav_Team.NAME" disabled fontSize="14px" customStyle="margin:0px;display:flex;padding:3px 0px" border="none" inputAlign="right">
					</u--input>
				</u-form-item>
				<u-form-item required label="班长：" prop="Nav_Monitor.NAME" @click="handleChangeMonitor('Nav_Monitor')" borderBottom>
					<u--input disabledColor="#fff" v-model="model.Nav_Monitor.NAME" disabled placeholder="请选择班长" suffixIcon="arrow-down" suffixIconStyle="font-size:12px" fontSize="14px"
						customStyle="margin:0px;display:flex;padding:3px 0px" border="none" inputAlign="right">
					</u--input>
				</u-form-item>
				<u-form-item required label="会议时间：" prop="MEETING_TIME" borderBottom @click="showCheckDate(3)">
					<u--input required v-model="model.MEETING_TIME" disabled disabledColor="#fff" 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-item required label="班次：" prop="Nav_Class.NAME" @click="handleChangeMonitor('Nav_Class')" borderBottom>
					<u--input disabledColor="#fff" v-model="model.Nav_Class.NAME" disabled placeholder="请选择班次" suffixIcon="arrow-down" suffixIconStyle="font-size:12px" fontSize="14px"
						customStyle="margin:0px;display:flex;padding:3px 0px" border="none" inputAlign="right">
					</u--input>
				</u-form-item>
				<u-form-item label="上班时间" prop="CHECKDATETIME" borderBottom @click="showCheckDate(1)">
					<u--input disabled disabledColor="#fff" v-model="model.START_TIME" 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-item label="下班时间" prop="ENDTIME" borderBottom @click="showCheckDate(2)">
					<u--input disabled disabledColor="#fff" v-model="model.END_TIME" 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-item label="地点" prop="LOCATION" borderBottom> <u--input disabledColor="#ffffff" v-model="model.LOCATION" border="none" inputAlign="right" fontSize="14px" placeholder="请输入地点"></u--input>
				</u-form-item>
				<u-form-item required label="主持人：" prop="Nav_User.NAME" @click="handleChangeMonitor('Nav_User')" borderBottom>
					<u--input disabledColor="#fff" v-model="model.Nav_User.NAME" disabled placeholder="请选择主持人" suffixIcon="arrow-down" suffixIconStyle="font-size:12px" fontSize="14px"
						customStyle="margin:0px;display:flex;padding:3px 0px" border="none" inputAlign="right">
					</u--input>
				</u-form-item>
				<u-form-item required label="记录人：" prop="Nav_Record.NAME" @click="handleChangeMonitor('Nav_Record')" borderBottom>
					<u--input disabledColor="#fff" v-model="model.Nav_Record.NAME" disabled placeholder="请选择记录人" suffixIcon="arrow-down" suffixIconStyle="font-size:12px" fontSize="14px"
						customStyle="margin:0px;display:flex;padding:3px 0px" border="none" inputAlign="right">
					</u--input>
				</u-form-item>
				<!-- <u-form-item required label="参会人员:" prop="Nav_Users" @click="handleShowSheet({title: '参会人员', name: 'UsersName'})">

					<u-icon style="margin-left: 4px;" name="arrow-down" size="12" slot="right"></u-icon>
				</u-form-item>
				<u-textarea v-model="model.NavUsersName" disabled autoHeight placeholder="请选择参会人员"></u-textarea> -->

				<u-form-item required label="应出勤人数:" prop="SHOULD_QTY" borderBottom> <u--input disabledColor="#ffffff" v-model="model.SHOULD_QTY" border="none" inputAlign="right" fontSize="14px"
						placeholder="请输入应出勤人数"></u--input>
				</u-form-item>
				<u-form-item required label="实际出勤人数:" prop="ACTUAL_QTY" borderBottom> <u--input disabledColor="#ffffff" v-model="model.ACTUAL_QTY" border="none" inputAlign="right" fontSize="14px"
						placeholder="请输入实际出勤人数"></u--input>
				</u-form-item>
				<u-form-item required label="迟到人数:" prop="LATE_QTY" borderBottom> <u--input disabledColor="#ffffff" v-model="model.LATE_QTY" border="none" inputAlign="right" fontSize="14px"
						placeholder="请输入迟到人数"></u--input>
				</u-form-item>
				<u-form-item required label="请假人数:" prop="LEAVE_QTY" borderBottom> <u--input disabledColor="#ffffff" v-model="model.LEAVE_QTY" border="none" inputAlign="right" fontSize="14px"
						placeholder="请输入请假人数"></u--input>
				</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 label="异常原因" prop="ABNORMAL_CAUSE"></u-form-item>
				<u--textarea autoHeight v-model="model.ABNORMAL_CAUSE" placeholder="请输入异常原因" border="surround"></u--textarea>
				<u-form-item label="问候语" prop="GREETING"></u-form-item> <u--textarea autoHeight v-model="model.GREETING" placeholder="请输入问候语" border="surround"></u--textarea>
				<u-form-item label="班组口号" prop="SLOGAN"></u-form-item> <u--textarea autoHeight v-model="model.SLOGAN" placeholder="请输入班组口号" border="surround"></u--textarea>
				<u-form-item label="欢迎新同事" prop="WELCOME"></u-form-item> <u--textarea autoHeight v-model="model.WELCOME" placeholder="请输入欢迎新同事" border="surround"></u--textarea>
				<u-form-item required label="今日计划及关注点" prop="TODAY_PLAN"></u-form-item> <u--textarea autoHeight v-model="model.TODAY_PLAN" placeholder="请输入今日计划及关注点" border="surround"></u--textarea>
				<u-form-item label="信息传递及学习内容" prop="LEARNING"></u-form-item> <u--textarea autoHeight v-model="model.LEARNING" placeholder="请输入信息传递及学习内容" border="surround"></u--textarea>
				<u-form-item label="其他事项" prop="OTHER_CONTENT"></u-form-item> <u--textarea autoHeight v-model="model.OTHER_CONTENT" placeholder="请输入其他事项" border="surround"></u--textarea>
				<u-form-item label="一分钟表扬" prop="PRAISE"></u-form-item> <u--textarea autoHeight v-model="model.PRAISE" placeholder="请输入一分钟表扬" border="surround"></u--textarea>
				<u-form-item label="优秀员工分享" prop="SHARE"></u-form-item> <u--textarea autoHeight v-model="model.SHARE" placeholder="请输入优秀员工分享" border="surround"></u--textarea>
				<u-form-item required label="安全环保事项" prop="DANGER"></u-form-item> <u--textarea autoHeight v-model="model.DANGER" placeholder="请输入安全环保事项" border="surround"></u--textarea>
				<u-form-item label="员工困难或建议" prop="DIFFICULTY"></u-form-item> <u--textarea autoHeight v-model="model.DIFFICULTY" placeholder="请输入员工困难或建议" border="surround"></u--textarea>
				<u-form-item label="安全宣誓" prop="SAFETY_OATH"></u-form-item> <u--textarea autoHeight v-model="model.SAFETY_OATH" placeholder="请输入安全宣誓" border="surround"></u--textarea>
			</u--form>
			<u--form labelPosition="left" labelWidth="auto" labelAlign="center" :model="model" :rules="rules" ref="wForm" errorType="border-bottom" class="demo-ruleForm" style="margin-top: 20px;">
				<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>
				<view style="margin: 10px 0px;">
					<u-button text="新增参会人员" type="primary" @click="handleAddPerson"></u-button>
				</view>
				<u-collapse :border="false" accordion>
					<uni-card margin="0" spacing="0" :is-shadow="false" v-for="(item, index) in model.Nav_Users.filter(i => !i.IS_DELETED)">
						<u-form-item :label="(index+1)+'. '+item['Nav_User'].NAME+' - '+item['Nav_User'].CODE" prop="Nav_User.NAME" @click="handleChangeUser(item)">
							<view slot="right" class="row-action">
								<view class="action" @click.stop>
									<u-icon @click="handleDelPersonRowBefore(index, item)" class="icon" name="trash" color="#ff4d4f" size="21"></u-icon>
								</view>
							</view>
						</u-form-item>
					</uni-card>
				</u-collapse>

			</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">
			<u--form labelPosition="left" labelWidth="auto" labelAlign="center" errorType="border-bottom" ref="sForm" class="sub-form">
				<uni-collapse :border="false" accordion>
					<view v-for="(item, index) in model.Nav_Details" :key="index">
						<uni-collapse-item title-border="none" :border="false">
							<template v-slot:title>
								<view class="uni-collapse-item__title-box">
									<view class="uni-collapse-item__title-text">
										{{index+1+'.'+item.QUOTA}}
									</view>
									<view @click.stop style="margin-right: 10px;">
										<u-icon @click="handleDelRowBefore(index)" 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">
								<u-form-item label="指标" prop="QUOTA"></u-form-item> <u--textarea autoHeight v-model="item.QUOTA" placeholder="请输入指标" border="surround"></u--textarea>
								<u-form-item label="目标" prop="PURPOSE"></u-form-item> <u--textarea autoHeight v-model="item.PURPOSE" placeholder="请输入目标" border="surround"></u--textarea>
								<u-form-item label="实际" prop="ACTUAL"></u-form-item> <u--textarea autoHeight v-model="item.ACTUAL" placeholder="请输入实际" border="surround"></u--textarea>
								<u-form-item label="达成率" prop="RATE" borderBottom> <u--input disabledColor="#ffffff" v-model="item.RATE" border="none" inputAlign="right" placeholder="请输入达成率" fontSize="14px"></u--input>
								</u-form-item>
								<u-form-item label="原因" prop="REASON"></u-form-item> <u--textarea autoHeight v-model="item.REASON" placeholder="请输入原因" border="surround"></u--textarea>
								<u-form-item label="改善对策" prop="IMPROVE"></u-form-item> <u--textarea autoHeight v-model="item.IMPROVE" placeholder="请输入改善对策" border="surround"></u--textarea>
								<u-form-item required label="涉及岗位:" prop="Nav_Users" @click="handleShowSheet({title: '涉及岗位', name: 'Nav_DetailPostsName'},index)">
									<u-icon style="margin-left: 4px;" name="arrow-down" size="12"></u-icon>
								</u-form-item>
								<u-textarea v-model="item.Nav_DetailPostsName" disabled autoHeight placeholder="请选择涉及岗位"></u-textarea>


							</view>


						</uni-collapse-item>
					</view>
				</uni-collapse>
				<view style="margin-top: 10px;">
					<u-button text="新增" type="primary" @click="handleAdd"></u-button>
				</view>
			</u--form>

		</view>

		<u-modal :show="showDelModalIndex >= 0" @confirm="confirmDel" @cancel="cancelDel" showCancelButton title="确认删除？"></u-modal>
		<u-modal :show="showDelModalIndexPerson >= 0" @confirm="confirmDelPerson" @cancel="cancelDelPerson" showCancelButton title="确认删除？"></u-modal>
		<query-selector :show="showPopup" :total="curTotal" :lists="userLists" :defaultValue="currentOperateUser.NAME" @close="handleClosePopup" @search="handleSearchUser" @select="handleSelectedUser" />
		<query-selector :show="showPopupMonitor" :total="curTotalMonitor" :lists="monitorLists" :defaultValue="currentOperateMonitor.NAME" @close="handleClosePopupMonitor" @search="handleSearchMonitor"
			@select="handleSelectedMonitor" />
		<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('Save')" style="width: 45%;float: left;">保存</button>
			<button type="primary" @click="submit('SaveAndNotify')" style="width: 45%;">提交</button>
		</view> -->

		<view style="padding: 10px 16px;display: flex;flex-direction: row;justify-content: space-around;" class="bottom-button" v-if="stepsPageList === 1">
			<u-button type="primary" @click="stepReduce" color="#3d4b70">上一步</u-button>
			<u-button type="default" @click="submit('Save')" :plain="true" color="#3d4b70" style="margin:0px 5px;">保存</u-button>
			<u-button type="default" @click="submit('SaveAndNotify')" color="#3d4b70">提交</u-button>
		</view>
		<u-datetime-picker :show="dateTimePickerInfo.showCheckDate" v-model='dateTimePickerInfo.defaultDateTime' @confirm="handleCheckDate" @close="dateTimePickerInfo.showCheckDate = false"
			@cancel="dateTimePickerInfo.showCheckDate = false" :mode="dateTimePickerInfo.mode"></u-datetime-picker>
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex'
	import {
		extendFilterGroup,
		extendGroupRule,
		extendInclude,
		extendOrder,
		extendRule,
		guid,
		initFilter,
		initFilterGroup
	} from '../../../../utils/common'
	import {
		getRequest,
		getTeamUsers
	} from '../../../../services/apply/FOServices/FOServices';
	import {
		getUserLists,
		getTeamLists,
		getClassLists,
		getUserPostLists
	} from '../../../../services/safe';

	import config from '../../../../config/common'

	export default {
		data() {
			return {
				userLists: [],
				listPropUpload: ['PRE_SHIFT_MEETING_RECORD_ID'],
				listPropValUpload: [],
				curTotalMonitor: 0,
				curTotal: 0,
				monitorLists: [],
				currentOperateMonitor: {},
				showPopupMonitor: false,
				stepsPageList: 0,
				model: {
					NavUsersName: '',
					Nav_Users: [],
					ORG_ID: "",
					Nav_User: {
						NAME: ''
					},
					Nav_Team: {
						NAME: ''
					},
					Nav_Monitor: {
						NAME: ''
					},
					Nav_Class: {
						NAME: ''
					},
					Nav_Record: {
						NAME: ''
					},
					Nav_Details: [],

					USER_ID: null,
				},
				options: [{
					text: '删除',
					style: {
						backgroundColor: '#f56c6c'
					}
				}],
				rules: {
					'Nav_Team.NAME': {
						type: 'string',
						required: true,
						trigger: ['blur', 'change']
					},
					'Nav_Monitor.NAME': {
						type: 'string',
						required: true,
						trigger: ['blur', 'change']
					},
					'MEETING_TIME': {
						type: 'string',
						required: true,
						trigger: ['blur', 'change']
					},
					'Nav_Class.NAME': {
						type: 'string',
						required: true,
						trigger: ['blur', 'change']
					},
					'Nav_User.NAME': {
						type: 'string',
						required: true,
						trigger: ['blur', 'change']
					},
					'Nav_Record.NAME': {
						type: 'string',
						required: true,
						trigger: ['blur', 'change']
					},
					'Nav_Users': {
						type: 'array',
						required: true,
						trigger: ['blur', 'change']
					},
					'SHOULD_QTY': {
						type: 'number',
						required: true,
						trigger: ['blur', 'change']
					},
					'ACTUAL_QTY': {
						type: 'number',
						required: true,
						trigger: ['blur', 'change']
					},
					'LATE_QTY': {
						type: 'number',
						required: true,
						trigger: ['blur', 'change']
					},
					'LEAVE_QTY': {
						type: 'number',
						required: true,
						trigger: ['blur', 'change']
					},

				},
				comPickerInfo: {
					showSheet: false,
					columns: [],
					title: '',
					dataIndex: undefined,
					formIndex: undefined,
					name: ''
				},
				selectorInfo: {
					name: 'user',
					isMultiple: false,
					showPopup: false,
					totalCount: 0,
					title: '考核结果选择',
					dataItem: {},
					index: 0,
					columns: [],
					dataLists: [],
					defaultText: '',
					defaultChecked: []
				},
				dateTimePickerInfo: {
					showCheckDate: false,
					dataIndex: undefined,
					defaultDateTime: uni.$u.timeFormat(new Date(), 'yyyy-mm-dd hh:MM:ss'),
					value: '',
					name: '',
					mode: ''
				},
				currentOperateUser: {},
				showPopup: false,
				tableKey: '0',
				TaskID: '',
				isLoadOK: false,
				showDelModalIndex: undefined,
				showDelModalIndexPerson: undefined,
				isAdd: 0,
				MEETING_TIME: uni.$u.timeFormat(Date(), 'yyyy-mm-dd'),
				ORG_ID: uni.getStorageSync('orgId')
			}
		},
		onLoad(option) {
			this.TaskID = option.taskID ? option.taskID : '';
			this.model.ID = option.ID ? option.ID : '';
			this.tableKey = option.tableKey ? option.tableKey : '0';
			if (option.isAdd != 1) {
				this.loadData();
			} else {
				this.isAdd = 1;
				// this.model.MEETING_TIME = uni.$u.timeFormat(Date(), 'yyyy-mm-dd');
				this.model.ID = guid();
				this.loadTeamUsers();
			}
		},
		methods: {
			handleAdd() {
				this.model.Nav_Details.push({
					QUOTA: '',
					PURPOSE: '',
					ACTUAL: '',
					RATE: '',
					REASON: '',
					IMPROVE: '',
					Nav_DetailPosts: [],
					Nav_DetailPostsName: '',
				})
			},
			handleAddPerson() {
				this.model.Nav_Users.unshift({
					PRE_SHIFT_MEETING_RECORD_ID: this.model.ID,
					ID: guid(),
					ORG_ID: this.ORG_ID,
					Nav_User: {
						NAME: "",
						CODE: ""
					},
					USER_ID: "",
					IS_DELETED: false,
					DEAL_STATUS: 0,
				})
			},
			handleDelRowBefore(index) {

				this.showDelModalIndex = index
			},
			handleDelPersonRowBefore(index, item) {
				if (item.USER_ID == "") {
					this.model.Nav_Users.splice(index, 1)
				} else {
					this.showDelModalIndexPerson = index
				}
			},
			cancelDelPerson() {
				this.showDelModalIndexPerson = undefined
			},
			confirmDelPerson() {
				this.model.Nav_Users.filter(i => !i.IS_DELETED)[this.showDelModalIndexPerson].IS_DELETED = true;
				//this.model.Nav_Users.splice(this.showDelModalIndex, 1)
				this.showDelModalIndexPerson = undefined
			},

			cancelDel() {
				this.showDelModalIndex = undefined
			},
			confirmDel() {
				this.model.Nav_Details.splice(this.showDelModalIndex, 1)
				// this.model.Nav_Users.filter(i => !i.IS_DELETED)[this.showDelModalIndex].IS_DELETED = true;
				//this.model.Nav_Users.splice(this.showDelModalIndex, 1)
				this.showDelModalIndex = undefined
			},
			stepAdd() {
				// this.stepsPageList = this.stepsPageList + 1
				const ele = this.$refs
				ele['wForm'].validate().then(res => {
					this.stepsPageList = this.stepsPageList + 1
				}).catch(err => {
					uni.$showErrorInfo('请检查必填项，必填项不能为空')
				})


			},
			stepReduce() {
				this.stepsPageList = this.stepsPageList - 1
			},
			async handleShowSheet(p, index) {
				const json = initFilter(this.ORG_ID, "", "", 0, p.pageIndex ?? 1)
				let dataSelect = []
				let defaultChecked = []
				json.Sort = "ID"
				json.Limit = 20
				this.selectorInfo.isMultiple = true
				if (p.val) {
					extendRule(json, 'NAME', 9, p.val);
				}
				json.SelectField = ["ID", "NAME", "NAME"]
				if (p.name == 'UsersName') {
					// const tempGroup = initFilterGroup(false)
					// extendGroupRule(tempGroup, 'DEPARTMENT_ID', 1, uni.getStorageSync('appInfo')?.User?.DEPARTMENT_ID)
					// extendFilterGroup(json, tempGroup)
					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
					})
					if (this.model.Nav_Users.length > 0 && this.model.Nav_Users != null) {
						// this.selectorInfo.defaultChecked = []
						this.model.Nav_Users.filter(i => !i.IS_DELETED).forEach(e => {
							if (e.Nav_User != null && e.Nav_User.NAME != null)
								defaultChecked.push(e.Nav_User)
						})
					} else {
						defaultChecked = null
					}
				} else if (p.name == 'Nav_DetailPostsName') {
					dataSelect = await getUserPostLists(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 (this.model.Nav_Details[index].Nav_DetailPosts.length > 0 && this.model.Nav_Details[index].Nav_DetailPosts != null) {
						// this.selectorInfo.defaultChecked = []
						this.model.Nav_Details[index].Nav_DetailPosts.filter(i => !i.IS_DELETED).forEach(e => {
							if (e.Nav_Post != null && e.Nav_Post.NAME != null)
								defaultChecked.push(e.Nav_Post)
						})
					} else {
						defaultChecked = null
					}
				}

				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,
						index: index
					}
				} else {
					// 暂无数据
				}

			},
			//数据加载
			handleSearch(val, pageIndex) {
				var p = {
					name: this.selectorInfo.name,
					title: this.selectorInfo.title,
					val: val,
					pageIndex: pageIndex,
				}
				this.handleShowSheet(p, this.selectorInfo.index)
			},

			handleSelected(e) {
				this.selectorInfo.showPopup = false
				if (this.selectorInfo.name == 'UsersName') { //被交底人
					let listUsers = []
					let UsersName = ''
					if (this.model.Nav_Users != null && this.model.Nav_Users.length > 0) {
						//如果有数据 数据删除
						this.model.Nav_Users.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(),
									PRE_SHIFT_MEETING_RECORD_ID: this.model.ID,
									USER_ID: item.ID,
									ORG_ID: this.ORG_ID,
									Nav_User: {
										NAME: item.NAME,
										ID: item.ID
									},
									IS_DELETED: false,
								})
								UsersName += item.NAME
							}
						})
					}
					this.model.Nav_Users = listUsers
					this.model.NavUsersName = UsersName
				} else if (this.selectorInfo.name == 'Nav_DetailPostsName') {
					let listUsers = []
					let UsersName = ''

					if (this.model.Nav_Details[this.selectorInfo.index].Nav_DetailPosts != null && this.model.Nav_Details[this.selectorInfo.index].Nav_DetailPosts.length > 0) {
						//如果有数据 数据删除
						this.model.Nav_Details[this.selectorInfo.index].Nav_DetailPosts.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(),
									PRE_SHIFT_MEETING_RECORD_DETAIL_ID: this.model.Nav_Details[this.selectorInfo.index].ID,
									POST_ID: item.ID,
									ORG_ID: this.ORG_ID,
									Nav_Post: e[i],
								})
								UsersName += item.NAME
							}
						})
					}
					this.model.Nav_Details[this.selectorInfo.index].Nav_DetailPosts = listUsers
					this.model.Nav_Details[this.selectorInfo.index].Nav_DetailPostsName = UsersName
				}
			},
			handleChangeMonitor(name) {
				this.currentOperateMonitor = name
				this.showPopupMonitor = true
				this.handleSearchMonitor('init')
			},
			handleSearchMonitor(val, pageIndex) {
				const orgId = uni.getStorageSync('orgId')
				const json = initFilter(orgId, "", "NAME", '', pageIndex)

				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;
				}

				if (this.currentOperateMonitor == 'Nav_Monitor' ||
					this.currentOperateMonitor == 'Nav_User' ||
					this.currentOperateMonitor == 'Nav_Record'
				) {
					if (orgId === '8b3c41aa-51b1-7ce9-1879-248a038c1b5c') {
						extendRule(json, 'DEPARTMENT_ID', 1, uni.getStorageSync('appInfo')?.User?.DEPARTMENT_ID)
					}

					getUserLists(json).then(res => {
						if (res.IsSuccessful) {
							this.monitorLists = res.Data.map(i => {
								return {
									...i,
									name: i.NAME,
									code: i.CODE
								}
							})
							this.curTotalMonitor = res.TotalCount
						}
					})
				} else if (this.currentOperateMonitor == 'Nav_Team') {
					getTeamLists(json).then(res => {
						if (res.IsSuccessful) {
							this.monitorLists = res.Data.map(i => {
								return {
									...i,
									name: i.NAME,
									code: i.CODE
								}
							})
							this.curTotalMonitor = res.TotalCount
						}
					})
				} else if (this.currentOperateMonitor == 'Nav_Class') {
					extendInclude(json, 'Nav_ClassDetail');
					getClassLists(json).then(res => {
						if (res.IsSuccessful) {
							this.monitorLists = res.Data.map(i => {
								return {
									...i,
									name: i.NAME,
									code: i.CODE
								}
							})
							this.curTotalMonitor = res.TotalCount
						}
					})
				}

			},
			handleSelectedMonitor(val) {
				this.showPopupMonitor = false
				if (this.currentOperateMonitor == 'Nav_Team') {
					this.model.Nav_Team = val
					this.model.TEAM_ID = val.ID
				} else if (this.currentOperateMonitor == 'Nav_Monitor') {
					this.model.Nav_Monitor = val
					this.model.MONITOR_ID = val.ID
				} else if (this.currentOperateMonitor == 'Nav_Class') {
					this.model.Nav_Class = val
					this.model.CLASS_ID = val.ID
					let DATE_TIME = uni.$u.timeFormat(new Date(), 'yyyy-mm-dd')
					let start = uni.$u.timeFormat(val.Nav_ClassDetail[0].STARTTIME, 'hh:MM:ss')
					let end = uni.$u.timeFormat(val.Nav_ClassDetail[0].ENDTIME, 'hh:MM:ss')
					this.model.START_TIME = DATE_TIME + ' ' + start
					this.model.END_TIME = DATE_TIME + ' ' + end

				} else if (this.currentOperateMonitor == 'Nav_User') {
					this.model.Nav_User = val
					this.model.USER_ID = val.ID
				} else if (this.currentOperateMonitor == 'Nav_Record') {
					this.model.Nav_Record = val
					this.model.RECORD_ID = val.ID
				}
				this.currentOperateMonitor = val
			},
			handleClosePopupMonitor() {
				this.showPopupMonitor = false
			},
			loadTeamUsers() {
				this.model.Nav_Team = uni.getStorageSync('appInfo').User.Team
				this.model.TEAM_ID = uni.getStorageSync('appInfo').User.Team?.ID
				this.model.DEPARTMENT_ID = uni.getStorageSync('appInfo').User.DEPARTMENT_ID
				let personid = uni.getStorageSync('appInfo').User.PERSON_ID;
				const json = initFilter(this.ORG_ID, "", "")
				extendRule(json, 'CHARGE_PERSON_ID', 1, personid);
				extendInclude(json, 'Nav_TeamPersons.Nav_Person.Nav_User');
				getTeamUsers(json).then(res => {
					if (res && res.length > 0) {
						let teamPersons = res[0].Nav_TeamPersons;
						let person = [];
						let rowNo = 1;
						let NavUsersName = ''
						if (teamPersons && teamPersons.length > 0) {
							teamPersons.forEach(item => {
								let objPerson = {
									Nav_User: {},
									NAME: '',
									CODE: '',
								}
								if (item.Nav_Person.NAME !== null) {
									NavUsersName += item.Nav_Person.NAME + ' ';
								}
								objPerson.Nav_User.CODE = item.Nav_Person.CODE;
								objPerson.Nav_User.NAME = item.Nav_Person.NAME;
								objPerson.Nav_User.ID = item.Nav_Person.Nav_User.ID;
								objPerson.ROW_NO = rowNo;
								objPerson.ID = guid();
								objPerson.PRE_SHIFT_MEETING_RECORD_ID = this.model.ID;
								objPerson.USER_ID = item.Nav_Person?.Nav_User?.ID;
								objPerson.DEAL_STATUS = 0;
								person.push(objPerson);
								rowNo++;

							})
						}
						this.model.NavUsersName = NavUsersName
						this.model.Nav_Users = person;
					}
				})
			},
			loadData() {
				const json = initFilter(this.ORG_ID, "", "")
				if (this.listPropValUpload.length == 0) {
					this.listPropValUpload.push(this.model.ID)
				}
				extendInclude(json, "Nav_Monitor")
				extendInclude(json, "Nav_Class")
				extendInclude(json, "Nav_Record")
				extendInclude(json, "Nav_Team")
				extendInclude(json, "Nav_User")
				extendInclude(json, "Nav_Details")
				extendInclude(json, "Nav_Users.Nav_User")
				extendInclude(json, 'Nav_Files.Nav_ImgFile.Nav_File');
				// TODO: id 未获取
				extendRule(json, 'ID', 1, this.model.ID)
				getRequest(json, "/FO/PreShiftMeetingRecord/Get").then(res => {
					this.model = res
					this.model.MEETING_TIME = uni.$u.timeFormat(res.MEETING_TIME, 'yyyy-mm-dd')
					let NavUsersName = ''
					let person = [];
					let rowNo = 1;
					if (res.Nav_Users && res.Nav_Users.length > 0) {
						res.Nav_Users.forEach(item => {
							let objPerson = {
								Nav_User: {},
								NAME: '',
								CODE: '',
							}
							if (item.Nav_User.NAME !== null) {
								NavUsersName += item.Nav_User.NAME + ' ';
							}
							objPerson.Nav_User.CODE = item.Nav_User.CODE;
							objPerson.Nav_User.NAME = item.Nav_User.NAME;
							objPerson.Nav_User.ID = item.Nav_User.ID;
							objPerson.ROW_NO = rowNo;
							objPerson.ID = guid();
							objPerson.PRE_SHIFT_MEETING_RECORD_ID = this.model.ID;
							objPerson.USER_ID = item.Nav_User?.ID;
							objPerson.DEAL_STATUS = 0;
							person.push(objPerson);
							rowNo++;

						})
					}
					this.model.NavUsersName = NavUsersName
					this.model.Nav_Users = person;
				})
			},
			handleSearchUser(val, pageIndex) {
				const json = initFilter(this.ORG_ID, "", "NAME", '', pageIndex)
				extendInclude(json, "Nav_Person.Nav_Post")
				extendRule(json, 'ENABLE_STATUS', 1, '0')
				// extendRule(json, 'DEPARTMENT_ID', 1, uni.getStorageSync('appInfo').User.DEPARTMENT_ID)
				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 = []
				this.currentOperateUser.USER_ID = val.ID;
				this.currentOperateUser.Nav_User.NAME = val.NAME;
				this.currentOperateUser.Nav_User.CODE = val.CODE;
			},
			handleClosePopup() {
				this.showPopup = false
			},
			handleChangeUser(user) {
				if (user.Nav_User.NAME == '') {
					this.currentOperateUser = user;
					this.showPopup = true;
					this.handleSearchUser('init');
				}

			},
			onConfirmPicker(e) {
				const {
					name,
					dataIndex,
					formIndex
				} = this.comPickerInfo
				if (formIndex === "sForm1") {
					const result = this.model.Nav_Users.map((obj, index) => {
						return obj
					})
					this.model.Nav_Users = result
				} else {

				}
				this.comPickerInfo.showSheet = false
			},
			closePicker() {
				this.comPickerInfo = {
					showSheet: false,
					columns: [],
					title: '',
					name: '',
					dataIndex: undefined,
					formIndex: undefined
				}
			},
			submit(type) {
				this.modelEdit = JSON.parse(JSON.stringify(this.model))
				// const ele = this.$refs
				// ele['wForm'].validate().then(res => {
				this.modelEdit.RATE = type;
				if (this.TaskID != "") {
					this.modelEdit.TaskID = this.TaskID;
				}
				if (this.modelEdit.ORG_ID == "") {
					this.modelEdit.ORG_ID = this.ORG_ID;
				}
				if (this.modelEdit.USER_ID == "") {
					this.modelEdit.USER_ID = uni.getStorageSync('appInfo').User.ID;
				}
				if (this.modelEdit.Nav_Users && this.modelEdit.Nav_Users.length > 0) {
					this.modelEdit.Nav_Users.forEach(item => {
						delete item.Nav_User.ID
					});
				}
				if (this.modelEdit.Nav_Files && this.modelEdit.Nav_Files.length > 0) {
					this.modelEdit.Nav_Files.forEach(item => {
						if (item.PRE_SHIFT_MEETING_RECORD_ID == undefined) {
							item.PRE_SHIFT_MEETING_RECORD_ID = this.model.ID;
						}
						if (item.ORG_ID == undefined) {
							item.ORG_ID = this.model.ORG_ID;
						}
					});
				}

				if (this.modelEdit.Nav_Details && this.modelEdit.Nav_Details.length > 0) {
					this.modelEdit.Nav_Details.forEach(item => {
						if (item.Nav_DetailPosts && item.Nav_DetailPosts.length > 0) {
							item.Nav_DetailPosts.map(item1 => {
								delete item1.Nav_Post
							})
						}
					});
				}


				delete this.modelEdit.Nav_Class
				delete this.modelEdit.Nav_Monitor
				delete this.modelEdit.Nav_Record
				delete this.modelEdit.Nav_Team
				delete this.modelEdit.Nav_User

				this.modelEdit.ACTUAL_QTY = Number(this.modelEdit.ACTUAL_QTY)
				this.modelEdit.LATE_QTY = Number(this.modelEdit.LATE_QTY)
				this.modelEdit.LEAVE_QTY = Number(this.modelEdit.LEAVE_QTY)
				this.modelEdit.SHOULD_QTY = Number(this.modelEdit.SHOULD_QTY)
				getRequest(this.modelEdit, "/FO/FOPreShiftMeetingRecord/FullUpdate").then(res => {
					if (res) {
						uni.$showMsgFunc('操作成功!', () => {
							uni.navigateBack()
						}, 'success', 1000)
					}
				})
				// }).catch(err => {
				// 	uni.$showErrorInfo('请检查必填项，必填项不能为空')
				// })
			},
			showCheckDate(dataIndex) {
				// let date = new Date()
				// this.dateTimePickerInfo.showCheckDate = true
				this.dateTimePickerInfo = {
					showCheckDate: true,
					defaultDateTime: uni.$u.timeFormat(new Date(), 'yyyy-mm-dd hh:MM:ss'),
					dataIndex: dataIndex,
					mode: dataIndex == 3 ? 'date' : 'datetime'
				}
			},
			//隐藏控件 显示时间
			handleCheckDate(e) {

				if (this.dateTimePickerInfo.dataIndex == 1) {
					this.model.START_TIME = uni.$u.timeFormat(e.value,
						'yyyy-mm-dd hh:MM:ss')
				} else if (this.dateTimePickerInfo.dataIndex == 2) {
					this.model.END_TIME = uni.$u.timeFormat(e.value,
						'yyyy-mm-dd hh:MM:ss')
				} else if (this.dateTimePickerInfo.dataIndex == 3) {
					this.model.MEETING_TIME = uni.$u.timeFormat(e.value,
						'yyyy-mm-dd')
				}
				this.dateTimePickerInfo.showCheckDate = false

			},
		}
	}
</script>

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