<template>
	<view class="addIssue">
		<view class="fixedheader">
			<headers :showBack="true" :themeType="true">
				<view class="headerName">
					风险点清单
				</view>
			</headers>
		</view>
		<view class="content" :style="{paddingTop: mobileTopHeight + 44 + 'px'}">
			<view class="content_main">
				<view class="box-header">
					<view @click.stop>
						<view>
							{{riskListPointInfo.riskPointName}}
						</view>
					</view>
					<view class="riskcolor riskcolor_table" :class="{
					  riskcolor1: riskListPointInfo.riskLevel == 1,
					  riskcolor2: riskListPointInfo.riskLevel == 2,
					  riskcolor3: riskListPointInfo.riskLevel == 3,
					  riskcolor4: riskListPointInfo.riskLevel == 4,
					}">{{riskLevelUp(riskListPointInfo.riskLevel)}}</view>
				</view>
				<view class="box-item">
					<view>风险描述:</view>
					<view>
						{{riskListPointInfo.riskDescription ? riskListPointInfo.riskDescription : '--'}}
					</view>
				</view>
				<view class="box-item">
					<view>潜在事故类型:</view>
					<view>
						{{accidentTypeUp(riskListPointInfo.accidentTypeId)}}
					</view>
				</view>
				<view class="box-item">
					<view>风险评价方法:</view>
					<view>
						{{
						  setNameUp(
							riskListPointInfo.riskAssessmentCalculator,
							riskAssessmentCalculatorList,
							"id",
							"name"
						  )
						}}
					</view>
				</view>
				<view class="box-item">
					<view>风险值:</view>
					<view>
						{{riskListPointInfo.riskVal ? riskListPointInfo.riskVal : '--'}}
					</view>
				</view>
				<view class="box-item">
					<view>有效时间:</view>
					<view v-if="riskListPointInfo.effectiveTimeBegin">{{ riskListPointInfo.effectiveTimeBegin }} 至
						{{ riskListPointInfo.effectiveTimeEnd }}
					</view>
					<view v-else class="color-error">
						未设置有效时间
					</view>
				</view>
				<view class="box-item">
					<view>具体责任区域:</view>
					<view v-if="riskListPointInfo.specificResponsibilityAreaNames">
						{{ riskListPointInfo.specificResponsibilityAreaNames }}
					</view>
					<view v-else class="color-error">
						未设置具体责任区域
					</view>
				</view>
				<view class="box-item">
					<view>管控责任人:</view>
					<view>{{riskListPointInfo.controlWorkerNames ? riskListPointInfo.controlWorkerNames : '--'}}
					</view>
				</view>
				<view class="box-item">
					<view>管控情况:</view>
					<view @click="onNavigateToDetail(4)" v-if="riskListPointInfo.workable == 1">
						已落实(<text class="color-49">查看落实情况</text>)
					</view>
					<view v-else>--</view>
				</view>
				<view class="box-item">
					<view>辨识时间:</view>
					<view>{{riskListPointInfo.identificationTime ? riskListPointInfo.identificationTime : '--'}}</view>
				</view>
				<view class="box-item">
					<view>排查责任人:</view>
					<view>{{riskListPointInfo.checkWorkerNames ? riskListPointInfo.checkWorkerNames : '--'}}</view>
				</view>
				<view class="box-content1">
					<view>管控措施:</view>
					<view>
						<view>
							工程措施：{{
							  riskListPointInfo.engineeringMeasure ? riskListPointInfo.engineeringMeasure : "--"
							}}
						</view>
						<view>
							管理措施：{{
							  riskListPointInfo.managementMeasure ? riskListPointInfo.managementMeasure : "--"
							}}
						</view>
						<view>
							个体防护：{{
							  riskListPointInfo.personalProtection ? riskListPointInfo.personalProtection : "--"
							}}
						</view>
						<view>
							应急措施：{{
							  riskListPointInfo.emergencyMeasure ? riskListPointInfo.emergencyMeasure : "--"
							}}
						</view>
						<view>
							教育措施：{{
							  riskListPointInfo.educationalMeasure ? riskListPointInfo.educationalMeasure : "--"
							}}
						</view>
					</view>
				</view>
				<view class="box-item">
					<view>备注:</view>
					<view>{{riskListPointInfo.remark ? riskListPointInfo.remark : '--'}}</view>
				</view>
			</view>
			<view class="confrim-bottom">
				<view class="confrim-btn">
					<view class="btn-primary" @click="copyBtn">复制</view>
					<!-- <view @click="onNavigateToDetail(1)" class="btn-primary">关联业务</view>
					<view @click="onNavigateToDetail(2)" class="btn-primary">辨识危险源</view> -->
					<view @click="onNavigateToDetail(3)" class="btn-primary">设置</view>
					<view @click="onDelete">删除</view>
				</view>
			</view>
		</view>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				mobileTopHeight: 0,
				projectDetail: {},
				riskListPointId: "",
				riskListPointInfo: {},
				riskLevelList: [{
						id: 1,
						name: "重大风险",
					},
					{
						id: 2,
						name: "较大风险",
					},
					{
						id: 3,
						name: "一般风险",
					},
					{
						id: 4,
						name: "低风险",
					},
				],
				riskAssessmentCalculatorList: [{
						id: 1,
						name: "LECD",
					},
					{
						id: 2,
						name: "直接判定法",
					},
					{
						id: 3,
						name: "LCD",
					},
					{
						id: 4,
						name: "LSR",
					},
				],
				accidentTypeList: [],
			}
		},
		onLoad(opts) {
			this.projectDetail = JSON.parse(uni.getStorageSync('projectDetail'));
			this.riskListPointId = opts.id;
			this.getDicProjectTypeList();
		},
		onShow() {
			this.getRiskListPointQueryByIdFn()
		},
		mounted() {
			var that = this
			uni.getSystemInfo({
				success(res) {
					that.mobileTopHeight = res.statusBarHeight ? res.statusBarHeight : 0;
					uni.setStorageSync('systemInfo', res)
					console.log(res)
				}
			})
		},
		methods: {
			// 关联业务
			onNavigateToDetail(type) {
				if (type == 1) {
					uni.navigateTo({
						url: `./relatedBusiness?id=${this.riskListPointId}`
					})
				} else if (type == 2) {
					uni.navigateTo({
						url: `./sourceDangerIdentify?libraryId=${this.riskListPointInfo.riskListLibraryId}&id=${this.riskListPointId}`
					})
				} else if (type == 3) {
					uni.navigateTo({
						url: `./sourceDangerSet?id=${this.riskListPointId}`
					})
				} else if (type == 4) {
					uni.navigateTo({
						url: `./implementationStatusList?id=${this.riskListPointId}`
					})
				}
			},
			// 返回上一级
			onNavigateBack() {
				uni.navigateBack({
					delta: 0
				})
			},
			// 复制
			copyBtn() {
				let that = this;
				let data = {
					...this.riskListPointInfo,
					createTime: this.$dayjs().format("YYYY-MM-DD HH:mm:ss"),
					identificationTime: this.$dayjs().format("YYYY-MM-DD HH:mm:ss"),
				};
				this.sendRequest({
					url: 'xmgl/riskListSource/copy',
					method: 'POST',
					data: data,
					success: res => {
						if (res.code == 200) {
							this.showToast('复制成功！', 'success');
							setTimeout(() => {
								uni.$emit('updateData');
								that.onNavigateBack();
							}, 500)
						}
					}
				})
			},
			// 删除
			onDelete() {
				let that = this;
				let data = {
					id: this.riskListPointInfo.id
				};

				uni.showModal({
					title: '提示',
					content: '确定删除该作业吗?',
					success: function(res) {
						if (res.confirm) {
							that.sendRequest({
								url: 'xmgl/riskListSource/delete',
								method: 'POST',
								data: data,
								success: res => {
									if (res.code == 200) {
										that.showToast('删除成功！', 'success');
										setTimeout(() => {
											uni.$emit('updateData');
											that.onNavigateBack();
										}, 500)
									}
								}
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});

			},
			showToast(title, type) {
				this.$refs.uToast.show({
					title: title,
					type: type,
				})
			},
			// 通过id查询管控清单信息
			getRiskListPointQueryByIdFn() {
				let that = this;
				let data = {
					projectSn: this.projectDetail.projectSn,
					id: this.riskListPointId,
				};
				this.sendRequest({
					url: 'xmgl/riskListSource/queryById',
					method: 'GET',
					data: data,
					success: res => {
						if (res.code == 200) {
							that.riskListPointInfo = res.result;
						}
					}
				})
			},
			// 获取字典工程类别列表
			getDicProjectTypeList() {
				let that = this;
				let data = {
					projectSn: this.projectDetail.projectSn,
				};
				this.sendRequest({
					url: 'xmgl/riskListPotentialAccidentType/list',
					method: 'GET',
					data: data,
					success: res => {
						if (res.code == 200) {
							this.accidentTypeList = res.result.sort(
								(a, b) => Date.parse(a.createTime) - Date.parse(b.createTime)
							);
						}
					}
				})
			},
		},
		computed: {
			setNameUp() {
				return (rowId, dataList, id, name) => {
					const find = dataList.find((item) => item[id] === rowId);
					return find ? find[name] : "--";
				};
			},
			riskLevelUp() {
				return (riskLevel) => {
					const find = this.riskLevelList.find((item) => riskLevel === item.id);
					return find ? find.name : "--";
				};
			},
			accidentTypeUp() {
				return (accidentTypeId) => {
					const find = this.accidentTypeList.find((item) => accidentTypeId === item.id);
					return find ? find.type : "--";
				};
			},
		}
	}
</script>

<style scoped lang="scss">
	.riskcolor {
		color: white !important;
		padding: 8rpx 12rpx;
		width: 140rpx;
		margin-left: 10rpx;
		flex: inherit !important;
		text-align: center;
	}

	.riskcolor_table {
		padding: 2rpx 12rpx;
		display: inline-block;
	}

	.riskcolor1 {
		background-color: #eb4047;
	}

	.riskcolor2 {
		background-color: #ffbf00;
	}

	.riskcolor3 {
		background-color: #ffff00;
	}

	.riskcolor4 {
		background-color: #006fbf;
	}

	.content {
		.content_main {


			padding: 30rpx 28rpx;
			background-color: white;
			border-radius: 18rpx;
			position: relative;

			.box-bottom {
				width: 100%;
				padding: 0 26rpx;
				height: 112rpx;
				display: flex;
				align-items: center;
				background-color: #FFFFFF;
				box-shadow: 0rpx -8rpx 8rpx 0rpx rgba(0, 0, 0, 0.05);
				border-radius: 0 0 18rpx 18rpx;
				justify-content: flex-end;
				position: absolute;
				left: 0;
				bottom: 0;

				>view {
					padding: 10rpx 18rpx;
					border-radius: 6rpx;
					border: 2rpx solid #3E89FD;
					font-size: 28rpx;
					color: #3E89FD;
				}

				>view:not(:first-child) {
					margin-left: 20rpx;
				}

				.btn-error {
					border-color: #ED2B29;
					color: #ED2B29;
				}

				.btn-start {
					background-color: #3E89FD;
					border-color: #3E89FD;
					color: #FFFFFF;
				}
			}

			.box-content_detail {
				font-size: 28rpx;
				color: #4D4D4D;
				margin-top: 4rpx;
			}

			.webkit-clamp_2 {
				display: -webkit-box;
				-webkit-box-orient: vertical;
				-webkit-line-clamp: 2;
				/* 限制为两行 */
				overflow: hidden;
			}

			.box-content {
				display: flex;
				align-items: center;
				justify-content: space-between;
				margin-top: 26rpx;
				font-size: 28rpx;

				>view:first-child {
					color: #808080;
				}

				>view:last-child {
					font-size: 24rpx;
					color: #4D8EEC;
				}
			}
			
			.box-content1 {
				margin-top: 26rpx;
				font-size: 28rpx;
				>view:first-child {
					color: #808080;
				}
				> view:last-child {
					margin-top: 20rpx;
					font-size: 28rpx;
					color: #4D4D4D;
				}
			}

			.box-item {
				display: flex;
				align-items: center;
				margin-top: 26rpx;
				font-size: 28rpx;

				>view:first-child {
					width: 220rpx;
					margin-right: 26rpx;
					color: #808080;
				}

				>view:last-child {
					flex: 1;
					color: #4D4D4D;
					word-break: break-all;
					// display: -webkit-box;
					// -webkit-box-orient: vertical;
					// -webkit-line-clamp: 1;
					// /* 限制为两行 */
					// overflow: hidden;
				}

				.color-error {
					color: #FF0000 !important;
				}

				.color-49 {
					color: #498CEC !important;
				}
			}

			.box-header {
				display: flex;
				align-items: center;
				justify-content: space-between;

				>view:first-child {
					display: flex;
					align-items: center;
					flex: 1;

					>view:last-child {
						font-weight: 800;
						font-size: 30rpx;
						color: #171717;
					}
				}

				// >view:last-child {
				// 	padding: 4rpx 20rpx;
				// 	border-radius: 4rpx;
				// 	border: 2rpx solid #F1F1F1;
				// 	font-weight: 500;
				// 	font-size: 22rpx;
				// }

				.wks_active {
					background-color: #898989;
					color: #1A1A1A;
				}

				.sgz_active {
					background-color: #BED0FA;
					color: #5181F6;
				}

				.ztz_active {
					background-color: #C38100;
					color: #FFFFFF;
				}

				.ywg_acitve {
					background-color: #88CF65;
					color: #1A1A1A;
				}
			}
		}

		.confrim-bottom {
			width: 100%;
			padding: 26rpx 26rpx;
			background-color: #FFFFFF;
			box-shadow: 0rpx -8rpx 8rpx 0rpx rgba(0, 0, 0, 0.05);
			display: flex;
			align-items: center;
			justify-content: flex-end;
			position: fixed;
			bottom: 0;
			z-index: 1;

			>view:first-child {
				display: flex;
				align-items: center;
			}

			.confrim-btn {
				display: flex;

				>view {
					padding: 10rpx 20rpx;
					font-weight: 500;
					font-size: 28rpx;
					display: flex;
					align-items: center;
					justify-content: center;
					border: 2rpx solid #D9D9D9;
					border-radius: 6rpx;
					color: #808080;
				}

				.btn-error {
					border: 2rpx solid #ED2B29;
					color: #ED2B29;
				}

				.btn-primary {
					background-color: #5181F6;
					color: #FFFFFF;
				}

				>view:nth-child(n + 2) {
					margin-left: 12rpx;
				}
			}
		}

	}

	.addIssue {
		min-height: 100vh;
		background-color: #FFFFFF;
	}

	.fixedheader {
		position: fixed;
		top: 0;
		left: 0;
		width: 100%;
		z-index: 999;

		/deep/ .headerBox {
			border-bottom: none;
		}

		.headerName {
			z-index: 1;
		}
	}
</style>