<template>
	<view class="page-wrap" v-bind:style="{paddingBottom:paddingBottom+'px'}">
		<view class="card">
			<view class="background"></view>
			<!-- <uni-card margin="0" :is-shadow="true"> -->
			<u--form labelPosition="left" labelWidth="auto" labelAlign="center" :model="model" class="demo-ruleForm">
				<u-form-item label="项目名称：" prop="Nav_Project.NAME" borderBottom>
					<u--input v-if="model.Nav_Project" v-model="model.Nav_Project.NAME" border="none" 
						inputAlign="right" disabled disabledColor="#ffffff" fontSize="14px"></u--input>
				</u-form-item>
				<u-form-item label="外包单位名称：" prop="Nav_Project.UNIT_NAME" borderBottom>
					<u--input v-if="model.Nav_Project" v-model="model.Nav_Project.UNIT_NAME" border="none" 
						inputAlign="right" disabled disabledColor="#ffffff" fontSize="14px"></u--input>
				</u-form-item>
				<u-form-item label="作业类别：" prop="Nav_Type.NAME" borderBottom>
					<u--input v-if="model.Nav_Type" v-model="model.Nav_Type.NAME" border="none" 
						inputAlign="right" disabled disabledColor="#ffffff" fontSize="14px"></u--input>
				</u-form-item>
				<u-form-item label="危险作业名称：" prop="DANGEROUS_JOB_NAME" borderBottom>
					<u--input autoHeight v-html="model.DANGEROUS_JOB_NAME" border="none" inputAlign="right" disabled
						disabledColor="#ffffff"  fontSize="14px"></u--input>
				</u-form-item>
				<u-form-item label="危险作业具体事项：" prop="DANGEROUS_JOB_ITEM" borderBottom>
					<u--input autoHeight v-html="model.DANGEROUS_JOB_ITEM" border="none" inputAlign="right" disabled
						disabledColor="#ffffff"  fontSize="14px"></u--input>
				</u-form-item>
				<u-form-item label="作业风险辨识：" prop="JOB_RISK_IDENTIFY" borderBottom>
					<u--input autoHeight v-html="model.JOB_RISK_IDENTIFY" border="none" inputAlign="right" disabled
						disabledColor="#ffffff"  fontSize="14px"></u--input>
				</u-form-item>
				<u-form-item label="作业开始时间：" prop="START_TIME" borderBottom>
					<u--input autoHeight v-html="model.START_TIME" border="none" inputAlign="right" disabled
						disabledColor="#ffffff"  fontSize="14px"></u--input>
				</u-form-item>
				<u-form-item label="作业结束时间：" prop="END_TIME" borderBottom>
					<u--input autoHeight v-html="model.END_TIME" border="none" inputAlign="right" disabled
						disabledColor="#ffffff"  fontSize="14px"></u--input>
				</u-form-item>
				<u-form-item label="作业地点：" prop="JOB_ADDRESS" borderBottom>
					<u--input autoHeight v-html="model.JOB_ADDRESS" border="none" inputAlign="right" disabled
						disabledColor="#ffffff"  fontSize="14px"></u--input>
				</u-form-item>
				<u-form-item label="作业人员：" prop="UserNames" borderBottom class="peoplecur">
					<view v-for="(item,index) in model.UserNames" :key="index">
						<view :style="item.type == 'red'?'color:red':''" class="peoplewrap">{{item.value}}</view>
					</view>
				</u-form-item>
				<u-form-item label="现场监护人：" prop="Nav_User.NAME" borderBottom>
					<u--input v-if="model.Nav_User" v-html="model.Nav_User.NAME" border="none" inputAlign="right"
						disabled disabledColor="#ffffff"  fontSize="14px"></u--input>
				</u-form-item>
				<view class="upload-title">附件</view>
				<full-upload v-model="model.Nav_Files" :listProp='listPropUpload' :listPropVal='listPropValUpload'
					:isShowBtn="false"></full-upload>
			</u--form>
			<u-sticky offset-top="20">
				<view class="sub-form">
					<view class="sub-form-wrap">
						<u--form labelPosition="left" labelWidth="auto" labelAlign="center" errorType="border-bottom"
							ref="sForm">
							<u-collapse :border="false" accordion>
								<uni-card style="margin-bottom: 16px;" margin="0" spacing="0" :is-shadow="false"
									v-for="(item, index) in model.Nav_Detail">
									<u-collapse-item
										:title="item.ROW_NUM + '. ' + item.MEASURE+' - '+transLevel(item.ISORNOT)+' - '+item.REMARK">
									</u-collapse-item>
								</uni-card>
							</u-collapse>
						</u--form>
					</view>
				</view>
			</u-sticky>
			<!-- </uni-card> -->
			<view class="btn-wrap" v-if="isLoadOK&&tableKey==1&&isAudit">
				<u--form>
					<view class="btn-wrap">
						<view>
							<u--textarea height='3em' v-model="DEALOPINION" placeholder="请输入审批意见"></u--textarea>
						</view>
						<view class="buttons">
							<u-button type="primary" color="#3d4b70" class="btn first-btn" @click="onUserAgree(1)"
								text="同意"></u-button>
							<u-button color="#3d4b70" :plain="true" @click="onUserAgree(2)" text="驳回"></u-button>
						</view>
					</view>
				</u--form>
			</view>

		</view>
		<view class="bottom" style="padding: 10px 16px;" v-if="isLoadOK&&tableKey==1&&this.isSign">
			<u-button type="primary" @click="onTableBtnAgree" color="#3d4b70">签到</u-button>
		</view>

	</view>
