<template>
	<view class="page-wrap" v-bind:style="{paddingBottom:paddingBottom+'px'}">
		<view class="background"></view>
		<view class="card">
			<!-- <uni-card margin="0" :is-shadow="true"> -->
			<u--form labelPosition="left" labelWidth="auto" labelAlign="center" :model="model" 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_Project.NAME" borderBottom>
					<u--input v-if="model.Nav_Project" v-model="model.Nav_Project.NAME" border="none" inputAlign="right" disabled disabledColor="#ffffff" fontSize="14px"></u--input>
				</u-form-item>
				<u-form-item label="外包单位名称：" prop="Nav_Project.UNIT_NAME" borderBottom>
					<u--input v-if="model.Nav_Project" v-model="model.Nav_Project.UNIT_NAME" border="none" inputAlign="right" disabled disabledColor="#ffffff" fontSize="14px"></u--input>
				</u-form-item>
				<u-form-item label="作业类别：" prop="Nav_Type.NAME" borderBottom>
					<u--input v-if="model.Nav_Type" v-model="model.Nav_Type.NAME" border="none" inputAlign="right" disabled disabledColor="#ffffff" fontSize="14px"></u--input>
				</u-form-item>
				<u-form-item label="危险作业名称：" prop="DANGEROUS_JOB_NAME" borderBottom>
					<u--input autoHeight v-model="model.DANGEROUS_JOB_NAME" border="none" inputAlign="right" disabled disabledColor="#ffffff" fontSize="14px"></u--input>
				</u-form-item>
				<u-form-item label="危险作业具体事项：" prop="DANGEROUS_JOB_ITEM" borderBottom>
					<u--input autoHeight v-model="model.DANGEROUS_JOB_ITEM" border="none" inputAlign="right" disabled disabledColor="#ffffff" fontSize="14px"></u--input>
				</u-form-item>
				<u-form-item label="作业风险辨识：" prop="JOB_RISK_IDENTIFY" borderBottom>
					<u--input autoHeight v-model="model.JOB_RISK_IDENTIFY" border="none" inputAlign="right" disabled disabledColor="#ffffff" fontSize="14px"></u--input>
				</u-form-item>
				<u-form-item label="作业开始时间：" prop="START_TIME" borderBottom>
					<u--input autoHeight v-model="model.START_TIME" border="none" inputAlign="right" disabled disabledColor="#ffffff" fontSize="14px"></u--input>
				</u-form-item>
				<u-form-item label="作业结束时间：" prop="END_TIME" borderBottom>
					<u--input autoHeight v-model="model.END_TIME" border="none" inputAlign="right" disabled disabledColor="#ffffff" fontSize="14px"></u--input>
				</u-form-item>
				<u-form-item label="作业地点：" prop="JOB_ADDRESS" borderBottom>
					<u--input autoHeight v-model="model.JOB_ADDRESS" border="none" inputAlign="right" disabled disabledColor="#ffffff" fontSize="14px"></u--input>
				</u-form-item>
				<u-form-item label="现场监护人：" prop="Nav_User.NAME" borderBottom>
					<u--input v-if="model.Nav_User" v-model="model.Nav_User.NAME" border="none" inputAlign="right" disabled disabledColor="#ffffff" fontSize="14px"></u--input>
				</u-form-item>
				<u-form-item label="交底时间" prop="DISCLOSE_TIME" borderBottom>
					<u--input disabledColor="#fff" disabled v-model="model.DISCLOSE_TIME" border="none" inputAlign="right" fontSize="14px"></u--input>
				</u-form-item>
				<u-form-item label="交底人:" borderBottom>
					<u--input disabledColor="#fff" disabled v-model="model.Nav_DisCloseUser.NAME" border="none" inputAlign="right" fontSize="14px"></u--input>
				</u-form-item>
				<u-form-item label="被交底人:" prop="UsersName">
				</u-form-item>
				<u-textarea v-model="model.UserNames" disabled autoHeight placeholder="请选择被交底人"></u-textarea>
				<view class="upload-title">附件:</view>
				<full-upload v-model="model.Nav_DisCloseFiles" :listProp='listPropUpload' :listPropVal='listPropValUpload' :isShowBtn="false"></full-upload>
			</u--form>
			<u--form labelPosition="left" labelWidth="auto" labelAlign="center" errorType="border-bottom" ref="sForm" class="sub-form" style="margin-top: 10px;" v-if="model.Nav_DisCloseDetails.length>0">
				<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>

				<uni-collapse :border="false" accordion>
					<view v-for="(item, index) in model.Nav_DisCloseDetails" :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.MEASURE}}
									</view>

								</view>
							</template>
							<view class="content" style="margin: 0px 10px;">
								<u-form-item label="序号" prop="ROW_NUM" borderBottom>
									<u--input disabledColor="#fff" disabled v-model="item.ROW_NUM" border="none" inputAlign="right" fontSize="14px"></u--input>
								</u-form-item>
								<u-form-item label="安全措施" class="subRequired" prop="MEASURE" borderBottom>
									<u--input disabledColor="#fff" disabled v-model="item.MEASURE" border="none" inputAlign="right" fontSize="14px"></u--input>
								</u-form-item>
							<!-- 	<u-form-item label="是否涉及" class="subRequired" prop="ISORNOTShow" borderBottom>
									<view class="right-align">{{transLevel(item.ISORNOT)}}</view>
								</u-form-item> -->
								<u-form-item label="说明" prop="REMARK" borderBottom>
									<u--input disabledColor="#fff" disabled v-model="item.REMARK" border="none" inputAlign="right" fontSize="14px"></u--input>
								</u-form-item>
							</view>


						</uni-collapse-item>
						<!-- <u-collapse-item :title="item.ROW_NUM + '. ' + item.MEASURE+' - '+transLevel(item.ISORNOT)+' - '+item.REMARK">
						</u-collapse-item> -->
					</view>
				</uni-collapse>
			</u--form>
			<!-- 	<u-sticky offset-top="20">
				<view class="sub-form">
					<view class="sub-form-wrap">
						<u--form labelPosition="left" labelWidth="auto" labelAlign="center" errorType="border-bottom" ref="sForm">
							<u-collapse :border="false" accordion>
								<uni-card style="margin-bottom: 16px;" margin="0" spacing="0" :is-shadow="false" v-for="(item, index) in model.Nav_DisCloseDetails">
									<u-collapse-item :title="item.ROW_NUM + '. ' + item.MEASURE+' - '+transLevel(item.ISORNOT)+' - '+item.REMARK">
									</u-collapse-item>
								</uni-card>
							</u-collapse>
						</u--form>
					</view>
				</view>
			</u-sticky> -->
			<!-- </uni-card> -->
			<!-- <check-action v-if="isLoadOK&&tableKey==1&&isAudit" :okApi="okApi" :refuseApi="refuseApi" :dataSource="$store.state.auditModel"></check-action> -->
		</view>
		<view class="bottom-button" style="padding: 10px 16px;" v-if="isLoadOK&&(tableKey==1||tableKey==4)&&this.isSign">
			<u-button type="primary" @click="onTableBtnAgree" color="#3d4b70">签到</u-button>
		</view>

	</view>
