<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.Nav_RiskArea.NAME" placeholder="请选择检查区域" suffixIcon="arrow-down" suffixIconStyle="font-size: 12px" disabled disabledColor="#ffffff" 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" placeholder="请填写隐患地点" disabledColor="#ffffff" 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" placeholder="请填写隐患描述" disabledColor="#ffffff" inputAlign="right" fontSize="14px" border="none">
						</u--input>
					</u-form-item>
					<view class="upload-title">隐患照片：</view>
					<full-upload v-model="dataModel.Nav_ReportFiles" :isShowBtn='true' :listProp='listPropUpload' :listPropVal='listPropValUpload'></full-upload>

				</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-picker :show="showPopupRiskLevel" :columns="RiskLevel" @confirm="confirmRiskLevel" @cancel="cancelRiskLevel" :defaultIndex="RiskLevelDefaultIndex"></u-picker>
			<u-picker :show="showPopupType" :columns="TypeLists" @confirm="confirmType" @cancel="cancelType" :defaultIndex="TypeDefaultIndex"></u-picker>
			<u-picker :show="showPopupPeriod" :columns="PeriodLists" @confirm="confirmPeriod" @cancel="cancelPeriod" :defaultIndex="PeriodDefaultIndex"></u-picker>
			<u-picker :show="showPopupLevel" :columns="LevelLists" @confirm="confirmLevel" @cancel="cancelLevel" :defaultIndex="LevelDefaultIndex"></u-picker>
			<u-modal :show="showDelModalIndex >= 0" @confirm="confirmDel" @cancel="cacelDel" :showCancelButton="true" title="确认删除？"></u-modal>
			<u-datetime-picker :show="showPopupDate" v-model="dateTime" mode="datetime" @confirm="confirmDate" @cancel="cancelDate"></u-datetime-picker>
			<u-datetime-picker :show="showPopupRecitifyDate" v-model="dateRecitifyTime" mode="datetime" @confirm="confirmRecitifyDate" @cancel="cancelRecitifyDate"></u-datetime-picker>
			<people-selector :defaultChecked="peopleSelectOption.defaultChecked" :show="peopleSelectOption.showSelector" @select="handleSelectorPeople" @close="peopleSelectOption.showSelector = false">
			</people-selector>
			<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,
		MineTypeIndex,
		MineTypeName
	} from '../../../../utils/enums.js'
	import {
		GetCheckContentsInfo,
		GetRiskHandleReport,
		HiddenDangerReportFullUpdate,
		GetRiskAreaInfo,
		getUserLists
	} from '../../../../services/apply/subPages/SK/SKServices.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 {
				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,
				listPropUpload: ['NOTIFY_ID'],
				listPropValUpload: [],
				ORG_ID: uni.getStorageSync('orgId'),
				dataModel: {
					Nav_ReportFiles: [],
					MineType: '',
					Nav_RiskArea: {
						NAME: ''
					},
					RISK_AREA_ID:null,
					HIDDEN_PLACE: '',
					HIDDEN_DESCRIPTION: '',
				},
				model: {
					ORG_ID: '',
					Nav_RiskArea:{
						NAME:''
					},
					RISK_AREA_ID:null

				},
				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'),
				stepsText: ['发起', '归档'],
				stepsPage: 0,
				stepsPageList: 0,
				Pu: '',
				Check_Type_ID: '',
				TypeListres: {},
				TaskID: '',
				poparr: '',
				currentOperateStep: {},
				currentOperateArea: {},
				chooseCheckContent: '',
				chooseCheckArea: '',
				showPopupMonitor: false,
				currentOperateMonitor: {},
				monitorLists: [],
				curTotalMonitor: 0,
				chooseCheckMonitor: '',
				chooseRecitify: '',
				ID:'',

			}
		},
		onLoad(option) {
			this.TaskID = option.taskID ? option.taskID :'';
			this.ID = option.ID ? option.ID :  guid();
			this.loadData()
		},
		methods: {
			loadData() {
				// const json = {}
				const orgId = uni.getStorageSync('orgId')
				const json = initFilter(orgId, "", "")
				extendIgnoreDataRule(json)
				GetRiskHandleReport(json).then(res => {
					// this.model = res;
					this.dataModel.Nav_ReportFiles = res.Nav_ReportFiles ? res.Nav_ReportFiles : []
					this.stepsPage = res.STATUS == 0 ? 0 : 1
					this.dataModel.Product_Unit = MineTypeName[res.MineType]
					this.UnitDefaultIndex = res.MineType == 0 ? [0] : res.MineType == 10 ? [1] : res.MineType == 20 ? [2] : [3]
				})

			},

			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(item) {
				this.chooseCheckArea = item
				this.currentOperateArea = {}
				this.showPopupArea = true
				this.handleSearchArea()
			},
			handleSearchArea(val, pageIndex) {
				const orgId = uni.getStorageSync('orgId')
				const json = initFilter(orgId, "", "",0, pageIndex ?? 1)
				if (val) {
					extendRule(json, 'NAME', 9, val);
				}
				
				
				json.Limit = 20
				if (pageIndex) {
					json.Start = (pageIndex - 1) * json.Limit;
				}
				GetRiskAreaInfo(json).then(res => {
					// if (res.IsSuccessful) {
					this.areaLists = (res.Data || res).map(i => {
						return {
							...i,
							id: i.ID,
							name: i.NAME,
						}
					})
					this.curTotalArea = res.TotalCount
					// }
				})
			},
			handleSelectedArea(val) {
				this.dataModel.RISK_AREA_ID = val.ID
				this.dataModel.Nav_RiskArea = val
				this.showPopupArea = false

			},

			submit() {
				if (!this.dataModel.Product_Unit) {
					uni.showToast({
						title: '请选择生产单元',
						icon: 'none'
					})
					return
				}
				if (!this.dataModel.Nav_RiskArea.NAME) {
					uni.showToast({
						title: '请选择检查区域',
						icon: 'none'
					})
					return
				}
				if (!this.dataModel.HIDDEN_DESCRIPTION) {
					uni.showToast({
						title: '请填写隐患描述',
						icon: 'none'
					})
					return
				}
				if (!this.dataModel.HIDDEN_PLACE) {
					uni.showToast({
						title: '请填写隐患地点',
						icon: 'none'
					})
					return
				}
				if(this.dataModel.Nav_ReportFiles.length==0){
					uni.showToast({
						title: '请上传隐患照片',
						icon: 'none'
					})
					return
				}
				this.model.Nav_RiskArea.NAME = this.dataModel.Nav_RiskArea.NAME
				this.model.RISK_AREA_ID = this.dataModel.RISK_AREA_ID
				this.model.HIDDEN_PLACE = this.dataModel.HIDDEN_PLACE
				this.model.HIDDEN_DESCRIPTION = this.dataModel.HIDDEN_DESCRIPTION
				this.model.MineType = MineTypeIndex[this.dataModel.Product_Unit]
				const result = this.dataModel.Nav_ReportFiles.map((obj) => {
					return Object.assign({
						IMG_FILE_ID: obj.IMG_FILE_ID,
					})
					return obj
				})
				this.model.Nav_ReportFiles = result
				if (this.model.ORG_ID == '') {
					this.model.ORG_ID = this.ORG_ID
				}
				this.model.ID = this.ID;
				this.model.PUBLISH = "SaveAndNotify";
				HiddenDangerReportFullUpdate(this.model).then(res => {
					if (res) {
						uni.$showMsgFunc('操作成功!', () => {
							uni.navigateBack()
						}, 'success', 1000)
					}
				})


			}

		}



	}
</script>

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

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