<!-- 安全检查通知 确认 -->
<template>
	<view class="page-wrap">
		<view class="card">
			<uni-card margin="0" :is-shadow="true">
				<u--form labelPosition="left" labelWidth="auto" labelAlign="center" :model="model">
					<u-form-item label="安全检查名称" prop="NAME" borderBottom>
						<u--input disabled v-model="model.NAME" disabledColor="#fff" border="none" slot="right"
							inputAlign="right"></u--input>
					</u-form-item>
					<u-form-item label="安全检查编号" prop="CODE" borderBottom>
						<u--input disabled v-model="model.CODE" disabledColor="#ffffff" border="none" slot="right"
							inputAlign="right"></u--input>
					</u-form-item>
					<u-form-item label="检查类型" prop="Nav_CheckType.NAME" borderBottom>
						<u--input disabled disabledColor="#ffffff" v-model="model.Nav_CheckType.NAME" border="none"
							slot="right" inputAlign="right"></u--input>
					</u-form-item>
					<u-form-item label="检查层级" prop="Nav_CheckTypeLevel.Nav_Enums.NAME" borderBottom>
						<u--input disabled disabledColor="#ffffff" v-model="model.Nav_CheckTypeLevel.Nav_Enums.NAME"
							border="none" slot="right" inputAlign="right"></u--input>
					</u-form-item>
					<u-form-item label="检查时间" prop="CHECKTIME" borderBottom>
						<u--input disabled disabledColor="#ffffff" v-model="model.CHECKTIME" border="none" slot="right"
							inputAlign="right"></u--input>
					</u-form-item>
					<view class="label-title">检查区域</view>
					<u-form-item prop="RiskAreaNAME" borderBottom>
						<u--textarea disabled disabledColor="#ffffff" autoHeight v-model="model.RiskAreaNAME"
							placeholder="检查区域" border="surround"></u--textarea>
					</u-form-item>
					<view class="label-title">检查项目</view>
					<u-form-item prop="CheckProjectNAME" borderBottom>
						<u--textarea disabled disabledColor="#ffffff" autoHeight v-model="model.CheckProjectNAME"
							placeholder="检查项目" border="surround"></u--textarea>
					</u-form-item>
					<view class="label-title">检查项目分类</view>
					<u-form-item prop="CheckProjectCategoryNAME" borderBottom>
						<u--textarea disabled disabledColor="#ffffff" autoHeight
							v-model="model.CheckProjectCategoryNAME" placeholder="检查项目分类"
							border="surround"></u--textarea>
					</u-form-item>
					<view class="label-title">检查人员</view>
					<u-form-item prop="CheckUsers" borderBottom>
						<u--textarea disabled disabledColor="#ffffff" autoHeight v-model="model.CheckUsers"
							placeholder="检查人员" border="surround"></u--textarea>
					</u-form-item>
					<view class="upload-title">附件</view>
					<full-upload v-model="model.Nav_Files" :isShowBtn='isShowUpload' :listProp='listProp'
						:listPropVal='listPropVal'></full-upload>
				</u--form>
			</uni-card>
		</view>
		<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;padding: 10px 0px;" margin="0" padding="0" spacing="0"
								:is-shadow="false" v-for="(item, index) in model.Nav_ListSafeCheckDetail">
								<u-collapse-item name="1">
									<view slot="title" class="collapse-title">
										<!-- <view class="down">
											<uni-icons type="bottom"></uni-icons>
										</view> -->
										<view class="text-num">{{index + 1+ '. '}}</view>
										<view class="text">{{item.CHECKCONTENT}}</view>
									</view>
									<u-form-item label="检查区域" prop="Nav_CheckArea.NAME" borderBottom>
										<u--input disabled disabledColor="#fff" v-model="item.Nav_CheckArea.NAME"
											border="none" inputAlign="right"></u--input>
									</u-form-item>
									<u-form-item label="检查项目" prop="Nav_CheckProject.NAME" borderBottom>
										<u--input disabled disabledColor="#fff" v-model="item.Nav_CheckProject.NAME"
											border="none" inputAlign="right"></u--input>
									</u-form-item>

									<view class="label-title">检查内容</view>
									<u-form-item prop="CHECKCONTENT" borderBottom>
										<u--textarea disabled autoHeight v-model="item.CHECKCONTENT"
											placeholder="请输入检查内容" border="surround"></u--textarea>
									</u-form-item>
									<view class="label-title">检查依据</view>
									<u-form-item prop="CHECKPROOF" borderBottom>
										<u--textarea disabled autoHeight v-model="item.CHECKPROOF" placeholder="检查依据"
											border="surround"></u--textarea>
									</u-form-item>
									<u-form-item label="检查人员" prop="userNameHtml" borderBottom>
										<rich-text disabled disabledColor="#fff" v-html="item.userNameHtml"
											border="none" slot="right"></rich-text>
									</u-form-item>
								</u-collapse-item>
							</uni-card>
						</u-collapse>
					</u--form>
				</view>
			</view>
		</u-sticky>
		<view class="bottom-button">
			<button type="primary" v-if='isLoadOK&&tableKey==1&&!isAudit' @click="sureCheck">确认</button>

			<check-action v-if="isLoadOK && tableKey === '1' && isAudit === 'true'" :okApi="okApi"
				:refuseApi="refuseApi" :dataSource="$store.state.auditModel"></check-action>
		</view>
	</view>
