<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  border="none" disabledColor="#ffffff"
							inputAlign="right"></u--input>
					</u-form-item>
					<u-form-item label="文件名称" prop="NAME" borderBottom>
						<u--input v-model="dataModel.NAME" disabled  border="none" disabledColor="#ffffff"
							inputAlign="right"></u--input>
					</u-form-item>
					<u-form-item label="发布人" prop="userName" borderBottom>
						<u--input v-model="dataModel.Nav_User.NAME" disabled  border="none" disabledColor="#ffffff"
							inputAlign="right"></u--input>
					</u-form-item>
					<u-form-item label="发布部门" prop="departmentName" borderBottom>
						<u--input v-model="dataModel.Nav_User.Nav_Department.NAME" disabled  border="none" disabledColor="#ffffff"
							inputAlign="right"></u--input>
					</u-form-item>
					<u-form-item label="发布时间" prop="PUBLISH_DATE" borderBottom>
						<u--input v-model="dataModel.PUBLISH_DATE" disabled  border="none" disabledColor="#ffffff"
							inputAlign="right"></u--input>
					</u-form-item>
					<u-form-item label="文件密级" prop="SecretLevel" borderBottom>
						<u--input v-model="dataModel.SecretLevel" disabled  border="none" disabledColor="#ffffff"
							inputAlign="right"></u--input>
					</u-form-item>
					<u-form-item label="文件版次" prop="EDITION" borderBottom>
						<u--input v-model="dataModel.EDITION" disabled  border="none" disabledColor="#ffffff"
							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" disabledColor="#ffffff"
						inputAlign="right">
					</u--textarea>
				</u--form>
			</uni-card>
		</view>
		<u-sticky offset-top="20">
			<view class="sub-form">
				<uni-collapse :border="false" accordion>
					<uni-card margin="0" spacing="0" padding="0" :is-shadow="true">
						<uni-collapse-item title="任务名称">
							<view class="sub-form-wrap" style="height: 500px; overflow: auto">
								<u--form labelPosition="left" labelWidth="auto" labelAlign="center"
									:model="subDataModel" ref="sForm2" errorType="border-bottom">
									<u-swipe-action>
										<u-swipe-action-item style="margin-bottom: 16px;" :options="options"
											v-for="(item, index) in dataModel.Details">
											<uni-card margin="0" spacing="0" :is-shadow="false"
												style="margin-bottom: 10px;">
												<u-form-item label="作业名称" prop="stepName" borderBottom>
													<u--input disabled disabledColor="#fff" v-model="item.Nav_OperationStep.NAME"
																		border="none" inputAlign="right"></u--input>
													
												</u-form-item>
												<u-form-item label="作业周期" prop="CYCLE_TYPE" borderBottom>
													<u--input disabled disabledColor="#fff" v-model="item.CYCLE_TYPE"
																		border="none" inputAlign="right"></u--input>
													
												</u-form-item>
												<u-form-item label="作业前确认" prop="SafeConfirmsStr" borderBottom>
												</u-form-item>
													<u--textarea v-model="item.SafeConfirmsStr"
																	border="none" inputAlign="right"></u--textarea>
												<u-form-item label="作业流程及措施" prop="SafeMeasuresStr" borderBottom>
												</u-form-item>
												<u--textarea v-model="item.SafeMeasuresStr"
																	border="none" inputAlign="right"></u--textarea>
												<u-form-item label="作业后处理措施" prop="DealMeasuresStr" borderBottom>
												</u-form-item>
													<u--textarea v-model="item.DealMeasuresStr"
																	border="none" inputAlign="right"></u--textarea>
												<u-form-item label="作业许可类别" prop="WorkPermitType" borderBottom>
													<u--input disabled disabledColor="#fff" v-model="item['Nav_WorkPermitType'].NAME"
																		border="none" inputAlign="right"></u--input>
													
												</u-form-item>
												<u-form-item label="审批层级" prop="AUDIT_LEVEL" borderBottom>
													<u--input disabled disabledColor="#fff" v-model="item.AUDIT_LEVEL"
																		border="none" inputAlign="right"></u--input>
													
												</u-form-item>
												<u-form-item label="附件" prop="files" borderBottom>
												</u-form-item>
												<u-link v-for="itemChild in item.files" :href="itemChild.url" :text="itemChild.name">
												</u-link>
											</uni-card>
										</u-swipe-action-item>
									</u-swipe-action>
								</u--form>
							</view>
						</uni-collapse-item>
					</uni-card>
				</uni-collapse>
			</view>
		</u-sticky>
		<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 {
		getFilePublishGet,
		getFilePublishSign
	} from '../../../../services/apply/HMServices/HMServices.js'
	import config from '../../../../config/common'

	export default {
		data() {
			return {
				tableKey:0,
				isLoadOK :false,
				isAudit: false,
				dataModel: {
					CODE: '',
					Nav_User:{
						Nav_Department:{
							NAME:''
						},
						NAME:''
					},
				},
				subDataModel: {},
				options: [{
					text: '删除',
					style: {
						backgroundColor: '#f56c6c'
					}
				}],
				comPickerInfo: {
					showSheet: false,
					columns: [],
					title: '',
					dataIndex: undefined,
					formIndex: undefined,
					name: ''
				},
				currentOperateUser: {},
				showPopup: false,
			}
		},
		onLoad(opt) {
			this.handleGetLicenseGet(opt)
		},
		methods: {
			handleGetLicenseGet(opt) {
				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
				const orgId = uni.getStorageSync('orgId')
				const json = initFilter(orgId, "", "")
				 extendRule(json, 'ID', 1, opt.ID)
				// TODO: id 未获取
				getFilePublishGet(json).then(res => {
					this.dataModel = res.Data
					let strDetail = []
					//数据组装
					let strUserName = ''
					if (res.Data.Nav_Area && res.Data.Nav_Area.length > 0) {
						for (let i = 0; i < res.Data.Nav_Area.length; i++) {
							
								let user=res.Data.Nav_Area[i].DEPARTMENT_ID!=null?res.Data.Nav_Area[i].Nav_Department.NAME:'';
								strUserName += (strUserName.length > 0 ? "&nbsp;&nbsp;" : "") + user;

						}
					}
					if (res.Data.SecretLevel == 1) {
						res.Data.SecretLevel = "机密"
					} else if (res.Data.SecretLevel == 2) {
						res.Data.SecretLevel="绝密"
					}
					else
					{
						res.Data.SecretLevel="普通"
					}
					if (res.Data.Nav_License_Details && res.Data.Nav_License_Details.length > 0) {
						for (let i = 0; i < res.Data.Nav_License_Details.length; i++) {
							if (res.Data.Nav_License_Details[i].WORK_PERMIT_TYPE_ID == null) {
								res.Data.Nav_License_Details[i].Nav_WorkPermitType = []
							} 
							if (res.Data.Nav_License_Details[i].OPERATION_STEP_ID == null) {
								res.Data.Nav_License_Details[i].Nav_OperationStep = []
							} 
							if (res.Data.Nav_License_Details[i].CYCLE_TYPE == 0) {
								res.Data.Nav_License_Details[i].CYCLE_TYPE = "需求作业"
							} else {
								res.Data.Nav_License_Details[i].CYCLE_TYPE="每日作业"
							}
							if (res.Data.Nav_License_Details[i].AUDIT_LEVEL == 0) {
								res.Data.Nav_License_Details[i].AUDIT_LEVEL = "无审批层级"
							} else if(res.Data.Nav_License_Details[i].AUDIT_LEVEL == 1) {
								res.Data.Nav_License_Details[i].AUDIT_LEVEL="一级审批"
							}else if(res.Data.Nav_License_Details[i].AUDIT_LEVEL == 2) {
								res.Data.Nav_License_Details[i].AUDIT_LEVEL="二级审批"
							}
							else if(res.Data.Nav_License_Details[i].AUDIT_LEVEL == 3) {
								res.Data.Nav_License_Details[i].AUDIT_LEVEL="三级审批"
							}
							else if(res.Data.Nav_License_Details[i].AUDIT_LEVEL == 4) {
								res.Data.Nav_License_Details[i].AUDIT_LEVEL="四级审批"
							}
							let strconfirmFiles = [{
								url: '',
								name:''
							}]
							let details=res.Data.Nav_License_Details[i];
							if (details.Nav_Files && details.Nav_Files.length > 0) {
								for (let j = 0; j < details.Nav_Files.length; j++) {
								strconfirmFiles.push({
								url: config.uni_app_web_local_api_url+ details.Nav_Files[j].Nav_ImgFile.Nav_File.FILE_PATH,
								name:details.Nav_Files[j].Nav_ImgFile.FILE_NAME
								})
								details.files = strconfirmFiles
								}
							}
							strDetail.push(res.Data.Nav_License_Details[i]);
						}
					}
					if (res.Data.Nav_Crucial_Details && res.Data.Nav_Crucial_Details.length > 0) {
						for (let i = 0; i < res.Data.Nav_Crucial_Details.length; i++) {
							if (res.Data.Nav_Crucial_Details[i].WORK_PERMIT_TYPE_ID == null) {
								res.Data.Nav_Crucial_Details[i].Nav_WorkPermitType = []
							} 
							if (res.Data.Nav_Crucial_Details[i].OPERATION_STEP_ID == null) {
								res.Data.Nav_Crucial_Details[i].Nav_OperationStep = []
							} 
							if (res.Data.Nav_Crucial_Details[i].CYCLE_TYPE == 0) {
								res.Data.Nav_Crucial_Details[i].CYCLE_TYPE = "需求作业"
							} else {
								res.Data.Nav_Crucial_Details[i].CYCLE_TYPE="每日作业"
							}
							if (res.Data.Nav_Crucial_Details[i].AUDIT_LEVEL == 0) {
								res.Data.Nav_Crucial_Details[i].AUDIT_LEVEL = "无审批层级"
							} else if(res.Data.Nav_Crucial_Details[i].AUDIT_LEVEL == 1) {
								res.Data.Nav_Crucial_Details[i].AUDIT_LEVEL="一级审批"
							}else if(res.Data.Nav_Crucial_Details[i].AUDIT_LEVEL == 2) {
								res.Data.Nav_Crucial_Details[i].AUDIT_LEVEL="二级审批"
							}
							else if(res.Data.Nav_Crucial_Details[i].AUDIT_LEVEL == 3) {
								res.Data.Nav_Crucial_Details[i].AUDIT_LEVEL="三级审批"
							}
							else if(res.Data.Nav_Crucial_Details[i].AUDIT_LEVEL == 4) {
								res.Data.Nav_Crucial_Details[i].AUDIT_LEVEL="四级审批"
							}
							let strconfirmFiles = [{
								url: '',
								name:''
							}]
							let details=res.Data.Nav_Crucial_Details[i];
							if (details.Nav_Files && details.Nav_Files.length > 0) {
								for (let j = 0; j < details.Nav_Files.length; j++) {
								strconfirmFiles.push({
								url: config.uni_app_web_local_api_url+ details.Nav_Files[j].Nav_ImgFile.Nav_File.FILE_PATH,
								name:details.Nav_Files[j].Nav_ImgFile.FILE_NAME
								})
								details.files = strconfirmFiles
								}
							}
							strDetail.push(res.Data.Nav_Crucial_Details[i]);
						}
					}
					if (res.Data.Nav_Ordinary_Details && res.Data.Nav_Ordinary_Details.length > 0) {
						for (let i = 0; i < res.Data.Nav_Ordinary_Details.length; i++) {
							if (res.Data.Nav_Ordinary_Details[i].WORK_PERMIT_TYPE_ID == null) {
								res.Data.Nav_Ordinary_Details[i].Nav_WorkPermitType = []
							} 
							if (res.Data.Nav_Ordinary_Details[i].OPERATION_STEP_ID == null) {
								res.Data.Nav_Ordinary_Details[i].Nav_OperationStep = []
							} 
							if (res.Data.Nav_Ordinary_Details[i].CYCLE_TYPE == 0) {
								res.Data.Nav_Ordinary_Details[i].CYCLE_TYPE = "需求作业"
							} else {
								res.Data.Nav_Ordinary_Details[i].CYCLE_TYPE="每日作业"
							}
							if (res.Data.Nav_Ordinary_Details[i].AUDIT_LEVEL == 0) {
								res.Data.Nav_Ordinary_Details[i].AUDIT_LEVEL = "无审批层级"
							} else if(res.Data.Nav_Ordinary_Details[i].AUDIT_LEVEL == 1) {
								res.Data.Nav_Ordinary_Details[i].AUDIT_LEVEL="一级审批"
							}else if(res.Data.Nav_Ordinary_Details[i].AUDIT_LEVEL == 2) {
								res.Data.Nav_Ordinary_Details[i].AUDIT_LEVEL="二级审批"
							}
							else if(res.Data.Nav_Ordinary_Details[i].AUDIT_LEVEL == 3) {
								res.Data.Nav_Ordinary_Details[i].AUDIT_LEVEL="三级审批"
							}
							else if(res.Data.Nav_Ordinary_Details[i].AUDIT_LEVEL == 4) {
								res.Data.Nav_Ordinary_Details[i].AUDIT_LEVEL="四级审批"
							}
							let strconfirmFiles = [{
								url: '',
								name:''
							}]
							let details=res.Data.Nav_Ordinary_Details[i];
							if (details.Nav_Files && details.Nav_Files.length > 0) {
								for (let j = 0; j < details.Nav_Files.length; j++) {
								strconfirmFiles.push({
								url: config.uni_app_web_local_api_url+ details.Nav_Files[j].Nav_ImgFile.Nav_File.FILE_PATH,
								name:details.Nav_Files[j].Nav_ImgFile.FILE_NAME
								})
								details.files = strconfirmFiles
								}
							}
							strDetail.push(res.Data.Nav_Ordinary_Details[i]);
						}
					}
					this.dataModel.UserNames = strUserName
					this.dataModel.Details = strDetail
					this.isLoadOK = true
				})
			},
			onTableBtnAgree() {
				const json = initFilter(uni.getStorageSync('orgId'), this.ID)
				getFilePublishSign(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>
