<template>
	<view class="todo-page">
		<step-title :stepPage="stepsPage" :stepText="stepsText"></step-title>
		<view class="allview">
			<view class="card">
				<u--form labelWidth="auto" :model="dataModel" ref="wForm" 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="Product_Unit" @click="handleChangeUnit()">
						<u--input v-model="dataModel.Product_Unit" disabled disabledColor="#ffffff" placeholder="请选择生产单元" border="none" 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 label="整改记录编号:" @click="handleChangeArea">
						<u--input v-model="dataModel.CODE" placeholder="请选择编号" suffixIcon="arrow-down" suffixIconStyle="font-size: 12px" disabled disabledColor="#ffffff" border="none" inputAlign="right" fontSize="14px">
						</u--input>
					</u-form-item>
					<view style="background-color: #f5f7fa;padding: 0px 15px;">
						<u-form-item label="检查区域:">
							<u--input v-model="dataModel.Nav_RiskArea.NAME" disabled border="none" inputAlign="right" fontSize="14px">
							</u--input>
						</u-form-item>
						<u-form-item label="隐患地点:" prop="HIDDEN_PLACE">
							<u--input v-model="dataModel.HIDDEN_PLACE" disabled inputAlign="right" fontSize="14px" border="none">
							</u--input>
						</u-form-item>
						<u-form-item label="隐患描述:" prop="HIDDEN_DESCRIPTION">
							<u--input v-model="dataModel.HIDDEN_DESCRIPTION" disabled inputAlign="right" fontSize="14px" border="none">
							</u--input>
						</u-form-item>
						<u-form-item label="隐患等级" prop="HIDDEN_LEVEL" @click="handleChangeRiskLevel">
							<u--input v-model="dataModel.HIDDEN_LEVEL" disabled inputAlign="right" fontSize="14px" border="none">
							</u--input>
						</u-form-item>
						<u-form-item label="整改期限" prop="HIDDEN_PLACE">
							<u--input v-model="dataModel.RECITIFY_TIME" disabled inputAlign="right" fontSize="14px" border="none">
							</u--input>
						</u-form-item>
						<view class="upload-title">整改前照片：</view>
						<full-upload v-model="dataModel.Nav_RectifyPhotoas" :isShowBtn='false' :listProp='listPropUpload' :listPropVal='listPropValUpload'></full-upload>
					</view>

					<u-form-item label="延期整改理由:" prop="HIDDEN_LEVEL">
						<u--input v-model="dataModel.DELAY_REASON" placeholder="请填写延期整改理由" disabledColor="#ffffff" inputAlign="right" fontSize="14px" border="none">
						</u--input>
					</u-form-item>
					<u-form-item label="延期整改期限" prop="HIDDEN_PLACE" @click="handleChangeDate()">
						<u--input v-model="dataModel.DELAY_RECITIFY_TIME" disabled placeholder="请选择整改期限" disabledColor="#ffffff" inputAlign="right" fontSize="14px" border="none">
						</u--input>
						<u-icon style="margin-left: 4px;" slot="right" name="arrow-down" size="12">
						</u-icon>
					</u-form-item>
					<u-form-item label="整改前临时措施:">
						<u--input v-model="dataModel.RECITIFY_MEASURES_TEMP" placeholder="请填写整改前临时措施" disabledColor="#ffffff" border="none" inputAlign="right" fontSize="14px">
						</u--input>
					</u-form-item>

				</u--form>

			</view>
			<view style="padding: 10px 16px;" class="bottom-button">
				<u-button type="primary" @click="submit" color="#3d4b70">提交</u-button>
			</view>
			<u-picker :show="showPopupUnit" :columns="UnitLists" @confirm="confirmUnit" @cancel="cancelUnit" :defaultIndex="UnitDefaultIndex"></u-picker>
			<u-datetime-picker :show="showPopupDate" v-model="dateTime" mode="date" @confirm="confirmDate" @cancel="cancelDate"></u-datetime-picker>
			<query-selector :show="showPopupArea" :total="curTotalArea" :lists="areaLists" :defaultValue="currentOperateArea.NAME" @close="handleClosePopupArea" @search="handleSearchArea" @select="handleSelectedArea" />
		</view>
	</view>