</template>

<script>
	import {
		initFilter,
		extendRule,
		extendInclude
	} from '../../../../utils/common'

	import {
		getRequest,
	} from '../../../../services/apply/FOServices/FOServices'
	import {
		GetDangerousJob,
		WBdiscloseSign
	} from '../../../../services/apply/subPages/scWB';
	import '../../../../utils/showMsg.js'
	import color from '../../../../uni_modules/uview-ui/libs/config/color'
	import config from '../../../../config/common'

	export default {
		data() {
			return {
				model: {
					ID: '',
					ORG_ID: '',
					TaskID: null,
					Nav_Files: [],
					AUDIT_OPINION: '',
					PROJECT_ID: '',
					Nav_Project: {
						NAME: ''
					},
					UNIT_NAME: '',
					TYPE_ID: '',
					Nav_Type: {
						NAME: ''
					},
					DANGEROUS_JOB_NAME: '',
					DANGEROUS_JOB_ITEM: '',
					JOB_RISK_IDENTIFY: '',
					START_TIME: '',
					END_TIME: '',
					JOB_ADDRESS: '',
					UsersName: '',
					Nav_DisCloseUsers: [{
						Nav_User: {
							NAME: ''
						}
					}],
					PARENT_ID: '',
					Nav_DisCloseUser: {
						NAME: ''
					},
					DISCLOSE_USER_ID: '',
					USER_ID: '',
					Nav_User: {
						NAME: ''
					},
					DISCLOSE_TIME: '',
					Nav_DisCloseFiles: [],
					Nav_DisCloseDetails: [{
						ID: '',
						ORG_ID: '',
						PARENT_ID: '',
						ROW_NUM: '',
						MEASURE: '安全措施',
						ISORNOT: '',
						ISORNOTShow: '',
						REMARK: '',
					}]
				},
				listPropUpload: ['PARENT_ID'],
				listPropValUpload: [],
				paddingBottom: '150',
				TaskID: "",
				tableKey: '0',
				isLoadOK: false,
				isSign: true,
				isAudit: true,
				DEALOPINION: "",
				ORG_ID: uni.getStorageSync('orgId'),
			}
		},
		onLoad(option) {
			this.model.ID = option.ID;
			this.TaskID = option.taskID;
			this.tableKey = option.tableKey ? option.tableKey : '0'
			this.okApi = option.okApi
			this.refuseApi = option.refuseApi
			this.auditModel = {
				...this.$store.state.auditModel,
				TaskID: option.taskID ? option.taskID : ''
			}
			this.loadData()
		},
		methods: {
			transLevel(level) {
				if (level == 0) {
					return '否';
				}
				if (level == 1) {
					return '是 ';
				}
			},
			loadData() {
				const json = initFilter(this.ORG_ID)
				extendRule(json, 'ID', 1, this.model.ID);
				extendInclude(json, 'Nav_Project')
				extendInclude(json, 'Nav_DisCloseUser')
				extendInclude(json, 'Nav_Type')
				extendInclude(json, 'Nav_User')
				extendInclude(json, 'Nav_DisCloseUsers.Nav_User')
				extendInclude(json, 'Nav_DisCloseDetails')
				extendInclude(json, 'Nav_DisCloseFiles.Nav_ImgFile')
				GetDangerousJob(json).then(res => {
					this.model = res
					this.initializeMissingFields();
					let strUserName = []
					if (this.model.Nav_DisCloseUsers.length > 0) {
						this.model.Nav_DisCloseUsers.forEach((item, i) => {
							if (item.Nav_User.NAME != null) {
								if (i > 0) {
									strUserName += ' '
								}
								strUserName += item.Nav_User.NAME
							}
						})
					}

					this.model.UserNames = strUserName;
					// if (this.model.STATUS == 30) {
					// 	this.isSign = true;
					// 	this.isAudit = false;
					// } else if (this.model.STATUS == 20) {
					// 	this.isSign = false;
					// 	this.isAudit = true;
					// }
					this.isLoadOK = true
				})
			},
			initializeMissingFields() {
				const fields = ['Nav_DisCloseUser', 'Nav_Project', 'Nav_Type', 'Nav_User'];
				fields.forEach(field => {
					if (!this.model[field]) {
						if (field == 'Nav_Project') {
							this.model[field] = {
								NAME: '',
								UNIT_NAME: ''
							};
						} else {
							this.model[field] = {
								NAME: ''
							};
						}

					}
				});
			},
			onTableBtnAgree() {
				const json = initFilter(this.ORG_ID)
				json.Parameter1 = this.model.ID;
				json.Parameter2 = this.TaskID;
				json.Parameter3 = uni.getStorageSync('appInfo')?.User?.ID || ''
				
				WBdiscloseSign(json).then(res => {
					if (res) {
						uni.$showMsgFunc('操作成功!', () => {
							uni.navigateBack()
						}, 'success', 1000)
					}
				})
			},

		}
	}
</script>

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