<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="userName" borderBottom>
						<u--input v-model="dataModel.Nav_CreateUser.NAME" disabled  border="none" disabledColor="#ffffff"
							inputAlign="right"></u--input>
					</u-form-item>
					<u-form-item label="发起时间" prop="CREATE_TIME" borderBottom>
						<u--input v-model="dataModel.CREATE_TIME" disabled  border="none" disabledColor="#ffffff"
							inputAlign="right"></u--input>
					</u-form-item>
					<!-- <u-form-item label="完成时间" prop="COMPLETE_DATE" borderBottom>
						<u--input v-model="dataModel.COMPLETE_DATE" disabled  border="none" disabledColor="#ffffff"
							inputAlign="right"></u--input>
					</u-form-item> -->
					<u-form-item label="附件" prop="UserFiles" borderBottom>
					</u-form-item>
					<u-link v-for="item in dataModel.UserFiles" :href="item.url" :text="item.name">
					</u-link>
					<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">
				<u-collapse :border="false" accordion>
					<uni-card margin="0" spacing="0" padding="0" :is-shadow="true">
						<u-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> -->
										<view style="margin-bottom: 16px;" 
											v-for="(item, index) in dataModel.Nav_AnalyzeDetails">
											<uni-card margin="0" spacing="0" :is-shadow="false"
												style="margin-bottom: 10px;">
												<u-form-item label="作业名称" prop="OperationStepName" 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="AnalyzeH" borderBottom>
													<u--input disabled disabledColor="#fff" v-model="item['Nav_DistinguishAnalyzeH'].NAME"
																		border="none" inputAlign="right"></u--input>
													
												</u-form-item>
												<u-form-item label="损失" prop="AnalyzeL" borderBottom>
													<u--input disabled disabledColor="#fff" v-model="item['Nav_DistinguishAnalyzeL'].NAME"
																		border="none" inputAlign="right"></u--input>
													
												</u-form-item>
												<u-form-item label="环境污染" prop="AnalyzeE" borderBottom>
													<u--input disabled disabledColor="#fff" v-model="item['Nav_DistinguishAnalyzeE'].NAME"
																		border="none" inputAlign="right"></u--input>
													
												</u-form-item>
												<u-form-item label="概率" prop="AnalyzeP" borderBottom>
													<u--input disabled disabledColor="#fff" v-model="item['Nav_DistinguishAnalyzeP'].NAME"
																		border="none" inputAlign="right"></u--input>
													
												</u-form-item>
												<u-form-item label="重复发生率" prop="AnalyzeR" borderBottom>
													<u--input disabled disabledColor="#fff" v-model="item['Nav_DistinguishAnalyzeR'].NAME"
																		border="none" inputAlign="right"></u--input>
													
												</u-form-item>
												<u-form-item label="总得分" prop="SCORE" borderBottom>
													<u--input disabled disabledColor="#fff" v-model="item.SCORE"
																		border="none" inputAlign="right"></u--input>
													
												</u-form-item>
												<u-form-item label="关键任务" prop="IS_MAINTASK" borderBottom>
													<u--input disabled disabledColor="#fff" v-model="item.IS_MAINTASK"
																		border="none" inputAlign="right"></u--input>
													
												</u-form-item>
												<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>
											</uni-card>
										</view>
									<!-- </u-swipe-action> -->
								</u--form>
							</view>
						</u-collapse-item>
					</uni-card>
				</u-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 {
		getAnalyzeGet,
		getAnalyzeSign,
	} from '../../../../services/apply/HMServices/HMServices.js'
	import config from '../../../../config/common'

	export default {
		data() {
			return {
				tableKey:0,
				isLoadOK :false,
				isAudit: false,
				dataModel: {
					CODE: '',
					Nav_CreateUser:[]
				},
				subDataModel: {
					
				},
				options: [{
					text: '删除',
					style: {
						backgroundColor: '#f56c6c'
					}
				}],
				comPickerInfo: {
					showSheet: false,
					columns: [],
					title: '',
					dataIndex: undefined,
					formIndex: undefined,
					name: ''
				},
				currentOperateUser: {},
				showPopup: false,
			}
		},
		onLoad(opt) {
			this.handleGetAnalyzeGet(opt)
		},
		methods: {
			handleGetAnalyzeGet(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 未获取
				getAnalyzeGet(json).then(res => {
					this.dataModel = res.Data
					//数据组装
					let strUserFiles = [{
						url: '',
						name:''
					}]
					if (res.Data.Nav_AnalyzeFiles && res.Data.Nav_AnalyzeFiles.length > 0) {
						for (let i = 0; i < res.Data.Nav_AnalyzeFiles.length; i++) {
							strUserFiles.push({
								url: config.uni_app_web_source_url+res.Data.Nav_AnalyzeFiles[i].Nav_ImgFile.FILE_PATH,
								name:res.Data.Nav_AnalyzeFiles[i].Nav_ImgFile.FILE_NAME
							})
						}
					}
					//数据组装
					let strUserName = ''
					if (res.Data.Nav_Users && res.Data.Nav_Users.length > 0) {
						for (let i = 0; i < res.Data.Nav_Users.length; i++) {
							if (res.Data.Nav_Users[i].DEAL_STATUS == 0) {
								strUserName += (strUserName.length > 0 ? "&nbsp;&nbsp;" : "") + "<text style='color:red'>" +
									res.Data.Nav_Users[i].Nav_User.NAME + "</text>";
							} else {
								let user=res.Data.Nav_Users[i].USER_ID!=null?res.Data.Nav_Users[i].Nav_User.NAME:'';
								strUserName += (strUserName.length > 0 ? "&nbsp;&nbsp;" : "") + user;
							}
					
						}
					}
					if (res.Data.Nav_AnalyzeDetails && res.Data.Nav_AnalyzeDetails.length > 0) {
						for (let i = 0; i < res.Data.Nav_AnalyzeDetails.length; i++) {
							if (res.Data.Nav_AnalyzeDetails[i].CYCLE_TYPE == 0) {
								res.Data.Nav_AnalyzeDetails[i].CYCLE_TYPE = "需求作业"
							} else {
								res.Data.Nav_AnalyzeDetails[i].CYCLE_TYPE="每日作业"
							}
							if(res.Data.IS_MAINTASK == 0){
								res.Data.Nav_AnalyzeDetails[i].IS_MAINTASK = "否"
							}else {
								res.Data.Nav_AnalyzeDetails[i].IS_MAINTASK="是"
							}
							if(res.Data.Nav_AnalyzeDetails[i].ANALYZE_H_ID ===null)
							{
								res.Data.Nav_AnalyzeDetails[i].Nav_DistinguishAnalyzeH={CODE:'',NAME:'',SCORE:0}
							}
							if(res.Data.Nav_AnalyzeDetails[i].ANALYZE_E_ID ===null)
							{
								res.Data.Nav_AnalyzeDetails[i].Nav_DistinguishAnalyzeE={CODE:'',NAME:'',SCORE:0}
							}
							if(res.Data.Nav_AnalyzeDetails[i].ANALYZE_P_ID ===null)
							{
								res.Data.Nav_AnalyzeDetails[i].Nav_DistinguishAnalyzeP={CODE:'',NAME:'',SCORE:0}
							}
							if(res.Data.Nav_AnalyzeDetails[i].ANALYZE_R_ID ===null)
							{
								res.Data.Nav_AnalyzeDetails[i].Nav_DistinguishAnalyzeR={CODE:'',NAME:'',SCORE:0}
							}
							if(res.Data.Nav_AnalyzeDetails[i].ANALYZE_L_ID ===null)
							{
								res.Data.Nav_AnalyzeDetails[i].Nav_DistinguishAnalyzeL={CODE:'',NAME:'',SCORE:0}
							}
							if(res.Data.Nav_AnalyzeDetails[i].WORK_PERMIT_TYPE_ID ===null)
							{
								res.Data.Nav_AnalyzeDetails[i].Nav_WorkPermitType={CODE:'',NAME:''}
							}
						}
					}
					this.dataModel.UserNames = strUserName
					this.dataModel.UserFiles = strUserFiles
					this.isLoadOK = true
				})
			},
			onTableBtnAgree() {
				let json={};
				json.ID=this.ID;
				json.TaskID=this.TaskID;
				getAnalyzeSign(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>
