<template>
	<view class="todo-page">
		<step-title :stepPage="stepsPage" :stepText="stepsText"></step-title>
		<view class="allview">
			<view class="card">
				<u--form labelWidth="auto" :model="model" ref="wForm" :rules="rules" class="demo-ruleForm">

					<u-form-item  label="建议事项名称" prop="NAME" borderBottom>
						<u--input disabled disabledColor="#ffffff" v-model="model.NAME" border="none" slot="right"
							inputAlign="right" placeholder="请输入建议事项名称" fontSize="14px"></u--input>
					</u-form-item>
					<u-form-item class="subRequired"  label="建议事项类别" prop="Nav_ItemEnum.NAME" borderBottom>
						<u--input v-model="model.Nav_ItemEnum.NAME" disabled disabledColor="#ffffff"
							placeholder="请选择建议事项类别" border="none" inputAlign="right" fontSize="14px">
						</u--input>
					</u-form-item>

					<u-form-item label="建议事项描述" prop="NAME" borderBottom>
					</u-form-item>
					<u--textarea autoHeight disabled v-model="model.DESCRIPTION" placeholder="请输入建议事项描述"
						border="surround"></u--textarea>

					<u-form-item v-if="stepsPage>0" class="subRequired" label="受理人" prop="Nav_Assignee.NAME"
						borderBottom> <u--input disabled disabledColor="#fff" v-model="model.Nav_Assignee.NAME"
							border="none" inputAlign="right"></u--input>
					</u-form-item>

					<u-form-item v-if="stepsPage>0" label="受理状况" prop="ASSIGNEE_STATUS_SHOW" borderBottom>
						<u--input disabled disabledColor="#ffffff" v-model="model.ASSIGNEE_STATUS_SHOW" border="none"
							inputAlign="right" placeholder="请输入受理状况"></u--input>
					</u-form-item>

					<u-form-item label="受理状况描述" v-if="stepsPage>0" prop="ASSIGNEE_DESCRIPTION"
						borderBottom></u-form-item>
					<u--textarea v-if="stepsPage>1" autoHeight disabled v-model="model.ASSIGNEE_DESCRIPTION"
						placeholder="请输入受理状况描述" border="surround"></u--textarea>

					<u-form-item v-if="model.STATUS>0" class="subRequired" label="落实部门" prop="Nav_DoDepartment.NAME"
						borderBottom>
						<u--input disabledColor="#fff" disabled v-model="model.Nav_DoDepartment.NAME" border="none"
							inputAlign="right"></u--input>
						<u-icon style="margin-left: 4px;" slot="right" name="arrow-down" v-if="stepsPage==1"></u-icon>
					</u-form-item>
					<u-form-item v-if="model.STATUS>0" class="subRequired" label="落实人员" prop="Nav_DoUser.NAME"
						borderBottom>
						<u--input disabledColor="#fff" disabled v-model="model.Nav_DoUser.NAME" border="none"
							inputAlign="right"></u--input>
					</u-form-item>

					<u-form-item v-if="model.STATUS>1" label="落实情况描述" prop="IMPLEMENT_DESCRIPTION"
						borderBottom></u-form-item>
					<u--textarea v-if="stepsPage>2" disabled autoHeight v-model="model.IMPLEMENT_DESCRIPTION"
						border="surround"></u--textarea>

					<view class="upload-title">建议文件：</view>
					<full-upload v-model="model.Nav_FileList" :isShowBtn='false' :listProp='listPropUpload'
						:listPropVal='listPropValUpload'></full-upload>

					<view v-if="model.STATUS>1" class="upload-title">落实文件：</view>
					<full-upload v-if="model.STATUS>1" v-model="model.Nav_ImpFileList" :isShowBtn='false'
						:listProp='listPropUpload' :listPropVal='listPropValUpload'></full-upload>

					<u-form-item v-if="stepsPage>2" label="反馈的满意度" prop="SATISFACTION_STATUS_SHOW" borderBottom>
						<u--input disabled disabledColor="#ffffff" v-model="model.SATISFACTION_STATUS_SHOW"
							border="none" inputAlign="right" placeholder="请选择反馈的满意度"></u--input>
					</u-form-item>
				</u--form>
			</view>
		</view>

	</view>
</template>

