<template>
	<div class="checkResult">
		<headNav :title="'检查总结'"></headNav>

		<!-- 检查结果 -->
		<div class="danger">
			<div class="headTip FontColorInfo">检查结果</div>
			<div class="checkResult">{{ resultData }}</div>
		</div>

		<!-- 检查判断 -->
		<div class="checkJudge" v-if="!hasRes">
			<div class="headTip FontColorInfo">检查判断</div>

			<div class="radio">
				<div class="radioItem itemFirst">
					<van-checkbox
						:disabled="topDisabled"
						icon-size="0.4rem"
						v-model="checkCheck"
						shape="square"
						@change="firstCheckChange"
					>
						检查情况良好，未发现异常隐患情况
					</van-checkbox>
				</div>
				<van-checkbox-group v-model="checkCheckGroup" :disabled="checkDisable">
					<div class="radioItem">
						<van-checkbox icon-size="0.4rem" name="2" shape="square">
							部分检查情况异常，责令立即改正
						</van-checkbox>
						<div class="mt10 ml20 fz12 FontColorInfo">《责令立即改正通知》</div>
					</div>
					<div class="radioItem">
						<van-checkbox icon-size="0.4rem" name="3" shape="square">
							部分检查情况异常，责令限期改正
						</van-checkbox>
						<div class="mt10 ml20 fz12 FontColorInfo">《责令限期改正通知》</div>
					</div>
				</van-checkbox-group>
			</div>

			<div class="btn" v-if="!hasRes">
				<van-button type="info" @click="sure">确定</van-button>
			</div>
		</div>

		<!-- 遮罩层 -->
		<v-mask :showOverLay="showOverLay" :tipMsg="tipMsg"></v-mask>
	</div>
</template>

<script>
import headNav from '@/components/headNav.vue';
import mask_overLay from '@/components/overLay_xy.vue';
import { get, post, put } from '@/utils/http.js';

export default {
	name: 'checkResult',
	components: {
		headNav,
		'v-mask': mask_overLay
	},
	data() {
		return {
			resultData: '',
			checkCheck: '',
			checkCheckGroup: [],
			checkDisable: false,
			topDisabled: false,
			showOverLay: false,
			tipMsg: '加载中',
			hasRes: false
		};
	},
	mounted() {
		this.init();
	},
	methods: {
		// 初始化
		init() {
			this.getPageListApi();
		},

		// 获取列表 信息
		async getPageListApi() {
			this.tipMsg = '加载中';
			this.showOverLay = true;
			const res = await this.getConditionApi();
			this.showOverLay = false;
			if (res.success === true) {
				this.resultData = res.data[0].checkCont;
			} else {
				this.showOverLay = false;
				this.$toast.fail('获取数据失败');
			}
		},

		async getConditionApi() {
			return get('/cdsupervisionCheckRecord/listByCondition', {
				taskId: this.$route.params.taskId
			});
		},

		backPage() {
			this.$router.go(-1);
		},

		// 跳转检查详情页面
		gotoDangerDetail(item) {
			this.$router.push(`/dangerDetail/${item.id}`);
		},

		sure() {
			if (!this.checkCheck && this.checkCheckGroup.length == 0) {
				this.$toast.fail('请判断检查结果');
				return;
			}

			let judge = '';

			if (this.checkCheck) judge = 1;
			else judge = this.checkCheckGroup.join(',');

			let submitData = {
				checkJudge: judge.toString(),
				id: this.$route.params.ID
			};

			this.showOverLay = true;
			this.tipMsg = '提交中';

			if (this.checkCheck) {
				put('/cdsupervisionOthertask/edit', {
					id: this.$route.params.ID,
					excuteStatus: '2'
				})
				.then(res => {
					if (res.success) {
						this.$router.push(`/`);
					} else {
						this.$toast.fail(`${res.msg}`);
					}
				})
				.catch(err => {
					this.$toast.fail(err);
				});
			} else {
				post('/cdsupervisionAmend/otherTaskEditJudge', {
					taskId: this.$route.params.taskId,
					checkJudge: judge
				}).then(res => {
					if (res) {
						this.$router.push(
							`/checkResultDetail/${this.$route.params.ID}/${this.$route.params.taskId}/1`
						);
					} else {
						this.$toast.fail(res.msg);
					}
				});
			}
		},

		// 第一个checkBox改变
		firstCheckChange() {
			if (this.checkCheck == true) {
				this.checkDisable = true;
				this.checkCheckGroup = [];
			} else {
				this.checkDisable = false;
			}
		}
	}
};
</script>

<style lang="scss" scoped>
.checkResult {
	font-size: 14px;

	.headTip {
		margin-bottom: 10px;
		padding: 0 15px;
	}

	.danger {
		margin-top: 57px;
		padding: 0 10px;
	}

	.checkResult {
		padding: 10px 15px;
		background-color: #fff;
		height: 200px;
		color: #434343;
	}

	.checkJudge {
		margin-top: 10px;
		padding: 0 10px;

		.radio {
			.radioItem {
				margin: 0px 0;
				padding: 10px 15px;
				background-color: #fff;
				border-bottom: 1px solid #ddd;
			}

			.radioItem.itemFirst {
				margin-bottom: 15px;
			}
		}
	}

	.btn {
		margin-top: 30px;
		display: flex;
		justify-content: space-around;

		button {
			flex: 1;
			margin: 0 20px;
		}
	}
}
</style>

<style lang="scss">
.checkResult {
	.van-cell {
		display: flex;
		align-items: center;
		font-size: 13px;
		color: #5c5c5e;

		&::after {
			border-bottom: 1px solid #888888;
		}
	}

	.van-radio__label {
		color: #767676;
	}

	.van-button.van-button--default.van-button--normal {
		background-color: #d7d7d7;
		color: #fff;
	}

	.van-cell::after {
		border: none;
	}
}
</style>
