<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>
										<u-swipe-action-item style="margin-bottom: 16px;" :options="options"
											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="OperationStepName" borderBottom>
													<u--input disabled disabledColor="#fff" v-model="item.OperationStepName"
																		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="DetailPost" borderBottom>
													<u--input disabled disabledColor="#fff" v-model="item.DetailPost"
																		border="none" inputAlign="right"></u--input>
													
												</u-form-item>
											</uni-card>
										</u-swipe-action-item>
									</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 {
		getIdentifyGet,
		getIdentitySign
	} 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.handleGetIdentityGet(opt)
		},
		methods: {
			handleGetIdentityGet(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 未获取
				getIdentifyGet(json).then(res => {
					this.dataModel = res.Data
					//数据组装
					let strUserFiles = [{
						url: '',
						name:''
					}]
					if (res.Data.Nav_Files && res.Data.Nav_Files.length > 0) {
						for (let i = 0; i < res.Data.Nav_Files.length; i++) {
							strUserFiles.push({
								url: config.uni_app_web_local_api_url+res.Data.Nav_Files[i].Nav_ImgFile.Nav_File.FILE_PATH,
								name:res.Data.Nav_Files[i].Nav_ImgFile.FILE_NAME
							})
						}
					}
					//数据组装
					let strUserName = ''
					if (res.Data.Nav_IdentifyUser && res.Data.Nav_IdentifyUser.length > 0) {
						for (let i = 0; i < res.Data.Nav_IdentifyUser.length; i++) {
							if (res.Data.Nav_IdentifyUser[i].DEAL_STATUS == 0) {
								strUserName += (strUserName.length > 0 ? "&nbsp;&nbsp;" : "") + "<text style='color:red'>" +
									res.Data.Nav_IdentifyUser[i].Nav_User.NAME + "</text>";
							} else {
								let user=res.Data.Nav_IdentifyUser[i].USER_ID!=null?res.Data.Nav_IdentifyUser[i].Nav_User.NAME:'';
								strUserName += (strUserName.length > 0 ? "&nbsp;&nbsp;" : "") + user;
							}
					
						}
					}
					if (res.Data.Nav_Details && res.Data.Nav_Details.length > 0) {
						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="每日作业"
							}
						}
					}
					this.dataModel.UserNames = strUserName
					this.dataModel.UserFiles = strUserFiles
					this.isLoadOK = true
				})
			},
			onTableBtnAgree() {
				let json={};
				json.ID=this.ID;
				json.TaskID=this.TaskID;
				getIdentitySign(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>
