<template>
	<view>
		<view class="top">
			<image src="./img/top.jpg" mode=""></image>
		</view>
		<view class="content">
			<view class="list">
				<view class="item" v-for="(item,index) in list" :key="index"
					@click="open_draw(item.mine_id,item.mine_name)">
					<view class="inner" :style="{borderLeftColor: bgColor[index]}">
						<view class="left">
							<view class="name">{{item.mine_name}}</view>
							<view class="text">{{item.danger_num}} 条隐患信息</view>
						</view>
						<view class="right">
							<view class="num">{{item.score}} 分</view>
							<view class="icon">
								<uni-icons type="arrowright"></uni-icons>
							</view>
						</view>
					</view>
				</view>
			</view>


			<!-- 弹出层 -->
			<uni-drawer ref="draw" mode="right" :width="300">
				<view class="drawer">
					<view class="title">{{mine_name}}</view>
					<view class="container">
						<view class="item" v-for="(item,index) in depart_list" :key="index"
							@click="go_detail(item.depart_id)">
							<view class="inner" :style="{borderLeftColor: bgColor[index]}">
								<view class="left">
									<view class="name">{{item.depart_name}}</view>
									<view class="text">{{item.danger_num}} 条隐患信息</view>
								</view>
								<view class="right">
									<view class="num">{{item.score}} 分</view>
									<view class="icon">
										<uni-icons type="arrowright"></uni-icons>
									</view>
								</view>
							</view>
						</view>
					</view>
				</view>
			</uni-drawer>
		</view>
	</view>
</template>

<script>
	import time from "@/common/time.js"

	export default {
		data() {
			return {
				start_time: "",
				end_time: "",

				list: [],
				bgColor: [],
				depart_list: [],
				mine_name: ""
			};
		},
		onLoad() {
			// 初始化时间
			this.start_time = new Date().format("yyyy-MM-01")
			this.end_time = new Date().format("yyyy-MM-dd")


			console.log(this.start_time, this.end_time)

			// 设置头像
			for (let i = 0; i < 100; i++) {
				// 获取随机色
				let r = parseInt(Math.random() * 256)
				let g = parseInt(Math.random() * 256)
				let b = parseInt(Math.random() * 256)

				// ES6 字符串拼接
				// this.bgColor = `rgba(${r},${g},${b},0.3)`
				let color = "rgba(" + r + "," + g + "," + b + "," + 0.8 + ")"
				// console.log(color)
				this.bgColor.push(color)
			}

			this.get_list()
		},
		methods: {
			open_draw(mine_id, mine_name) {
				this.mine_name = mine_name
				this.depart_list = []
				this.$refs.draw.open()

				this.$p_api.danger_depart({
					mine_id: mine_id,
					start_time: this.start_time,
					end_time: this.end_time
				}).then((res) => {
					// console.log(res.data.data)

					this.depart_list = res.data.data
				})
			},
			go_detail(depart_id) {
				uni.navigateTo({
					url: "detail/detail?depart_id=" + depart_id
				})
			},

			get_list() {
				this.$p_api.danger_mine({
					start_time: this.start_time,
					end_time: this.end_time
				}).then((res) => {
					// console.log(res.data.data)

					this.list = res.data.data
				})
			},


		}
	}
</script>

<style lang="scss">
	.top {
		image {
			width: 750rpx;
			height: 360rpx;
		}
	}

	.content {
		width: 749rpx;
	}

	.list {
		.item {
			box-sizing: border-box;
			padding: 20rpx 0;
			padding-right: 30rpx;

			border-bottom: 1px solid #eee;

			.inner {
				border-left: 12rpx solid #8BDAFF;

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

				.left {
					box-sizing: border-box;
					padding-left: 30rpx;
					line-height: 45rpx;

					.name {}

					.text {
						font-size: 26rpx;
						color: #999999;
					}
				}

				.right {
					display: flex;
					align-items: center;

					.num {
						font-size: 26rpx;
						color: #AC5158;
					}

					.icon {
						margin-left: 4rpx;
					}
				}
			}
		}
	}

	.drawer {
		width: 600rpx;

		.title {
			line-height: 87rpx;
			box-sizing: border-box;
			padding: 0 30rpx;
			border-bottom: 1px solid #2E8EAA;
		}

		.container {
			width: 600rpx;

			.item {
				box-sizing: border-box;
				padding: 20rpx 0;
				padding-right: 30rpx;

				border-bottom: 1px solid #eee;

				.inner {
					border-left: 12rpx solid #8BDAFF;

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

					.left {
						box-sizing: border-box;
						padding-left: 30rpx;
						line-height: 45rpx;

						width: 390rpx;

						.name {
							width: 390rpx;
							white-space: nowrap;
							overflow: hidden;
							text-overflow: ellipsis;
						}

						.text {
							font-size: 26rpx;
							color: #999999;
						}
					}

					.right {
						display: flex;
						align-items: center;

						.num {
							font-size: 26rpx;
							color: #AC5158;
						}

						.icon {
							margin-left: 4rpx;
						}
					}
				}
			}
		}
	}
</style>
