<template>
	<view class="page-wrap" v-bind:style="{paddingBottom:paddingBottom+'px'}">
		<view class="background"></view>
		<view class="card">
			<!-- <uni-card margin="0" :is-shadow="true"> -->
			<u--form labelPosition="left" labelWidth="auto" labelAlign="center" :model="model" class="demo-ruleForm">
				<view style="position: relative;">
					<view style="position: absolute;left: -10px;color: #3d4b70;top: -3px;">*</view>
				</view>

				<view style="font-size: 15px; font-weight: bold;color: #3d4b70;margin-bottom: 10px;">基本信息</view>
				<u-form-item label="点检时间" prop="RECORD_DATE" borderBottom>
					<u--input disabledColor="#fff" v-model="model.RECORD_DATE" border="none" inputAlign="right" fontSize="14px"></u--input>

				</u-form-item>

				<!-- <u-textarea v-model="model.NavUsersName" disabled autoHeight></u-textarea> -->
				<u-form-item label="设备名称" prop="Nav_DeviceBase.NAME" borderBottom>
					<u--input v-if="model.Nav_DeviceBase" disabled disabledColor="#ffffff" v-model="model.Nav_DeviceBase.NAME" border="none" inputAlign="right" fontSize="14px"></u--input>
				</u-form-item>
				<u-form-item label="规格" prop="Nav_Project.NAME" borderBottom>
					<u--input disabled disabledColor="#ffffff" v-model="model.SPEC" border="none" inputAlign="right" fontSize="14px"></u--input>
				</u-form-item>
				<u-form-item label="设备编号" prop="Nav_Project.NAME" borderBottom>
					<u--input disabled disabledColor="#ffffff" v-model="model.MACHINE_CODE" border="none" inputAlign="right" fontSize="14px"></u--input>
				</u-form-item>
				<u-form-item label="设备位置" prop="Nav_Project.NAME" borderBottom>
					<u--input disabled disabledColor="#ffffff" v-model="model.POSITION_NAME" border="none" inputAlign="right" fontSize="14px"></u--input>
				</u-form-item>
				<u-form-item label="点检人员:" prop="Nav_Users">


				</u-form-item>
				<rich-text autoHeight v-html="model.NavUsersName" border="none" disabled class="richtext"></rich-text>
			</u--form>
			<u--form labelPosition="left" labelWidth="auto" labelAlign="center" errorType="border-bottom" ref="sForm" class="sub-form" style="margin-top: 10px;">
				<view style="position: relative;">
					<view style="position: absolute;left: -10px;color: #3d4b70;top: -3px;">*</view>
				</view>

				<view style="font-size: 15px; font-weight: bold;color: #3d4b70;margin-bottom: 10px;">点检信息</view>

				<uni-collapse :border="false" accordion>
					<view v-for="(item, index) in model.Nav_ListDetail.filter(i => !i.IS_DELETED)" :key="index">
						<uni-collapse-item title-border="none" :border="false">
							<template v-slot:title>
								<view class="uni-collapse-item__title-box">
									<view class="uni-collapse-item__title-text">
										{{item.ITEM1?index+1+'.'+item.ITEM1:index+1+'.'}}
									</view>
								</view>
							</template>
							<view class="content">
								<u-form-item label="点检部位" prop="POSITION" borderBottom>
									<u--input disabled disabledColor="#ffffff" v-model="item.ITEM1" border="none" inputAlign="right" fontSize="14px" placeholder="请输入点检部位">
									</u--input>
								</u-form-item>
								<u-form-item label="点检内容" prop="POSITION" borderBottom>
									<u--input disabled disabledColor="#ffffff" v-model="item.ITEM2" border="none" inputAlign="right" fontSize="14px" placeholder="请输入点检内容">
									</u--input>
								</u-form-item>
								<u-form-item label="点检标准" prop="POSITION" borderBottom>
									<u--input disabled disabledColor="#ffffff" v-model="item.ITEM3" border="none" inputAlign="right" fontSize="14px" placeholder="请输入点检标准">
									</u--input>
								</u-form-item>
								<u-form-item label="点检结论" prop="Product_Unit" borderBottom>
									<u--input v-model="item.CHECK_VALUEShow" disabled disabledColor="#ffffff" border="none" inputAlign="right" fontSize="14px">
									</u--input>

								</u-form-item>
								<u-form-item label="问题描述" prop="POSITION" borderBottom>
									<u--input disabled disabledColor="#ffffff" v-model="item.DESCRIPTION" border="none" inputAlign="right" fontSize="14px">
									</u--input>
								</u-form-item>
								<view class="upload-title">附件</view>
								<full-upload v-model="item.Nav_DetailFiles" :isShowBtn='false' :listProp='listPropUpload' :listPropVal='listPropValUpload'></full-upload>


							</view>


						</uni-collapse-item>
					</view>
				</uni-collapse>
			</u--form>
			<check-action v-if="isLoadOK&&tableKey==1&&isAudit" :okApi="okApi" :refuseApi="refuseApi" :dataSource="auditModel"></check-action>
		</view>
		<view class="bottom-button" style="padding: 10px 16px;" v-if="isLoadOK&&tableKey==1&&this.isSign">
			<u-button type="primary" @click="onTableBtnAgree" color="#3d4b70">确认</u-button>
		</view>
		<!-- <view class="bottom-button" style="padding: 10px 16px;" v-if="isLoadOK&&(tableKey==1||tableKey==4)&&this.isSign">
			<u-button type="primary" @click="onTableBtnAgree" color="#3d4b70">审阅</u-button>
		</view> -->

	</view>