</template>

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

	import {
		getNotice,
		sureCheck
	} from '../../../../services/apply/subPages/BS/notice'

	export default {
		data() {
			return {
				tableKey: '0',
				TaskID: '',
				model: {
					ID: '',
					TaskID: '',
					Nav_CheckType: {},
					Nav_CheckTypeLevel: {
						Nav_Enums: {}
					},
					Nav_Files: [],
					CheckUsers: '',
					Nav_ListSafeCheckDetail: [{
						Nav_ListCheckDetailUser: [],
						userNameHtml: '',
						Nav_CheckArea: {
							NAME: ''
						},
						Nav_CheckProject: {
							NAME: ''
						},
					}]
				},
				listProp: [],
				listPropVal: [],
				ApproveID: '',
				isAudit: false,
				okApi: '',
				refuseApi: '',
				isLoadOK: false,
				lists: [],
				currentTab: 0,
				text: '',
				isShowUpload: false
			}
		},
		onLoad(option) {
			this.model.ID = option.ID
			this.model.TaskID = option.taskID ? option.taskID : ''
			this.TaskID = this.model.TaskID
			this.tableKey = option.tableKey ? option.tableKey : '0'

			this.ApproveID = option.ApproveID
			this.isAudit = option.isAudit
			this.okApi = option.okApi
			this.refuseApi = option.refuseApi
			this.auditModel = {
				...this.$store.state.auditModel,
				TaskID: this.TaskID
			}

			if (this.isAudit || this.tableKey == 0) {
				this.isShowUpload = false
			}
			this.loadData()

		},
		methods: {
			handleReject(val) {
				// 驳回回调
				console.log('val', val)
				uni.$showMsgFunc('驳回成功', () => {
					uni.navigateBack()
				})
			},
			handlePass(val) {
				// 通过回调
				console.log('val', val)
				uni.$showMsgFunc('操作成功', () => {
					uni.navigateBack()
				})
			},
			handleTab(t) {
				this.currentTab = t
			},
			sureCheck() {
				const orgId = uni.getStorageSync('orgId')
				let json = initFilter(orgId, this.model.ID, null, null, null, this.TaskID);
				sureCheck(json).then(res => {
					uni.$showMsgFunc('操作成功!', () => {
						if (this.tableKey == null || this.tableKey == 0) {
							uni.navigateTo({
								url: 'checkPlanNoticeIndex'
							})
						} else {
							uni.navigateBack()
						}
					}, 'success', 1000)

				})
			},

			loadData() {
				const orgId = uni.getStorageSync('orgId')

				this.listProp.push("ORG_ID")
				this.listPropVal.push(orgId)

				const json = initFilter(orgId, "", "CODE", 1)
				extendRule(json, 'ID', 1, this.model.ID);
				extendInclude(json, 'Nav_CheckType');
				extendInclude(json, 'Nav_Department');
				extendInclude(json, 'Nav_CheckTypeLevel.Nav_Enums');
				extendInclude(json, 'Nav_ListCheckRiskArea.Nav_RiskArea');
				extendInclude(json, 'Nav_ListCheckProject.Nav_CheckProject');
				extendInclude(json, 'Nav_ListCheckProjectCategory.Nav_CheckProjectCategory');
				extendInclude(json, 'Nav_Files.Nav_ImgFile');
				extendInclude(json,
					"Nav_Approve.Nav_ApproveDetails.Nav_ApproveUser");
				// extendIgnoreDataRule(json)
				json.IgnoreDataRule = true
				getNotice(json).then(res => {
					// console.log('res', res)
					this.model = res
					this.model.Nav_Files = fileStructChange(this.model.Nav_Files)

					//数据组装
					let strRiskAreaNAME = ''
					if (res.Nav_ListCheckRiskArea && res.Nav_ListCheckRiskArea.length > 0) {
						for (let i = 0; i < res.Nav_ListCheckRiskArea.length; i++) {
							strRiskAreaNAME += (strRiskAreaNAME.length > 0 ? " " : "") + res.Nav_ListCheckRiskArea[
								i].Nav_RiskArea.NAME;
						}
					}

					let strCheckProjectNAME = ''
					if (res.Nav_ListCheckProject && res.Nav_ListCheckProject.length > 0) {
						for (let i = 0; i < res.Nav_ListCheckProject.length; i++) {
							strCheckProjectNAME += (strCheckProjectNAME.length > 0 ? " " : "") + res
								.Nav_ListCheckProject[i].Nav_CheckProject.NAME;
						}
					}

					let CheckProjectCategoryNAME = ''
					if (res.Nav_ListCheckProjectCategory && res.Nav_ListCheckProjectCategory.length > 0) {
						for (let i = 0; i < res.Nav_ListCheckProjectCategory.length; i++) {
							CheckProjectCategoryNAME += (CheckProjectCategoryNAME.length > 0 ? " " : "") + res
								.Nav_ListCheckProjectCategory[i].Nav_CheckProjectCategory.NAME;
						}
					}
					this.model.RiskAreaNAME = strRiskAreaNAME
					this.model.CheckProjectNAME = strCheckProjectNAME
					this.model.CheckProjectCategoryNAME = CheckProjectCategoryNAME


					// Nav_ListSafeCheckDetail: [{
					// 	Nav_ListCheckDetailUser: [],
					// userNameHtml
					let userNameHtml = ''
					let CheckUsers = ''
					let name = ''
					if (this.model.Nav_ListSafeCheckDetail != null && this.model.Nav_ListSafeCheckDetail.length >
						0) {
						for (let i = 0; i < this.model.Nav_ListSafeCheckDetail.length; i++) {
							if (this.model.Nav_ListSafeCheckDetail[i].Nav_ListCheckDetailUser != null && this.model
								.Nav_ListSafeCheckDetail[i].Nav_ListCheckDetailUser.length > 0) {
								userNameHtml = ''
								// debugger
								// this.model.Nav_ListSafeCheckDetail[i].foreach(
								// 	function(item, index) {
								// 		userNameHtml += item.Nav_User.NAME
								// 	})

								// this.model.Nav_ListSafeCheckDetail[i].foreach((item) => {
								// 	userNameHtml += item.Nav_User.NAME
								// })

								for (let j = 0; j < this.model.Nav_ListSafeCheckDetail[i].Nav_ListCheckDetailUser
									.length; j++) {

									name = this.model.Nav_ListSafeCheckDetail[i].Nav_ListCheckDetailUser[j]
										.Nav_User.NAME
									if (this.model.Nav_ListSafeCheckDetail[i].Nav_ListCheckDetailUser[j]
										.SAFECHECKSTATE >= 60) {
										userNameHtml += '<a style="color:rgba(0, 0, 0, 0.65)"> ' + (j > 0 ?
											" " : "") + name + '</a>'
									} else {
										userNameHtml += '<a style="color: red"> ' + (j > 0 ? " " : "") + name +
											'</a>'
									}
									if (CheckUsers.indexOf(name) == -1) {
										CheckUsers += (CheckUsers.length > 0 ? ' ' : '') + name
									}
								}

								this.model.Nav_ListSafeCheckDetail[i].userNameHtml = userNameHtml
							}
						}

					}
					// fileStructChange
					this.isLoadOK = true
					this.model.CheckUsers = CheckUsers
					// this.$router.go(0)
					// this.model.CheckUsersShow = '<a style="color:red">red显示</a><a style="color:blue">blue显示</a>'
				})
			},
		},
		computed: {

		}
	}
</script>
<style>
	@import url("../../../../style/css/editTemplate.css");
</style>