<template>
	<view class="addIssue">
		<view class="fixedheader">
			<headers :showBack="true" :themeType="true">
				<view class="headerName">
					风险管控待办
				</view>
			</headers>
		</view>
		<view class="search-box" :style="{paddingTop: mobileTopHeight + 44 + 'px'}">
			<view class="uni-form-item">
				<u-search class="uni-input" placeholder="搜索风险相关内容" :show-action="false" @change="loadData"
					v-model="searchName"></u-search>
			</view>
		</view>
		<view class="content" :style="{paddingTop: mobileTopHeight + 110 + 'px'}">
			<u-collapse ref="myCollapse" v-if="selectWorkerInfoList.length > 0" v-model="activeName"
				accordion>
				<u-collapse-item @change="onRegionChange" :index="item.id" v-for="item in selectWorkerInfoList" :key="item.id">
					<template v-slot:title>
						<view class="item-cell flex-center item-cell_title">
							{{item.regionName}}({{item.riskListPointTodoNum ? item.riskListPointTodoNum : 0}})
						</view>
					</template>
					<u-collapse class="my-collapse" ref="myCollapse1" v-if="riskListPointList.length > 0"
						accordion>
						<u-collapse-item @change="onRiskPointChange(item)" :index="item.id" v-for="item in riskListPointList" :key="item.id">
							<template v-slot:title>
								<view class="item-cell flex-center item-cell_title">
									{{fullPathCutOut(item.riskPointName, 2)}}({{item.hazardSourceNumber}})
								</view>
							</template>
							<template v-if="riskListSourceList.length > 0">
								<view class="content-box content-box1" v-for="ele in riskListSourceList" :key="ele.id">
									<view class="content-header">
										<view class="header-title">{{ele.subProjectWorkTask}}</view>
										<view class="riskcolor riskcolor_table" :class="{
										  riskcolor1: ele.riskLevel == 1,
										  riskcolor2: ele.riskLevel == 2,
										  riskcolor3: ele.riskLevel == 3,
										  riskcolor4: ele.riskLevel == 4,
										}">{{riskLevelUp(ele.riskLevel)}}</view>
									</view>
									<view class="content-row">
										<view>风险描述:</view>
										<view>{{ele.riskDescription ? ele.riskDescription : '--'}}</view>
									</view>
									<view class="content-row">
										<view>管控措施:</view>
										<view>{{ele.managementMeasure ? ele.managementMeasure : '--'}}</view>
									</view>
									<view class="content-row">
										<view>工程措施:</view>
										<view>{{ele.engineeringMeasure ? ele.engineeringMeasure : '--'}}</view>
									</view>
									<view class="content-row">
										<view>管理措施:</view>
										<view>{{ele.managementMeasure ? ele.managementMeasure : '--'}}
										</view>
									</view>
									<view class="content-row">
										<view>个体防护:</view>
										<view>{{ele.personalProtection ? ele.personalProtection : '--'}}
										</view>
									</view>
									<view class="content-row">
										<view>应急措施:</view>
										<view>{{ele.emergencyMeasure ? ele.emergencyMeasure : '--'}}
										</view>
									</view>
									<view class="content-row">
										<view>教育措施:</view>
										<view>{{ele.educationalMeasure ? ele.educationalMeasure : '--'}}
										</view>
									</view>
									<view class="content-btn">
										<view @click="onNavigateToDetail(ele)">新增落实记录</view>
									</view>
								</view>
							</template>
							<view class="new-nodata1" v-else>
								<view></view>
								<text>暂无数据...</text>
							</view>
						</u-collapse-item>
					</u-collapse>
					<view class="new-nodata1" v-else>
						<view></view>
						<text>暂无数据...</text>
					</view>
				</u-collapse-item>
			</u-collapse>
			<view class="new-nodata" v-else>
				<view></view>
				<text>暂无数据...</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				mobileTopHeight: 0,
				projectDetail: {},
				pageNo: 1,
				pageSize: 10,
				selectWorkerInfoList: [],
				isLoadMore: false,
				loadStatus: 'more',
				activeName: "",
				activeName1: "",
				searchName: "",
				riskListPointList: [],
				riskListSourceList: [],
				riskLevelList: [{
						id: 1,
						name: "重大风险",
					},
					{
						id: 2,
						name: "较大风险",
					},
					{
						id: 3,
						name: "一般风险",
					},
					{
						id: 4,
						name: "低风险",
					},
				],
				regionIds: "",
			}
		},
		onLoad(opts) {
			console.log(112233, opts)
			this.projectDetail = JSON.parse(uni.getStorageSync('projectDetail'))

			this.getSelectWorkerInfoList();
		},
		mounted() {
			var that = this
			uni.getSystemInfo({
				success(res) {
					that.mobileTopHeight = res.statusBarHeight ? res.statusBarHeight : 0;
					uni.setStorageSync('systemInfo', res)
					console.log(res)
				}
			})
		},
		onReachBottom() {
			console.log(1)
			// if (!this.isLoadMore) { //此处判断，上锁，防止重复请求
			// 	this.isLoadMore = true
			// 	this.pageNo += 1
			// 	this.getSelectWorkerInfoList()
			// }
		},
		onPullDownRefresh() {
			console.log(2)
			this.pageNo = 1
			this.selectWorkerInfoList = []
			this.getSelectWorkerInfoList()
		},
		methods: {
			// 截取指定/字符串
			fullPathCutOut(strName, startIndex) {
				const parts = strName.split('/');
				if (startIndex < 1 || startIndex >= parts.length) return ''; // n 无效或超出范围
				return parts.slice(startIndex).join('/'); // 拼接第 n 部分之后的内容
			},
			onRiskPointChange(row) {
				console.log("event", row)
				let data = {
					projectSn: this.projectDetail.projectSn,
					pageNo: 1,
					pageSize: -1,
					pointId: row.id,
					isMySourceToDoForWorkable: 1,
				}

				this.sendRequest({
					url: 'xmgl/riskListSource/page',
					method: 'GET',
					data: data,
					success: res => {
						if (res.code == 200) {
							this.riskListSourceList = res.result.records;
							this.$nextTick(() => {
								console.log(this.$refs.myCollapse1)
								const findIndex = this.selectWorkerInfoList.findIndex(item => item.id == this.regionIds);
								this.$refs.myCollapse1[findIndex].init();
								setTimeout(() => {
									this.$refs.myCollapse.init();
								}, 200)
							})
						}
					}
				})
			},
			onRegionChange(event) {
				console.log("event", event)
				this.regionIds = event.index
				let data = {
					projectSn: this.projectDetail.projectSn,
					pageNo: 1,
					pageSize: -1,
					regionIds: this.regionIds,
					isMySourceToDoForWorkable: 1,
				}

				this.sendRequest({
					url: 'xmgl/riskListPoint/page',
					method: 'GET',
					data: data,
					success: res => {
						if (res.code == 200) {
							this.riskListPointList = res.result.records;
							this.$nextTick(() => {
								this.$refs.myCollapse.init();
							})
						}
					}
				})
			},
			onNavigateToDetail(row) {
				uni.navigateTo({
					url: `./addImplementingRecord?id=${row.id}`
				})
			},
			loadData() {
				this.pageNo = 1
				this.selectWorkerInfoList = []
				this.getSelectWorkerInfoList()
			},
			getSelectWorkerInfoList() {
				let data = {
					pageNo: this.pageNo,
					pageSize: this.pageSize,
					projectSn: this.projectDetail.projectSn,
					regionName: this.searchName,
					isMySourceToDoForWorkable: 1,
				}

				this.sendRequest({
					url: 'xmgl/qualityRegion/notTreeList',
					method: 'POST',
					data: data,
					success: res => {
						uni.hideLoading()
						if (res.code == 200) {
							console.log("workList======================", res)
							// this.selectWorkerInfoList = this.selectWorkerInfoList.concat(res.result.records);
							this.selectWorkerInfoList = res.result;
							// if (res.result.records.length < this.pageSize) { //判断接口返回数据量小于请求数据量，则表示此为最后一页
							// 	this.isLoadMore = true
							// 	this.loadStatus = 'nomore'
							// } else {
							// 	this.isLoadMore = false
							// 	// that.loadStatus='more'
							// }
							// uni.stopPullDownRefresh()
						}
					}
				})
			},
		},
		computed: {
			riskLevelUp() {
				return (riskLevel) => {
					const find = this.riskLevelList.find((item) => riskLevel === item.id);
					return find ? find.name : "--";
				};
			},
		}
	}