</template>

<script>
	import {
		extendFilterGroup,
		extendGroupRule,
		extendInclude,
		extendOrder,
		extendRule,
		extendIgnoreDataRule,
		guid,
		initFilter,
		initFilterGroup
	} from '../../../../utils/common'
	import {
		FMProductionUnit,
		CheckPeriods,
		CheckLevels,
		SKAcceptResultEnum,
		MineTypeIndex,
		MineTypeName
	} from '../../../../utils/enums.js'
	import {
		RectifyDeferrFullUpdate,
		GetRiskCodeInfo
	} from '../../../../services/apply/subPages/SK/SKServices.js'
	import stepTitle from '@/components/custom/step-title.vue'
	export default {
		components: {
			stepTitle,
		},
		data() {
			return {
				showDelModalIndex: undefined,
				showDelModalIndex1: undefined,
				subsectionList: ['入库', '不入库', ],
				radiolist1: [{
					name: '是',
					disabled: false
				}, {
					name: '否',
					disabled: false
				}],
				curNow: 1,
				RiskLevel: ['一般', '重大'],
				Accept: [],

				showPopupUnit: false,
				UnitDefaultIndex: [0],
				showPopupRiskLevel: false,
				RiskLevelDefaultIndex: [0],
				showPopupAccept: false,
				AcceptDefaultIndex: [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,
				showPopupDateTwo: false,
				showPopupRecitifyDate: false,
				listPropUpload: ['NOTIFY_ID'],
				listPropValUpload: [],
				ORG_ID: uni.getStorageSync('orgId'),
				dataModel: {
					Product_Unit: '',
					MineType: '',
					CODE: '',
					Nav_RiskArea: {
						NAME: ''
					},
					HIDDEN_PLACE: '',
					HIDDEN_DESCRIPTION: '',
					HIDDEN_LEVEL: '',
					RECITIFY_TIME: '',
					Nav_RectifyPhotoas: [],
					DELAY_REASON: '',
					DELAY_RECITIFY_TIME: '',
					RECITIFY_MEASURES_TEMP: '',

				},
				model: {
					ORG_ID: '',
					MineType: 0,
					HIDDEN_DANGER_RECTIFY_RECORD_ID: '',
					Nav_RectifyRecord: {
						CODE: '',
						Nav_RiskArea: {
							NAME: ''
						},
						HIDDEN_PLACE: '',
						HIDDEN_DESCRIPTION: '',
						HIDDEN_LEVEL: '',
						RECITIFY_TIME: '',
						Nav_RectifyPhotoas: [],
					},
					DELAY_REASON: '',
					DELAY_RECITIFY_TIME: '',
					RECITIFY_MEASURES_TEMP: '',

				},
				dateTime: uni.$u.timeFormat(new Date(), 'yyyy-mm-dd'),
				stepsText: ['发起', '审批', '审阅', '归档'],
				stepsPage: 0,
				stepsPageList: 0,
				TaskID: '',
				currentOperateArea: {},
				ID:'',

			}
		},
		onLoad(option) {
			this.TaskID = option.taskID ? option.taskID : '';
			this.ID = option.ID ? option.ID : '';
			// this.loadData()
		},
		methods: {
			cancelDate() {
				this.showPopupDate = false
			},
			handleChangeDate() {
				this.showPopupDate = true
			},
			confirmDate(e) {
				this.dataModel.DELAY_RECITIFY_TIME = uni.$u.timeFormat(e.value,
					'yyyy-mm-dd')
				this.dateTime = uni.$u.timeFormat(e.value,
					'yyyy-mm-dd')

				this.showPopupDate = false
			},
			cancelUnit() {
				this.showPopupUnit = false
			},
			handleChangeUnit() {
				this.UnitLists = [FMProductionUnit]
				this.showPopupUnit = true
			},
			confirmUnit(e) {
				this.dataModel.Product_Unit = e.value[0]
				this.showPopupUnit = false
			},

			handleClosePopupArea() {
				this.showPopupArea = false
				// this.showPopupCertificate = false
			},
			handleChangeArea() {
				this.currentOperateArea = {}
				this.showPopupArea = true
				this.handleSearchArea('init')
			},
			handleSearchArea(val, pageIndex) {
				const orgId = uni.getStorageSync('orgId')
				const json = initFilter(orgId, "", "", '', pageIndex)
				if (val !== 'init') {
					const tempGroup = initFilterGroup(false);
					extendGroupRule(tempGroup, 'CODE', 9, val)
					extendFilterGroup(json, tempGroup);
				}
				json.Limit = 20
				if (pageIndex) {
					json.Start = (pageIndex - 1) * 20;
				}
				// extendRule(json, 'ID', 1, this.model.ID);
				extendInclude(json, 'Nav_RiskArea');
				// extendInclude(json, 'Nav_ApplyDepartment');
				// extendInclude(json, 'Nav_RectifyRecord');
				// extendInclude(json, 'Nav_RectifyRecord.Nav_RiskArea');
				// extendInclude(json, 'Nav_RectifyRecord.Nav_RectifyPhotoas.Nav_ImgFile');
				extendIgnoreDataRule(json)
				GetRiskCodeInfo(json).then(res => {
					this.areaLists = res.Data.map(i => {
						return {
							...i,
							id: i.ID,
							name: i.CODE,
						}
					})
					this.curTotalArea = res.TotalCount
				})

			},
			handleSelectedArea(val) {
				this.dataModel = val
				this.dataModel.Product_Unit = MineTypeName[val.MineType]
				this.dataModel.HIDDEN_DANGER_RECTIFY_RECORD_ID = val.ID
				this.dataModel.CODE = val.CODE
				this.dataModel.Nav_RectifyPhotoas = val.Nav_RectifyPhotoas ? val.Nav_RectifyPhotoas : []
				this.dataModel.RECITIFY_TIME = uni.$u.timeFormat(val.RECITIFY_TIME, 'yyyy-mm-dd')
				this.stepsPage = val.STATUS == 0 ? 0 : val.STATUS == 20 ? 1 : val.STATUS == 21 ? 2 : 3
				this.showPopupArea = false

			},


			submit() {
				if (!this.dataModel.Product_Unit) {
					uni.showToast({
						title: '请选择生产单元',
						icon: 'none'
					})
					return
				}
				if (!this.dataModel.CODE) {
					uni.showToast({
						title: '请选择整改记录编号',
						icon: 'none'
					})
					return
				}
				if (!this.dataModel.DELAY_REASON) {
					uni.showToast({
						title: '请填写延期整改理由',
						icon: 'none'
					})
					return
				}
				if (!this.dataModel.DELAY_RECITIFY_TIME) {
					uni.showToast({
						title: '请选择延期整改期限',
						icon: 'none'
					})
					return
				}
				if (!this.dataModel.RECITIFY_MEASURES_TEMP) {
					uni.showToast({
						title: '请填写整改前临时措施',
						icon: 'none'
					})
					return
				}

				// this.model = this.dataModel
				this.model = {
						ORG_ID: this.ORG_ID,
						MineType: MineTypeIndex[this.dataModel.Product_Unit],
						HIDDEN_DANGER_RECTIFY_RECORD_ID: this.dataModel.HIDDEN_DANGER_RECTIFY_RECORD_ID,
						DELAY_REASON: this.dataModel.DELAY_REASON,
						DELAY_RECITIFY_TIME: this.dataModel.DELAY_RECITIFY_TIME,
						RECITIFY_MEASURES_TEMP: this.dataModel.RECITIFY_MEASURES_TEMP,
						ID:this.ID

					},
					this.model.PUBLISH = "SaveAndNotify";
				RectifyDeferrFullUpdate(this.model).then(res => {
					if (res) {
						uni.$showMsgFunc('操作成功!', () => {
							uni.navigateBack()
						}, 'success', 1000)
					}
				})


			}

		}



	}
</script>

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