<template>
	<view class="page-wrap">
		<view class="card">
			<uni-card margin="0" :is-shadow="true">
				<u--form labelPosition="left" labelWidth="auto" labelAlign="center" :model="dataModel" ref="wForm"
					errorType="border-bottom">
					<!-- <u-form-item label="编号" prop="CODE" borderBottom>
						<u--input v-model="dataModel.CODE" disabled disabledColor="#ffffff" placeholder="请输入编号" border="none" inputAlign="right">
						</u--input>
					</u-form-item> -->
					<u-form-item label="作业名称" prop="stepName" borderBottom>
						<u--input v-model="dataModel.Nav_OperationStep.NAME" disabled disabledColor="#ffffff"
							placeholder="请输入作业名称" border="none" inputAlign="right"></u--input>
					</u-form-item>
					<u-form-item label="审批层级" prop="AUDIT_LEVEL" borderBottom>
						<u--input v-model="dataModel.AUDIT_LEVEL" disabled disabledColor="#ffffff" placeholder="请输入审批层级"
							border="none" inputAlign="right"></u--input>
					</u-form-item>
					<u-form-item label="作业地点" prop="JOB_LOCATION" borderBottom>
						<u--input v-model="dataModel.JOB_LOCATION" disabled disabledColor="#ffffff"
							placeholder="请输入作业地点" border="none" inputAlign="right"></u--input>
					</u-form-item>
					<u-form-item label="开始时间" prop="JOB_DATE" borderBottom>
						<u--input v-model="dataModel.JOB_DATE" disabled disabledColor="#ffffff" placeholder="请输入开始时间"
							border="none" inputAlign="right"
							:value="$u.timeFormat(dataModel.JOB_DATE,'yyyy-mm-dd hh:MM:ss')">
						</u--input>
					</u-form-item>
					<u-form-item label="结束时间" prop="JOB_END_DATE" borderBottom>
						<u--input v-model="dataModel.JOB_END_DATE" disabled disabledColor="#ffffff"
							placeholder="请输入结束时间" border="none" inputAlign="right"
							:value="$u.timeFormat(dataModel.JOB_END_DATE,'yyyy-mm-dd hh:MM:ss')">
						</u--input>
					</u-form-item>
					<u-form-item label="作业申请人" prop="applyUser" borderBottom>
						<u--input v-model="dataModel.Nav_ApplyUser.NAME" disabled disabledColor="#ffffff"
							placeholder="请输入作业申请人" border="none" inputAlign="right">
						</u--input>
					</u-form-item>
					<u-form-item label="属地部门" prop="Nav_Department.NAME" borderBottom>
						<u--input disabledColor="#fff" v-model="(dataModel.Nav_Department||{}).NAME" disabled  fontSize="14px"
							border="none" inputAlign="right">
						</u--input>
					</u-form-item>
					<u-form-item label="监护人" prop="monitorUser" borderBottom>
						<u--input v-model="dataModel.Nav_MonitorUser.NAME" disabled disabledColor="#ffffff"
							placeholder="请输入监护人" border="none" inputAlign="right">
						</u--input>
					</u-form-item>
					<u-form-item label="作业区域" prop="Nav_Area.NAME" borderBottom>
						<u--input disabledColor="#fff" v-model="(dataModel.Nav_Area||{}).NAME" disabled   fontSize="14px"
							inputAlign="right" border="none">
						</u--input>
					</u-form-item>
					<u-form-item label="作业原因" prop="JobCause" borderBottom>
						<u--input v-model="dataModel.JobCause" disabled disabledColor="#ffffff" placeholder="请输入作业原因"
							border="none" inputAlign="right">
						</u--input>
					</u-form-item>
					<view class="upload-title" >安全措施确认</view>
					<full-upload v-model="dataModel.Nav_Files" :listProp='listPropUpload'
						:listPropVal='listPropValUpload' :isShowBtn="false"></full-upload>
					<u-form-item label="作业人员" prop="UserNames" borderBottom>
					</u-form-item>
					<u--textarea autoHeight type="textarea" v-html="dataModel.UserNames" border="none"
						inputAlign="right">
					</u--textarea>
					<u-form-item label="作业前安全确认" prop="UserConfirms" borderBottom>
					</u-form-item>
					<u--textarea autoHeight type="textarea" disabled v-model="dataModel.UserConfirms" border="none"
						style="line-height: 100;" inputAlign="right">
					</u--textarea>
					<!-- <u-form-item label="作业流程及安全措施" prop="UserMeasures" borderBottom>
					</u-form-item>
					<u--textarea autoHeight type="textarea" disabled v-model="dataModel.UserMeasures" border="none"
						inputAlign="right">
					</u--textarea>
					<u-form-item label="作业后处理措施" prop="UserDeals" borderBottom>
					</u-form-item>
					<u--textarea autoHeight type="textarea" disabled v-model="dataModel.UserDeals" border="none"
						inputAlign="right">
					</u--textarea> -->
				</u--form>
			</uni-card>
		</view>
		<view v-if="auditData.length>0">
			<view v-for="(item, index) in auditData[0].Nav_ApproveDetails" :key="index">
				<view v-if="item.NODE_APPROVE_STATUS!==0">
					<view v-if="item.Nav_ApproveUser!==null && item.Nav_ApproveUser.FILE_PATH != null&& item.Nav_ApproveUser.FILE_PATH.length>0">
						<view>{{item.NAME}}</view>
						<imageSign slot="right" :user='item.Nav_ApproveUser'>
						</imageSign>
					</view>
				</view>
			</view>
		</view>
		<audit-process :show="showAudit" @close="handleCloseAudit" :dataSource="auditData" />
		<check-action v-if="isLoadOK && tableKey === '1'&&isAudit==='true' " :okApi="okApi" :refuseApi="refuseApi"
			:dataSource="$store.state.auditModel"></check-action>
		<view class="bottom-button">
			<button type="primary" class="bottom" v-if="isLoadOK&&tableKey==='1'&&!isAudit"
				@click="onTableBtnAgree">确认</button>
			<!-- <button type="primary" class="bottom" v-if='isLoadOK&&tableKey==1' @click="onTableBtnAgree">签到</button> -->
		</view>
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex'
	import {
		extendFilterGroup,
		extendGroupRule,
		extendInclude,
		extendOrder,
		extendRule,
		guid,
		initFilter,
		initFilterGroup,
		extendIgnoreDataRule
	} from '../../../../utils/common'
	import {
		getRequest, //getJobGet,
		getUserLists,
		getJobRecordSign,
		// getCertificateLists,
		saveJobRecord
	} from '../../../../services/apply/FOServices/FOServices.js'
	import config from '../../../../config/common'
	import imageSign from '@/components/custom/imageSign.vue'

	export default {
		components: {
			imageSign
		},
		data() {
			return {
				showAudit: false,
				auditData: [],
				ID: null,
				TaskID: null,
				tableKey: 0,
				okApi: '',
				refuseApi: '',
				isAudit: false,
				isLoadOK: false,
				userLists: [],
				certificateLists: [],
				listPropUpload: ['CRUCIAL_LICENSE_JOB_ID'],
				listPropValUpload: [],
				dataModel: {
					Nav_OperationStep: '',
					Nav_ApplyUser: '',
					Nav_MonitorUser: ''
				},
				subDataModel: {},
				options: [{
					text: '删除',
					style: {
						backgroundColor: '#f56c6c'
					}
				}],
				comPickerInfo: {
					showSheet: false,
					columns: [],
					title: '',
					dataIndex: undefined,
					formIndex: undefined,
					name: ''
				},
				currentOperateUser: {},
				showPopup: false,
				// currentCertificate: {},
				// showPopupCertificate: false,
			}
		},
		onLoad(opt) {
			this.handleGetJobGet(opt)
			this.loadAuditData()
		},
		methods: {
			handleGetJobGet(opt) {
				const orgId = uni.getStorageSync('orgId')
				const json = initFilter(orgId, "", "")
				this.TaskID = opt.taskID ? opt.taskID : '';
				this.ID = opt.ID ? opt.ID : '';
				this.tableKey = opt.tableKey ? opt.tableKey : '0'
				this.okApi = opt.okApi
				this.refuseApi = opt.refuseApi
				this.ApproveID = opt.ApproveID
				this.isAudit = opt.isAudit
				this.auditModel = {
					...this.$store.state.auditModel,
					TaskID: opt.taskID ? opt.taskID : ''
				}
				extendRule(json, 'ID', 1, opt.ID)
				// extendInclude(json, 'Nav_OperationStep');
				//  extendInclude(json, 'Nav_ApplyUser');
				//   extendInclude(json, 'Nav_MonitorUser');
				// TODO: id 未获取
				getRequest(json, "/FO/FOCrucialLicenseJob/FullGet").then(res => {
					this.dataModel = res
					//数据组装
					let strUserName = ''
					if (res.Nav_CrucialLicensePerson && res.Nav_CrucialLicensePerson.length > 0) {
						for (let i = 0; i < res.Nav_CrucialLicensePerson.length; i++) {
							if (res.Nav_CrucialLicensePerson[i].DEAL_STATUS == 0) {
								strUserName += (strUserName.length > 0 ? "&nbsp;&nbsp;" : "") +
									"<text style='color:red'>" +
									res.Nav_CrucialLicensePerson[i].Nav_User.NAME + "</text>";
							} else {
								strUserName += (strUserName.length > 0 ? "&nbsp;&nbsp;" : "") + res
									.Nav_CrucialLicensePerson[
										i].Nav_User.NAME;
							}

						}
					}
					//数据组装
					let strConfirms = ''
					if (res.Nav_SafeConfirms && res.Nav_SafeConfirms.length > 0) {
						for (let i = 0; i < res.Nav_SafeConfirms.length; i++) {
							strConfirms += (strConfirms.length > 0 ? "\n" : "") + res.Nav_SafeConfirms[i].NUM +
								"." + res.Nav_SafeConfirms[i].NAME;
						}
					}
					//数据组装
					let strMeasures = ''
					if (res.Nav_SafeMeasures && res.Nav_SafeMeasures.length > 0) {
						for (let i = 0; i < res.Nav_SafeMeasures.length; i++) {
							strMeasures += (strMeasures.length > 0 ? "\n" : "") + res.Nav_SafeMeasures[i].NUM +
								"." + res.Nav_SafeMeasures[i].NAME;
						}
					}
					//数据组装
					let strDeals = ''
					if (res.Nav_DealMeasures && res.Nav_DealMeasures.length > 0) {
						for (let i = 0; i < res.Nav_DealMeasures.length; i++) {
							strDeals += (strDeals.length > 0 ? "\n" : "") + res.Nav_DealMeasures[i].NUM +
								"." + res.Nav_DealMeasures[i].NAME;
						}
					}
					if (res.JOB_DATE) {
						res.JOB_DATE = uni.$u.timeFormat(res.JOB_DATE, 'yyyy-mm-dd hh:MM:ss')
					}
					if (res.JOB_END_DATE) {
						res.JOB_END_DATE = uni.$u.timeFormat(res.JOB_END_DATE, 'yyyy-mm-dd hh:MM:ss')
					}
					this.dataModel.UserNames = strUserName
					this.dataModel.UserConfirms = strConfirms
					this.dataModel.UserMeasures = strMeasures
					this.dataModel.UserDeals = strDeals
					this.isLoadOK = true
				})
			},
			onTableBtnAgree() {
				let json = {};
				json.ID = this.ID;
				json.TaskID = this.TaskID;
				getJobRecordSign(json).then(res => {
					uni.$showMsgFunc('操作成功!', () => {
						uni.navigateBack()
					}, 'success', 1000)
				})
			},

			loadAuditData() {
				const orgId = uni.getStorageSync('orgId')
				const json = initFilter(orgId, this.ID, "CODE", 1)
				return new Promise((resolve, reject) => {
					getRequest(json, "/PF/Approve/GetApproveInfo").then(res => {
						if (res) {
							if (res && res[0].Nav_ApproveDetails.length > 0) {
								res[0].Nav_ApproveDetails.sort((a, b) => a.NUM - b.NUM)
								resolve(res)
							}
							this.auditData = res
						} else {
							uni.showToast({
								title: '暂无审批数据',
								icon: 'none'
							})
						}
					}).catch(err => {
						reject(err)
					})
				})
			},
			handleCloseAudit() {
				this.showAudit = false
			},
			async onNavigationBarButtonTap() {
				// const res = await this.loadAuditData()
				// if (res) {
				// this.auditData = res
				this.showAudit = true
				// }
			}
		}
	}
</script>

<style scoped>
	.page-wrap {
		padding: 16px 16px 166px;
	}

	.card {
		margin-bottom: 18px;
	}

	.sub-form {
		margin-bottom: 16px;
	}

	.bottom-button {
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
		padding: 10px 16px;
		box-sizing: border-box;
		background: #fff;
		z-index: 999;
	}

	.upload-title {
		color: #303133;
		font-size: 15px;
		line-height: 22px;
		padding: 8px 0;
	}

	.page-wrap>>>.u-upload__button {
		margin-bottom: 0;
	}
</style>