</template>

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

	import {
		DeviceCheckGet,
		DMSign
	} from '../../../../services/apply/subPages/DM/dm';
	import '../../../../utils/showMsg.js'
	import color from '../../../../uni_modules/uview-ui/libs/config/color'
	import config from '../../../../config/common'
	import {
		getEnum
	} from '../../../../services/common';

	export default {
		data() {
			return {
				model: {
					Nav_Department: {
						NAME: ''
					},
					Nav_User: {
						NAME: ''
					},
					Nav_ListDetail: [{
						Nav_Device: {
							NAME: ''
						},
						Nav_Category: {
							NAME: ''
						},
						Nav_Type: {
							NAME: ''
						},
					}]

				},
				listPropUpload: ['PARENT_ID'],
				listPropValUpload: [],
				listResult: [],
				paddingBottom: '150',
				TaskID: "",
				tableKey: '0',
				isLoadOK: false,
				isSign: true,
				isAudit: true,
				DEALOPINION: "",
				ORG_ID: uni.getStorageSync('orgId'),
				listISORNOT: [], //是否涉及
				listISORNOTText: [],
			}
		},
		onLoad(option) {
			this.ID = option.ID;
			this.TaskID = option.taskID;
			this.tableKey = option.tableKey ? option.tableKey : '0'
			this.okApi = option.okApi
			this.refuseApi = option.refuseApi
			this.auditModel = {
				...this.$store.state.auditModel,
				TaskID: option.taskID ? option.taskID : ''
			}
			this.getConclusion()
		},
		methods: {
			getConclusion() {
				var dataParm = {
					'name': "CheckResult"
				}
				getEnum(dataParm).then(res => {
					this.listResult = res
					this.listResult.forEach(e => {
						e.name = e.NAME
						e.code = e.ID
					})
					this.loadData()
				})
			},
			loadData() {
				const json = initFilter(this.ORG_ID)
				extendRule(json, 'ID', 1, this.ID);
				extendIgnoreDataRule(json)
				extendInclude(json, 'Nav_DeviceBase')
				extendInclude(json, 'Nav_ListDetail')
				extendInclude(json, 'Nav_ListDetail.Nav_DetailFiles.Nav_ImgFile.Nav_File')
				extendInclude(json, 'Nav_Files.Nav_ImgFile');
				extendInclude(json, 'Nav_ListUser.Nav_User')
				DeviceCheckGet(json).then(res => {
					this.model = res
					this.model.TIME = uni.$u.timeFormat(this.model.TIME,
						'yyyy-mm-dd')
					let strUserName = ''
					if (res.Nav_ListUser && res.Nav_ListUser.length > 0) {
						for (let i = 0; i < res.Nav_ListUser.length; i++) {
							if (!res.Nav_ListUser[i].ISCHECK) {
								strUserName += (strUserName.length > 0 ? " " : "") +
									"<view style='color:#E35D58;background-color:rgba(227,93,88,0.2);padding:5px;line-height:20px;white-space:nowrap;'>" +
									res.Nav_ListUser[i].Nav_User.NAME + "</view>";
							} else {
								strUserName += (strUserName.length > 0 ? " " : "") +
									"<text style='padding:5px;line-height:20px;white-space:nowrap;color:#303133'>" +
									res.Nav_ListUser[i].Nav_User.NAME + "</text>";
							}

						}
					}
					this.model.NavUsersName = strUserName;
					if (res.Nav_ListDetail && res.Nav_ListDetail.length > 0) {
						res.Nav_ListDetail.map(item => {
							item.CHECK_VALUEShow = this.listResult.find(item1 => item1.code === item.CHECK_VALUE).name
						})
					}
					// let NavUsersName = ''
					// if (this.model.Nav_ListUser && this.model.Nav_ListUser.length > 0) {
					// 	this.model.Nav_ListUser.map(item => {
					// 		if (item.Nav_User.NAME !== null) {
					// 			NavUsersName += item.Nav_User.NAME + ' ';
					// 		}
					// 	})
					// }
					// this.model.NavUsersName = NavUsersName
					if (res.STATUS == 20) {
						this.isAudit = true
						this.isSign = false
					} else if (res.STATUS == 10) {
						this.isSign = true
						this.isAudit = false
					}
					this.isLoadOK = true
				})
			},
			onTableBtnAgree() {
				const json = initFilter(this.ORG_ID, this.ID, null, null, null, this.TaskID)
				extendRule(json, 'ID', 1, this.ID);
				extendRule(json, 'Parameter1', 1, this.TaskID)
				extendInclude(json, 'Nav_Files.Nav_ImgFile');
				DMSign(json).then(res => {
					if (res) {
						uni.$showMsgFunc('操作成功!', () => {
							uni.navigateBack()
						}, 'success', 1000)
					}
				})
			},

		}
	}
</script>

<style>
	/* @import url("../../../../style/css/editTemplate.css"); */
	@import url("../../../../style/css/newTemplate.css");
</style>