</template>

<script>
	import {
		initFilter,
		extendRule,
		extendInclude
	} from '../../../../utils/common'

	import {
		getRequest,
	} from '../../../../services/apply/FOServices/FOServices'

	import '../../../../utils/showMsg.js'
	import color from '../../../../uni_modules/uview-ui/libs/config/color'
	import config from '../../../../config/common'

	export default {
		data() {
			return {
				model: {},
				listPropUpload: ['PARENT_ID'],
				listPropValUpload: [],
				paddingBottom: '170',
				TaskID: "",
				tableKey: '0',
				isLoadOK: false,
				isSign: true,
				isAudit: true,
				DEALOPINION: "",
				ORG_ID: uni.getStorageSync('orgId'),
			}
		},
		onLoad(option) {
			this.model.ID = option.ID;
			this.TaskID = option.taskID;
			this.tableKey = option.tableKey ? option.tableKey : '0'
			this.loadData()
		},
		methods: {
			transLevel(level) {
				if (level == 0) {
					return '否';
				}
				if (level == 1) {
					return '是 ';
				}
			},
			loadData() {
				const json = initFilter(this.ORG_ID)
				extendRule(json, 'ID', 1, this.model.ID);
				extendInclude(json, 'Nav_Project')
				extendInclude(json, 'Nav_Type')
				extendInclude(json, 'Nav_User')
				extendInclude(json, 'Nav_Users.Nav_User')
				extendInclude(json, 'Nav_Detail')
				extendInclude(json, 'Nav_Files.Nav_ImgFile')
				getRequest(json, "/WB/DangerousJob/Get").then(res => {
					this.model = res
					let strUserName = []
					if (res.Nav_Users && res.Nav_Users.length > 0) {
						for (let i = 0; i < res.Nav_Users.length; i++) {
							if (res.Nav_Users[i].USER_SHIFT_STATUS == 0) {
								strUserName.push({
									type: 'red',
									value: res.Nav_Users[i].Nav_User.NAME
								})
							} else {
								strUserName.push({
									type: 'normal',
									value: res.Nav_Users[i].Nav_User.NAME
								})
							}

						}
					}

					this.model.UserNames = strUserName;
					if (this.model.STATUS == 30) {
						this.isSign = true;
						this.isAudit = false;
					} else if (this.model.STATUS == 20) {
						this.isSign = false;
						this.isAudit = true;
					}
					this.isLoadOK = true
				})
			},
			onTableBtnAgree() {
				let json = {};
				json.ID = this.model.ID;
				json.TaskID = this.TaskID;
				getRequest(json, "/FO/FOCurrentClassRecord/UserSignin").then(res => {
					if (res) {
						uni.$showMsgFunc('操作成功!', () => {
							uni.navigateBack()
						}, 'success', 1000)
					}
				})
			},
			onUserAgree(agree) {
				if (agree == 1) {
					let json = {};
					json.ID = this.model.ID;
					json.TaskID = this.TaskID;
					json.ORG_ID = this.ORG_ID;
					json.AUDIT_OPINION = this.DEALOPINION;
					getRequest(json, "/WB/WBDangerousJob/UserAgree").then(res => {
						if (res) {
							uni.$showMsgFunc('操作成功!', () => {
								uni.navigateBack()
							}, 'success', 1000)
						}
					})
				} else {
					const json = initFilter(this.ORG_ID, "", "", 0, p.pageIndex ?? 1)
					json.Parameter1 = this.model.ID;
					json.Parameter2 = this.TaskID;
					json.Parameter3 = this.ORG_ID;
					json.Parameter4 = this.state.DEALOPINION;
					getRequest(json, "/WB/WBDangerousJob/UserDisAgree").then(res => {
						if (res) {
							uni.$showMsgFunc('操作成功!', () => {
								uni.navigateBack()
							}, 'success', 1000)
						}
					})
				}
			}

		}
	}
