<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')">
						</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">
						</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="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="JobCause" borderBottom>
						<u--input v-model="dataModel.JobCause" disabled disabledColor="#ffffff" placeholder="请输入作业原因" border="none" inputAlign="right">
						</u--input>
					</u-form-item>
					<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>
		<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'

	export default {
		data() {
			return {
				ID:null,
				TaskID: null,
				tableKey: 0,
				okApi: '',
				refuseApi: '',
				isAudit: false,
				isLoadOK :false,
				userLists: [],
				certificateLists:[],
				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)
		},
		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')
					}
					if(res.JOB_END_DATE)
					{
						res.JOB_END_DATE = uni.$u.timeFormat(res.JOB_END_DATE,'yyyy-mm-dd')
					}
					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)
				})
			
			}
		}
	}
</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>