<script>
	import {
		extendFilterGroup,
		extendGroupRule,
		extendInclude,
		extendOrder,
		extendRule,
		extendIgnoreDataRule,
		guid,
		initFilter,
		initFilterGroup
	} from '../../../../utils/common'

	import {
		OrderPagedItemEnum,
		FullUpdateOpinion,
		GetOpinion
	} from '../../../../services/apply/subPages/scOG'

	import {
		getDepartmentLists
	} from '../../../../services/app'

	import {
		UserPagedLimit,
		getEnum,
		GetEnumAnyOrder
	} from '../../../../services/common'


	import {
		FMProductionUnit,
		CheckPeriods,
		CheckLevels
	} from '../../../../utils/enums.js'
	import {
		getRequest,
	} from '../../../../services/apply/FOServices/FOServices';
	import stepTitle from '@/components/custom/step-title.vue'
	import swipeActionItem from '../../../../uni_modules/uview-ui/libs/config/props/swipeActionItem';
	export default {
		components: {
			stepTitle,
		},
		data() {
			return {
				TaskID: null,
				tableKey: '',
				ORG_ID: uni.getStorageSync('orgId'),
				stepsText: ['发起', '受理', '落实', '评价', '归档'], //头部导航
				stepsPage: 0, //步骤
				model: {
					ID: '',
					NAME: '',
					TaskID: null,
					TYPE_ID: '',
					ItemEnumNAME: '',
					user: {
						NAME: ''
					},
					Nav_ItemEnum: {
						NAME: ''
					},
					DESCRIPTION: '',
					STATUS: 0,
					Nav_FileList: [],



					ASSIGNEE_ID: '',
					Nav_Assignee: {
						NAME: ''
					},
					DO_DEPARTMENT_ID: '',
					Nav_DoDepartment: {
						NAME: ''
					},
					DO_USER_ID: '',
					Nav_DoUser: {
						NAME: ''
					},
					Nav_ImpFileList: [],
					ASSIGNEE_STATUS: 0,
					ASSIGNEE_STATUS_SHOW: '未受理',
					ASSIGNEE_DESCRIPTION: '',
					IMPLEMENT_DESCRIPTION: '',
					SATISFACTION_STATUS: 0,
					SATISFACTION_STATUS_SHOW: ''
				},

				listPropUpload: ['EMPLOYEE_OPINION_REPORT_ID'],
				listPropValUpload: [],


				selectorInfo: {
					isSubShow: false,
					isMultiple: false,
					showPopup: false,
					totalCount: 0,
					title: '检查人员',
					itemData: {},
					index: 0,
					dataLists: [],
					defaultText: '',
					defaultValue: '',
					name: '',
					defaultChecked: []
				},

				listEnumStatus: [],
				listEnumStatusText: [],

				listEnumSatisfaction: [],
				listEnumSatisfactionText: [],

				comPickerInfo: {
					showSheet: false,
					dataItem: {},
					columns: [],
					title: '',
					dataIndex: undefined,
					formIndex: undefined,
					name: ''
				},


				rules: {
					'NAME': {
						type: 'string',
						required: true,
						trigger: ['blur', 'change'],
						message: '请填写建议事项名称'
					},
					'Nav_ItemEnum.NAME': {
						type: 'string',
						required: true,
						trigger: ['blur', 'change'],
						message: '请选择建议事项类别'
					}
				},

				// showDelModalIndex: undefined,
				// showDelModalIndex1: undefined,
				// subsectionList: ['入库', '不入库', ],
				// radiolist1: [{
				// 	name: '是',
				// 	disabled: false
				// }, {
				// 	name: '否',
				// 	disabled: false
				// }],
				// curNow: 1,
				// RiskLevel: ['一般', '重大'],
				// showPopupUnit: false,
				// UnitDefaultIndex: [0],
				// showPopupRiskLevel: false,
				// RiskLevelDefaultIndex: [0],
				// UnitLists: [],
				// TypeLists: [],
				// showPopupType: false,
				// TypeDefaultIndex: [0],
				// PeriodLists: [],
				// showPopupPeriod: false,
				// PeriodDefaultIndex: [0],
				// LevelLists: [],
				// showPopupStep: false,
				// showPopupArea: false,
				// showPopupLevel: false,
				// curTotalStep: 0,
				// curTotalArea: 0,
				// stepLists: [],
				// areaLists: [],
				// LevelDefaultIndex: [0],
				// showPopupDate: false,
				// showPopupRecitifyDate: false,
				// dataModel: {
				// 	Nav_ReportFiles: [],
				// 	MineType: '',
				// 	Nav_RiskArea: {
				// 		NAME: ''
				// 	},
				// 	HIDDEN_PLACE: '',
				// 	HIDDEN_DESCRIPTION: '',
				// },
				// peopleSelectOption: {
				// 	showSelector: false,
				// 	value: null,
				// 	index: 0,
				// 	defaultChecked: []
				// },
				// dateTime: uni.$u.timeFormat(new Date(), 'yyyy-mm-dd hh:MM'),
				// dateRecitifyTime: uni.$u.timeFormat(new Date(), 'yyyy-mm-dd hh:MM'),
				// stepsPage: 0,
				// stepsPageList: 0,
				// Pu: '',
				// Check_Type_ID: '',
				// TypeListres: {},
				// TaskID: '',
				// poparr: '',
				// currentOperateStep: {},
				// currentOperateArea: {},
				// chooseCheckContent: '',
				// chooseCheckArea: '',
				// showPopupMonitor: false,
				// currentOperateMonitor: {},
				// monitorLists: [],
				// curTotalMonitor: 0,
				// chooseCheckMonitor: '',
				// chooseRecitify: '',

			}
		},
		onLoad(option) {
			this.model.ID = option.ID
			this.model.TaskID = option.taskID
			this.TaskID = option.taskID
			this.tableKey = option.tableKey

			this.ORG_ID = uni.getStorageSync('orgId')
			if (option.ID != null && option.ID != 'null') {
				this.listPropValUpload.push(this.model.ID)
				//受理枚举  OGAssigneeStatus
				this.getEnums() // this.loadData()

			} else {
				this.isLoadOK = true
				this.model.ID = guid()
				this.model.ORG_ID = this.ORG_ID
				this.listPropValUpload.push(this.model.ID)
				// this.model.Nav_ListSafeCheckDetail = null
			}
		},
		methods: {

			getEnums() {
				var dataParm = {
					'name': "OGAssigneeStatus|OGSatisfactionStatus"
				}

				GetEnumAnyOrder(dataParm).then(res => {
					this.listEnumStatus = res[0]
					this.listEnumStatusText = []
					this.listEnumStatus.forEach(e => {
						e.name = e.NAME
						e.code = e.ID
						this.listEnumStatusText.push(e.NAME)
					})

					this.listEnumSatisfaction = res[1]
					this.listEnumSatisfactionText = []
					this.listEnumSatisfaction.forEach(e => {
						e.name = e.NAME
						e.code = e.ID
						this.listEnumSatisfactionText.push(e.NAME)
					})
					this.loadData()
				})
			},
			loadData() {
				const json = initFilter(this.ORG_ID, "", "", 1)
				extendRule(json, 'ID', 1, this.model.ID);
				extendInclude(json, "Nav_User")
				extendInclude(json, "Nav_LaunchDepartment")
				extendInclude(json, "Nav_ItemEnum")
				extendInclude(json, "Nav_Assignee")
				extendInclude(json, "Nav_DoDepartment")
				extendInclude(json, "Nav_DoUser")
				extendInclude(json, "Nav_FileList.Nav_ImgFile")
				extendInclude(json, "Nav_ImpFileList.Nav_ImgFile")
				json.IgnoreDataRule = true
				GetOpinion(json).then(res => {
					if (res.Nav_DoDepartment == null)
						res.Nav_DoDepartment = {
							NAME: ''
						}
					if (res.Nav_DoUser == null)
						res.Nav_DoUser = {
							NAME: ''
						}

					res.ASSIGNEE_STATUS_SHOW = '' // = '未受理' //res
					this.listEnumStatus.forEach((e, index) => {
						if (e.code == res.ASSIGNEE_STATUS) {
							res.ASSIGNEE_STATUS_SHOW = e.name
						}
					})

					res.SATISFACTION_STATUS_SHOW = ''
					this.listEnumSatisfaction.forEach((e, index) => {
						if (e.code == res.SATISFACTION_STATUS) {
							res.SATISFACTION_STATUS_SHOW = e.name
						}
					})
					this.stepsPage = res.STATUS
					this.model = res
				})
			},


			//下拉数据加载
			async handleShowSheet(p) {
				const orgId = uni.getStorageSync('orgId')
				const json = initFilter(orgId, "", "", 0, p.pageIndex ?? 1)
				let dataSelect = []
				var defaultChecked = []
				if (p.name == "ItemEnumNAME") {
					if (p.val) {
						extendRule(json, 'NAME', 9, p.val);
					}
					json.Sort = "NAME"
					json.Order = 1
					dataSelect = await OrderPagedItemEnum(json).then(res => {
						if (res != undefined && res.length > 0) {
							for (let i = 0; i < res.length; i++) {
								res[i].name = res[i].NAME
								// res[i].code = res[i].CODE
							}
						}
						return res
					})
				} else if (p.name == "Nav_DoUserNAME" || p.name == "Nav_AssigneeNAME") {
					if (p.val) {
						extendRule(json, 'NAME', 9, p.val);
					}
					// if (this.model.DO_DEPARTMENT_ID) {
					// 	extendRule(json, 'DEPARTMENT_ID', 1, this.model.DO_DEPARTMENT_ID);
					// }

					json.Sort = "NAME"
					json.Order = 0
					json.PageIndex = p?.pageIndex ?? 1
					json.Limit = 20
					if (p?.pageIndex) {
						json.Start = (p?.pageIndex - 1) * json.Limit;
					}
					dataSelect = await UserPagedLimit(json).then(res => {
						this.selectorInfo.totalCount = res.TotalCount
						if (res != undefined && res.Data != undefined && res.Data.length > 0) {

							this.selectorInfo.dataLists = res.Data.map(i => {
								return {
									...i,
									name: i.NAME,
									code: i.CODE
								}
							})
						}
						return this.selectorInfo.dataLists
					})
				} else if (p.name == "Nav_DoDepartmentNAME") {
					if (p.val) {
						extendRule(json, 'NAME', 9, p.val);
					}
					json.Sort = "NAME"
					json.Order = 0
					json.PageIndex = p?.pageIndex ?? 1
					json.Limit = 20
					if (p?.pageIndex) {
						json.Start = (p?.pageIndex - 1) * json.Limit;
					}
					dataSelect = await getDepartmentLists(json).then(res => {
						this.selectorInfo.totalCount = res.TotalCount
						if (res != undefined && res.Data != undefined && res.Data.length > 0) {

							this.selectorInfo.dataLists = res.Data.map(i => {
								return {
									...i,
									name: i.NAME,
									code: i.CODE
								}
							})
						}
						return this.selectorInfo.dataLists
					})
				}

				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
					}
				} else {
					// 暂无数据
				}
			},
			handleSelected(e) {
				this.selectorInfo.showPopup = false
				if (this.selectorInfo.name == "ItemEnumNAME") {
					this.model.ItemEnumNAME = e.NAME
					this.model.Nav_ItemEnum = e
					this.model.TYPE_ID = e.ID
				} else if (this.selectorInfo.name == "Nav_DoUserNAME") {
					this.model.Nav_DoUser = e
					this.model.DO_USER_ID = e.ID
				} else if (this.selectorInfo.name == "Nav_AssigneeNAME") {
					this.model.Nav_Assignee = e
					this.model.ASSIGNEE_ID = e.ID
				} else if (this.selectorInfo.name == "Nav_DoDepartmentNAME") {
					this.model.Nav_DoDepartment = e
					this.model.DO_DEPARTMENT_ID = e.ID
				}
			},
			closePicker() {
				this.comPickerInfo = {
					showSheet: false,
					columns: [],
					title: '',
					name: '',
					formIndex: undefined
				}
			},

			// //显示组件
			// handleChange() {
			// 	this.selectorInfo.showPopup = true
			// 	this.handleSearch()
			// },

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

			submit() {
				const ele = this.$refs
				this.modelEdit = JSON.parse(JSON.stringify(this.model))
				this.modelEdit.Nav_ItemEnum = null

				this.modelEdit.Nav_Assignee = null
				this.modelEdit.Nav_DoDepartment = null
				this.modelEdit.Nav_DoUser = null

				ele['wForm'].validate().then(res => {
					if (this.TaskID != null && this.TaskID != '' && this.TaskID.length > 0)
						this.modelEdit.TaskID = this.TaskID
					this.modelEdit.PUBLISH = "SaveAndNotify";
					FullUpdateOpinion(this.modelEdit).then(res => {
						uni.$showMsgFunc('操作成功!', () => {
							uni.navigateBack()
						}, 'success', 1000)
					})
				}).catch(err => {
					if (err.length > 0) {
						uni.$showErrorInfo(err[0].message)
					} else {
						uni.$showErrorInfo('校验失败！')
					}
				})
			},




			handleChange(item) {
				var dataSour = []
				if (item.name == 'OGAssigneeStatus') {
					dataSour = this.listEnumStatusText
				} else if (item.name == 'OGSatisfactionStatus') {
					dataSour = this.listEnumSatisfactionText
				}
				this.comPickerInfo = {
					showSheet: true,
					columns: [dataSour],
					dataItem: item.data,
					title: item.title,
					name: item.name
				}
			},
			onConfirmPicker(e) {
				//赋枚举值
				if (this.comPickerInfo.name == 'OGAssigneeStatus') {
					this.comPickerInfo.dataItem.ASSIGNEE_STATUS_SHOW = e.value[0]
					this.comPickerInfo.dataItem.ASSIGNEE_STATUS = this.listEnumStatus[e.indexs[0]].code
				} else if (this.comPickerInfo.name == 'OGSatisfactionStatus') {
					this.comPickerInfo.dataItem.SATISFACTION_STATUS_SHOW = e.value[0]
					this.comPickerInfo.dataItem.SATISFACTION_STATUS = this.listEnumSatisfactionText[e.indexs[0]].code
				}

				this.comPickerInfo = {
					showSheet: false,
					dataItem: this.comPickerInfo.dataItem,
					columns: [],
					title: '',
					name: '',
					formIndex: undefined
				}
			}
		}
	}
</script>

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

	.todo-page>>>.u-steps-item__line {
		width: 187.6px !important;
	}
</style>