<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="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> -->
										<view style="margin-bottom: 16px;" 
											v-for="(item, index) in dataModel.Nav_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="files" borderBottom>
												</u-form-item>
												<u-link v-for="itemChild in item.files" :href="itemChild.url" :text="itemChild.name">
												</u-link>
											</uni-card>
										</view>
									<!-- </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 {
		getOrdinaryGet,
		getOrdinarySign
	} 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.handleGetOrdinaryGet(opt)
		},
		methods: {
			handleGetOrdinaryGet(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 未获取
				getOrdinaryGet(json).then(res => {
					this.dataModel = res.Data
					//数据组装
					let strUserFiles = [{
						url: '',
						name:''
					}]
					
					//数据组装
					let strUserName = ''
					if (res.Data.Nav_OrdinaryAnalysisPerson && res.Data.Nav_OrdinaryAnalysisPerson.length > 0) {
						for (let i = 0; i < res.Data.Nav_OrdinaryAnalysisPerson.length; i++) {
							if (res.Data.Nav_OrdinaryAnalysisPerson[i].DEAL_STATUS == 0) {
								strUserName += (strUserName.length > 0 ? "&nbsp;&nbsp;" : "") + "<text style='color:red'>" +
									res.Data.Nav_OrdinaryAnalysisPerson[i].Nav_User.NAME + "</text>";
							} else {
								let user=res.Data.Nav_OrdinaryAnalysisPerson[i].USER_ID!=null?res.Data.Nav_OrdinaryAnalysisPerson[i].Nav_User.NAME:'';
								strUserName += (strUserName.length > 0 ? "&nbsp;&nbsp;" : "") + user;
							}
					
						}
					}
					if (res.Data.Nav_Details && res.Data.Nav_Details.length > 0) {
						let strconfirmFiles = [{
							url: '',
							name:''
						}]
						for (let i = 0; i < res.Data.Nav_Details.length; i++) {
							if (res.Data.Nav_Details[i].CYCLE_TYPE == 0) {
								res.Data.Nav_Details[i].CYCLE_TYPE = "需求作业"
							} else {
								res.Data.Nav_Details[i].CYCLE_TYPE="每日作业"
							}
							let details=res.Data.Nav_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_source_url+ details.Nav_Files[j].Nav_ImgFile.FILE_PATH,
								name:details.Nav_Files[j].Nav_ImgFile.FILE_NAME
								})
								details.files = strconfirmFiles
								}
							}
						}
					}
					this.dataModel.UserNames = strUserName
					this.dataModel.UserFiles = strUserFiles
					this.isLoadOK = true
				})
			},
			onTableBtnAgree() {
				let json={};
				json.ID=this.ID;
				json.TaskID=this.TaskID;
				getOrdinarySign(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>