</script>

<style scoped lang="scss">
	/deep/ .u-collapse-head {
		padding: 12rpx 0;
		background-color: #FFFFFF;
	
		.u-collapse-title {
			color: #498CEC;
		}
	
		// .u-icon__icon {
		// 	color: #498CEC !important;
		// }
	}
	/deep/ .u-collapse-content {
		    display: flex;
		    flex-direction: column;
		    align-items: center;
			padding-bottom: 13px;
	}
	
	.my-collapse {
		width: 100%;
		/deep/ .u-collapse-head {
			padding-left: 66rpx;
			background-color: #FBFBFB;
		}
	}
	
	/deep/ .van-cell__title,
	.item-cell_title {
		font-weight: 500;
		font-size: 30rpx;
		color: #1A1A1A;
	}
	
	/deep/ .van-collapse-item__content,
	/deep/ .uni-collapse-item__wrap-content {
		background-color: #F2F3F7;
		padding: 26rpx;
	}
	.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;
	}
	.icon-left,
	.icon-right {
		width: 32rpx;
		height: 32rpx;
		background-image: url('@/static/staffAttendance/attendance-icon1.png');
		background-repeat: no-repeat;
		background-size: 100% 100%;
	}

	.icon-right {
		transform: rotate(90deg);
	}

	.icon-top {
		transform: rotate(-90deg);
	}

	.new-nodata {
		position: absolute;
		top: 50%;
		left: 50%;
		transform: translate(-50%, -50%);
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;

		>view {
			width: 300rpx;
			height: 300rpx;
			background-image: url('@/static/staffAttendance/nodata.png');
			background-repeat: no-repeat;
			background-size: 100% 100%;
		}

		>text {
			font-size: 22rpx;
			color: #808080;
			margin-top: 60rpx;
		}
	}

	.new-nodata1 {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		background-color: white;
		padding: 20rpx;
		width: 698rpx;
		margin-top: 26rpx;

		>view {
			width: 300rpx;
			height: 300rpx;
			background-image: url('@/static/staffAttendance/nodata.png');
			background-repeat: no-repeat;
			background-size: 100% 100%;
		}

		>text {
			font-size: 22rpx;
			color: #808080;
			margin-top: 60rpx;
		}
	}

	/deep/ .van-cell,
	.item-cell {
		padding: 22rpx 26rpx;
	}

	/deep/ .van-cell__title,
	.item-cell_title {
		font-weight: 500;
		font-size: 30rpx;
		color: #1A1A1A;
	}

	/deep/ .van-collapse-item__content,
	/deep/ .u-collapse-item__wrap-content {
		background-color: #F2F3F7;
		padding: 26rpx;
	}

	.content-main {
		padding: 26rpx;
	}

	.content-box1 {
		// height: 554rpx;
		margin-top: 26rpx;
		position: relative;
		padding-bottom: 120rpx !important;

		.content-btn {
			width: 100%;
			padding: 18rpx 26rpx;
			background: #FFFFFF;
			box-shadow: 0rpx -8rpx 8rpx 0rpx rgba(0, 0, 0, 0.05);
			position: absolute;
			bottom: 0;
			left: 0;
			display: flex;
			justify-content: flex-end;

			>view {
				// width: 216rpx;
				background: #5181F6;
				border-radius: 6rpx;
				padding: 18rpx 24rpx;
				font-size: 28rpx;
				color: #FFFFFF;
				display: flex;
				align-items: center;
				justify-content: center;
			}
		}

		.content-row {
			display: flex;
			align-items: flex-start;
			padding: 20rpx 0;
			// border-bottom: 2rpx solid #F2F2F2;
			font-size: 28rpx;

			>view:first-child {
				width: 162rpx;
				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;
			}
		}

		.attachment {
			flex-direction: column;
			align-items: flex-start;

			>view:not(:first-child) {
				display: flex;
				align-items: center;
				justify-content: space-between;
				margin-top: 32rpx;
				width: 100%;

				>view:first-child {
					display: flex;
					align-items: center;
					width: 70%;

					>image {
						width: 40rpx;
						height: 40rpx
					}

					>view {
						font-size: 28rpx;
						color: #171717;
						margin-left: 32rpx;
						overflow: hidden;
						white-space: nowrap;
						text-overflow: ellipsis;
					}
				}

				>view:last-child {
					font-size: 24rpx;
					color: #808080;
				}
			}
		}
	}

	.content-box {
		width: 698rpx;
		padding: 26rpx;
		background: #FFFFFF;
		box-shadow: 0rpx 4rpx 10rpx 0rpx rgba(3, 92, 181, 0.1), 0rpx 8rpx 40rpx 0rpx rgba(0, 0, 0, 0.05);
		// border-radius: 16rpx;

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

			.header-title {
				font-weight: 500;
				font-size: 30rpx;
				color: #1A1A1A;
			}

			// >view:last-child {
			// 	font-size: 22rpx;
			// 	color: #4D4D4D;
			// 	background-color: #FFFF00;
			// 	padding: 4rpx 14rpx;
			// }
		}
	}


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

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

		.headerName {
			z-index: 1;
		}
	}

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

	/deep/ .u-collapse-item__title-arrow {
		display: none;
	}

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

	.icon-screen {
		display: flex;
		flex-direction: column;
		margin-left: 22rpx;

		>view:nth-child(1) {
			border-bottom: 12rpx solid #333333;
			border-right: 10rpx solid transparent;
			border-left: 10rpx solid transparent;
		}

		>view:nth-child(2) {
			border-top: 12rpx solid #333333;
			border-right: 10rpx solid transparent;
			border-left: 10rpx solid transparent;
			margin-top: 4rpx;
		}

		.icon-screen_active {
			border-bottom-color: #108BC7 !important;
			border-top-color: #108BC7 !important;
		}
	}

	.search-box {
		background-color: white;
		width: 100%;
		position: fixed;
		z-index: 99;

		.uni-form-item {
			padding: 20rpx 26rpx;
			position: relative;
			display: flex;

			.uni-input {
				border: 2rpx solid #E4E4E4;
				border-radius: 68rpx;
				padding: 0;
				font-size: 30rpx;
				color: #444444;

				/deep/ .u-content {
					background-color: #FFFFFF !important;

					.u-input {
						background-color: #FFFFFF !important;
						color: #999999 !important;
					}
				}
			}

			.search-btn {
				width: 72rpx;
				height: 72rpx;
				background: #498CEC;
				border-radius: 48rpx;
				margin-left: 30rpx;
				display: flex;
				align-items: center;
				justify-content: center;

				>image {
					width: 50rpx;
					height: 50rpx;
				}
			}
		}

		/deep/ .u-dropdown {
			padding-right: 60rpx;
		}

		.calendar_box {
			position: absolute;
			right: 28rpx;
			bottom: 20rpx;

			.calendar {
				width: 32rpx;
				height: 32rpx;
				background-image: url('@/static/workTicketManage/calendar.png');
				background-repeat: no-repeat;
				background-size: 100% 100%;
			}

			.calendar_active {
				background-image: url('@/static/workTicketManage/calendar-active.png');
			}
		}
	}
</style>