<template>
	<view class="page-wrap" v-bind:style="{paddingBottom:paddingBottom+'px'}">
		<uni-card margin="0" :is-shadow="true">
			<u--form labelPosition="left" labelWidth="auto" labelAlign="center" :model="model">
				<u-form-item label="记录日期：" prop="RECORD_DATE" borderBottom>
					<u--input v-model="model.RECORD_DATE" border="none" slot="right" inputAlign="right" disabled
						disabledColor="#ffffff"></u--input>
				</u-form-item>
				<u-form-item label="班次：" prop="Nav_Class.NAME" borderBottom>
					<u--input v-if="model.Nav_Class" v-model="model.Nav_Class.NAME" border="none" slot="right" inputAlign="right" disabled
						disabledColor="#ffffff"></u--input>
				</u-form-item>
				<u-form-item label="岗位：" prop="Nav_DepartmentPost.NAME" borderBottom>
					<u--input v-model="model.Nav_DepartmentPost.NAME" border="none" slot="right" inputAlign="right"
						disabled disabledColor="#ffffff"></u--input>
				</u-form-item>
				<u-form-item label="当班人员：" prop="UserNames" borderBottom>
					<u--input slot="right" v-html="model.UserNames" border="none" inputAlign="right" disabled
						disabledColor="#ffffff"></u--input>
				</u-form-item>

				<u-form-item label="本班运行情况：" prop="CURRENT_CLASS_STATUS" borderBottom>
					<u--input autoHeight v-html="model.current1" border="none" inputAlign="right" disabled
						disabledColor="#ffffff" slot="right"></u--input>
				</u-form-item>

				<u-form-item label="存在问题：" prop="CURRENT_CLASS_QUESTION" v-if="model.CURRENT_CLASS_STATUS==1">
				</u-form-item>
				<u--textarea autoHeight v-model="model.current2" border="none" inputAlign="right"
					v-if="model.CURRENT_CLASS_STATUS==1" disabled disabledColor="#ffffff"></u--textarea>
				<u-form-item label="处理情况：" prop="CURRENT_CLASS_MEASURE" v-if="model.CURRENT_CLASS_STATUS==1" disabled
					disabledColor="#ffffff">
				</u-form-item>
				<u--textarea autoHeight v-model="model.current3" border="none" inputAlign="right"
					v-if="model.CURRENT_CLASS_STATUS==1" disabled disabledColor="#ffffff"></u--textarea>
				<u-form-item label="设备运行状况：" prop="DEVICE_STATUS" borderBottom>
					<u--input autoHeight v-html="model.device1" border="none" inputAlign="right" disabled
						disabledColor="#ffffff" slot="right"></u--input>
				</u-form-item>

				<u-form-item label="存在问题：" prop="DEVICE_QUESTION" borderBottom v-if="model.DEVICE_STATUS==1">
				</u-form-item>
				<u--textarea autoHeight v-model="model.device2" border="none" inputAlign="right"
					v-if="model.DEVICE_STATUS==1" disabled disabledColor="#ffffff"></u--textarea>
				<u-form-item label="处理情况：" prop="DEVICE_MEASURE" borderBottom v-if="model.DEVICE_STATUS==1">
				</u-form-item>
				<u--textarea autoHeight v-model="model.device3" border="none" inputAlign="right"
					v-if="model.DEVICE_STATUS==1" disabled disabledColor="#ffffff"></u--textarea>
				<u-form-item label="现场环境情况：" prop="ENVIRONMENT_STATUS" borderBottom>
					<u--input autoHeight v-html="model.environment1" border="none" inputAlign="right" disabled
						disabledColor="#ffffff" slot="right"></u--input>
				</u-form-item>

				<u-form-item label="存在问题：" prop="ENVIRONMENT_QUESTION" borderBottom v-if="model.ENVIRONMENT_STATUS==1">
				</u-form-item>
				<u--textarea autoHeight v-model="model.environment2" border="none" inputAlign="right"
					v-if="model.ENVIRONMENT_STATUS==1" disabled disabledColor="#ffffff"></u--textarea>
				<u-form-item label="处理情况：" prop="ENVIRONMENT_MEASURE" borderBottom v-if="model.ENVIRONMENT_STATUS==1">
				</u-form-item>
				<u--textarea autoHeight v-model="model.environment3" border="none" inputAlign="right"
					v-if="model.ENVIRONMENT_STATUS==1" disabled disabledColor="#ffffff"></u--textarea>
				<u-form-item label="劳保用品使用情况：" prop="SUPPLIES_STATUS" borderBottom>
					<u--input autoHeight v-html="model.supplies1" border="none" inputAlign="right" disabled
						disabledColor="#ffffff" slot="right"></u--input>
				</u-form-item>

				<u-form-item label="存在问题：" prop="SUPPLIES_QUESTION" borderBottom v-if="model.SUPPLIES_STATUS==1">
				</u-form-item>
				<u--textarea autoHeight v-model="model.supplies2" border="none" inputAlign="right"
					v-if="model.SUPPLIES_STATUS==1" disabled></u--textarea>
				<u-form-item label="处理情况：" prop="SUPPLIES_MEASURE" borderBottom v-if="model.SUPPLIES_STATUS==1">
				</u-form-item>
				<u--textarea autoHeight v-model="model.supplies3" border="none" inputAlign="right"
					v-if="model.SUPPLIES_STATUS==1" disabled disabledColor="#ffffff"></u--textarea>
				<u-form-item label="设备工具材料使用存放情况：" prop="DEVICE_STORAGE" borderBottom>
				</u-form-item>
				<u--textarea v-model="model.DEVICE_STORAGE" border="none" inputAlign="right" disabled
					disabledColor="#ffffff"></u--textarea>
				<view class="upload-title">附件</view>
				<full-upload v-model="model.Nav_Files" :listProp='listPropUpload'
					:listPropVal='listPropValUpload' :isShowBtn="false"></full-upload>
			</u--form>
		</uni-card>
		<uni-card class="btn-wrap" :is-shadow="true" 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" class="btn first-btn" @click="onChargeUserAgree(1)"
							text="同意"></u-button>
						<u-button type="warning" @click="onChargeUserAgree(2)" text="驳回"></u-button>
					</view>
				</view>
			</u--form>
		</uni-card>
		<button type="primary" class="bottom" v-if="isLoadOK&&tableKey==1&&this.isSign"
			@click="onTableBtnAgree">签到</button>
	</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: {
					Nav_Class: "",
					Nav_DepartmentPost: ""
				},
				listPropUpload: ['CURRENT_CLASS_RECORD_ID'],
				listPropValUpload: [],
				paddingBottom: '170',
				TaskID: "",
				tableKey: '0',
				isLoadOK: false,
				isSign: true,
				isAudit: true,
				DEALOPINION: "",

			}
		},
		onLoad(option) {
			this.model.ID = option.ID;
			this.TaskID = option.taskID;
			this.tableKey = option.tableKey ? option.tableKey : '0'
			this.loadData()
		},
		methods: {
			loadData() {
				const orgId = uni.getStorageSync('orgId')
				const json = initFilter(orgId, "", "CODE", 1)
				extendRule(json, 'ID', 1, this.model.ID);
				extendInclude(json, 'Nav_Users.Nav_User.Nav_UserSignFiles.Nav_ImgFile.Nav_File');
				extendInclude(json, 'Nav_ChargeUser.Nav_UserSignFiles.Nav_ImgFile.Nav_File');
				extendInclude(json, 'Nav_Class');
				extendInclude(json, 'Nav_Files.Nav_ImgFile.Nav_File');
				extendInclude(json, 'Nav_DepartmentPost');
				getRequest(json,"/FO/CurrentClassRecord/Get").then(res => {
					this.model = res
					this.model.current1 = this.model.SHIFT_STATUS > 0 ? this.model.CURRENT_CLASS_STATUS == 0 ?
						'正常' : "<text style='color:red'>不正常</text>" : null;
					this.model.current2 = this.model.SHIFT_STATUS > 0 ? this.model.CURRENT_CLASS_STATUS == 0 ?
						'无' : this.model.CURRENT_CLASS_QUESTION : null;
					this.model.current3 = this.model.SHIFT_STATUS > 0 ? this.model.CURRENT_CLASS_STATUS == 0 ?
						'无' : this.model.CURRENT_CLASS_MEASURE : null;
					this.model.device1 = this.model.SHIFT_STATUS > 0 ? this.model.DEVICE_STATUS == 0 ? '正常' :
						"<text style='color:red'>不正常</text>" : null;
					this.model.device2 = this.model.SHIFT_STATUS > 0 ? this.model.DEVICE_STATUS == 0 ? '无' : this
						.model
						.DEVICE_QUESTION : null;
					this.model.device3 = this.model.SHIFT_STATUS > 0 ? this.model.DEVICE_STATUS == 0 ? '无' : this
						.model
						.DEVICE_MEASURE : null;
					this.model.environment1 = this.model.SHIFT_STATUS > 0 ? this.model.ENVIRONMENT_STATUS == 0 ?
						'正常' : "<text style='color:red'>不正常</text>" : null;
					this.model.environment2 = this.model.SHIFT_STATUS > 0 ? this.model.ENVIRONMENT_STATUS == 0 ?
						'无' : this.model.ENVIRONMENT_QUESTION : null;
					this.model.environment3 = this.model.SHIFT_STATUS > 0 ? this.model.ENVIRONMENT_STATUS == 0 ?
						'无' : this.model.ENVIRONMENT_MEASURE : null;
					this.model.supplies1 = this.model.SHIFT_STATUS > 0 ? this.model.SUPPLIES_STATUS == 0 ? '正常' :
						"<text style='color:red'>不正常</text>" : null;
					this.model.supplies2 = this.model.SHIFT_STATUS > 0 ? this.model.SUPPLIES_STATUS == 0 ? '无' :
						this.model.SUPPLIES_QUESTION : null;
					this.model.supplies3 = this.model.SHIFT_STATUS > 0 ? this.model.SUPPLIES_STATUS == 0 ? '无' :
						this.model.SUPPLIES_MEASURE : null;
					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 += (strUserName.length > 0 ? " " : "") + "&nbsp;<text style='color:red'>" +
									res.Nav_Users[i].Nav_User.NAME + "</text>";
							} else {
								strUserName += (strUserName.length > 0 ? " " : "") + res.Nav_Users[
									i].Nav_User.NAME;
							}

						}
					}
					this.model.UserNames = strUserName;
					if (this.model.SHIFT_STATUS == 2) {
						this.isSign = true;
						this.isAudit = false;
					} else if (this.model.SHIFT_STATUS == 3) {
						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)
					}
				})
			},
			onChargeUserAgree(agree) {
				let json = {};
				json.ID = this.model.ID;
				json.TaskID = this.TaskID;
				json.CODE = agree;
				json.AUDIT_OPINION = this.DEALOPINION;
				json.DEPARTMENT_ID = this.model.DEPARTMENT_ID;
				json.CLASS_ID = this.model.CLASS_ID;
				getRequest(json,"/FO/FOCurrentClassRecord/ChargeUserAgree").then(res => {
					if (res) {
						uni.$showMsgFunc('操作成功!', () => {
							uni.navigateBack()
						}, 'success', 1000)
					}
				})
			}
		}
	}
</script>

<style>
	@import url("@/style/css/editTemplate.css");
	.bottom {
		position: fixed;
		bottom: 0;
		display: block;
		margin-left: auto;
		margin-right: auto;
		padding-left: 14px;
		padding-right: 14px;
		box-sizing: border-box;
		font-size: 18px;
		text-align: center;
		text-decoration: none;
		line-height: 2.55555556;
		border-radius: 5px;
		-webkit-tap-highlight-color: transparent;
		overflow: hidden;
		color: #000;
		background-color: #f8f8f8;
		cursor: pointer;
		color: #fff;
		background-color: #007aff;
		width: 92%;
	}

	.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;
	}
</style>