</script>

<style>
	/* @import url("@/style/css/editTemplate.css"); */
	.background {
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		bottom: 0;
		background: #edf1fd;
		z-index: -1;
	}

	.peoplecur>>>.u-form-item__body__right {
		overflow: auto;
		white-space: nowrap;

	}

	.peoplecur>>>.u-form-item__body__right__content__slot {
		justify-content: flex-end;
	}

	.peoplewrap {
		overflow: hidden;
		white-space: nowrap;
		margin: 0px 3px;
	}

	.card {
		/* margin-bottom: 18px; */
		margin: 20px 16px 10px 16px;
		/* border: 1px solid #EBEEF5; */
		padding: 20px 30px 80px 30px;
		/* box-shadow: rgba(0, 0, 0, 0.08) 0px 0px 3px 1px; */
		background-color: #ffffff;
		border-radius: 10px;
	}

	.bottom {
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
		padding: 10px 16px;
		box-sizing: border-box;
		background: #edf1fd;
		z-index: 999;
	}

	.btn-wrap {
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
		box-sizing: border-box;
		padding: 16px;
		z-index: 1000;
		background: #fff;
		box-shadow: 0 -1px 2px 0 rgba(0, 0, 0, .05);
	}

	.buttons {
		margin-top: 10px;
		display: flex;
		justify-content: space-between;
	}

	.buttons .first-btn {
		margin-right: 20px;
	}

	.demo-ruleForm>>>.u-form-item__body__left__content__label {
		font-size: 14px;
		color: #8e8b9c;
		/* justify-content: flex-start; */
	}

	.demo-ruleForm>>>.u-form-item__body__left__content__ {
		left: -11px;
		top: 0px
	}

	.demo-ruleForm>>>.u-textarea__field {
		font-size: 14px;
	}

	.btn-wrap>>>.u-textarea__field {
		font-size: 14px;
	}

	.btn-wrap>>>.u-cell__title-text {
		font-size: 14px;
	}

	.demo-ruleForm>>>.u-cell__title-text {
		font-size: 14px;
	}

	.upload-title {
		font-size: 14px;
		color: #8e8b9c;
		line-height: 22px;
		padding: 8px 0px;
	}
</style>