<template>
	<view class="container">
		<u-popup :show="showpopup" @close="showpopup=false" :safeAreaInsetBottom='false' :round="10">
			<view class="popupmain">
				<view class="popup_title">
					<text>筛选</text>
				</view>
				<view class="line">
				</view>
				<view class="project">
					<view class="project_box" v-for="(item,index) in columns" :key="index">
						<view class="title">
							{{item.title}}
						</view>
						<view class="main">
							<view class='btns_main' :class="popupData[item.key]===k.id?'primary':''"
								@click="changetype(item,k)" style="border-radius: 0.7rem;" v-for="k in item.project"
								:key="k.id">{{k.label}}</view>
						</view>
					</view>
				</view>
				<view class="popup_btns">
					<u-button text="重置" @click="repect"></u-button>
					<u-button type="primary" text="确定" @click="surepopup">
					</u-button>
				</view>
			</view>
		</u-popup>
		<view style="position: relative;">
			<view style="display: flex;align-items: center;">
				<input placeholder='航线名称'
					style="background-color: #F2F2F2;border: none;padding: 3px 10px;border-radius: 1rem;"
					:style="'width: 85%;'" v-model="dataForm.lineName" type="text" confirm-type="search"
					@confirm="searchs">

				<u-icon @click="openshowpopup" style="margin-left: 0.3rem;" size="26" name="list-dot"
					color="#C6C7CB"></u-icon>
			</view>
			<view style="position: absolute;right: 2.5rem;top: 0.4rem;z-index:10"
				@click="dataForm.lineName='',getList()">
				<u-icon v-if="dataForm.lineName" name="close-circle-fill" color="#C6C7CB"></u-icon>
			</view>
		</view>
		<scroll-list ref="list" :option="option" @refresh="refresh" @scrolltolower="loadMore">
			<view class="list-item" v-for="(item, index) in list"
				:style="{'--isReceivedColor':isReceivedColor[item.isReceived]}" :key="index" @click="handleTest(item)">
				<view class="main_box">
					<view class="text">
						管线名称 ：{{item.lineName}}
					</view>
					<view class="text">
						管线单元名称 ：{{item.lineUnitName}}
					</view>
					<view class="text">
						任务状态：
						<span :style="{ color: isReceivedColor[item.isReceived] }">
							{{ isReceived[item.isReceived ]}}
						</span>
					</view>
				</view>
			</view>
		</scroll-list>
	</view>
</template>

<script>
	import Config from "@/common/Config.js";
	export default {
		data() {
			return {
				option: {
					size: 5,
					auto: true
				},
				propsData: {
					label: 'name',
					value: 'key',
					children: 'children',
				},
				popupData: {
					isReceived: "",
				},
				showpopup: false,
				isReceivedColor: {
					"0": "#d07946", // 灰色 - 未接收
					"1": "#4CAF50", // 绿色 - 已接收
					"2": "#9E9E9E", // 深灰色 - 已结束
					"3": "#F44336", // 红色 - 已拒绝
					"4": "#FFEB3B", // 黄色 - 已经下载航线文件
					"5": "#2196F3", // 蓝色 - 已上传文件
					"6": "#009688" // 深青色 - 已确认上传文件为最终巡检文件
				},
				columns: [{
					title: '状态',
					key: 'isReceived',
					project: [{
						label: '未接收',
						id: 0
					}, {
						label: '已接收',
						id: 1
					}, {
						label: '已结束',
						id: 2
					}, {
						label: '已拒绝',
						id: 3
					}, {
						label: '已下载文件',
						id: 4
					}, {
						label: '已上传文件',
						id: 5
					}, {
						label: '已确认文件',
						id: 6
					}]
				}],
				isReceived: {
					0: '未接收',
					1: '已接收',
					2: '已结束',
					3: '已拒绝',
					4: '已经下载航线文件',
					5: '已上传文件',
					6: '已确认上传文件为最终巡检文件',
				},
				dataForm: {
					page: 1,
					limit: 10
				},
				list: []
			}
		},
		onShow() {
			this.list = []
			this.dataForm.limit = 10
			this.getList()
		},
		methods: {
			handleScroll(x) {
				this.scrollTop = x.scrollTop
			},
			loadMore() {
				// 在触底时，调用加载更多的 API 方法
				this.dataForm.limit += 10; // 页数加1
				this.getList(); // 获取更多数据
			},
			searchs(e) {
				this.checked = []
				this.dataList = []
				this.list = []
				this.dataForm.limit = 10
				this.getList()
			},
			surepopup() {
				this.showpopup = false
				this.list = []
				this.dataForm.limit = 10
				this.dataForm = {
					...this.dataForm,
					...this.popupData
				}
				this.getList()
			},
			repect() {
				for (let key in this.popupData) {
					this.popupData[key] = ''
				}
			},
			changetype(x, k) {
				this.popupData[x.key] = k.id
			},
			openshowpopup(e) {
				this.showpopup = true
			},
			handleTest(x) {
				uni.navigateTo({
					url: '/pages/index/taskDeatils?data=' + JSON.stringify(x)
				})
			},
			getList() {
				this.dataForm.handleUserIds = uni.getStorageSync('userInfo').id
				this.$api.to_http(`/task/zhkjwurenjitaskarrange/getUserTaskArrange`, this.dataForm, 'get').then((res) => {
					this.list.push(...res.data.data.list)
					this.$refs.list.loadSuccess({
						list: this.list,
						total: res.data.data.total
					});
				})
			},
			// 加载数据
			load(paging) {
				this.$api.to_http(`/task/zhkjwurenjitaskarrange/getUserTaskArrange`, this.dataForm, 'get').then((res) => {
					let list = [];
					for (var i = 0; i < res.data.data.list.length; i++) {
						list.push(res.data.data.list[i]);
					}
					this.list = [...this.list, ...list];
					// 加载成功  参数对象{list: 当前列表,total: 数据总长度(后端查询的total)}
					this.$refs.list.loadSuccess({
						list: this.list,
						total: res.data.data.total
					});
					// 加载失败
					// this.$refs.list.loadFail()
				})
			},
			// 刷新刷剧
			refresh(paging) {
				this.list = []
				this.dataForm.limit = 10
				this.$api.to_http(`/task/zhkjwurenjitaskarrange/getUserTaskArrange`, this.dataForm, 'get').then((res) => {
					let list = [];
					for (var i = 0; i < res.data.data.list.length; i++) {
						list.push(res.data.data.list[i]);
					}
					this.list = list;
					// 加载成功  参数对象{list: 当前列表,total: 数据总长度(后端查询的total)}
					this.$refs.list.refreshSuccess({
						list: this.list,
						total: res.data.data.total
					});
					// 加载失败
					// this.$refs.list.loadFail()
				})
			}
		}

	}
</script>
<style lang="less" scoped>
	.list-item {
		font-size: 30rpx;
		padding: 10rpx 20rpx;
		position: relative;

		.main_box {
			border-radius: 15rpx;
			// border: 1px solid #000;
			padding: 30rpx;
			background-color: #fff;


			.text {
				margin: 18rpx 0;
			}
		}
	}

	.popupmain {

		.popup_title {
			padding: 0.5rem 1rem;
			text-align: center;
		}

		.line {
			height: 0.4rem;
			background-color: #F3F4F6;
		}

		.project {
			padding: 0.6rem;
			height: 15rem;
			overflow: auto;

			.project_box {
				margin-bottom: 0.5rem;

				.main {
					margin-top: 0.5rem;
					display: grid;
					grid-template-columns: 1fr 1fr 1fr;
					// grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
					grid-gap: 0.8rem;

					.btns_main {
						height: 40px;
						position: relative;
						align-items: center;
						justify-content: center;
						display: flex;
						flex-direction: row;
						box-sizing: border-box;
						flex-direction: row;
						padding: 0 12px;
						font-size: 14px;
						border-color: #ebedf0;
						border-width: 1px;
						border-style: solid;
					}

					.primary {
						background-color: #3c9cff;
						border-color: #3c9cff;
						color: #fff;
					}
				}
			}
		}

		.popup_btns {
			padding: 0.6rem;
			display: flex;
			margin-top: 1rem;
			border-top: 1px solid #f1f1f1;

			.u-button {
				width: 47%;
			}
		}
	}

	.list-item::after {
		display: block;
		content: '';
		width: 6rpx;
		height: 100rpx;
		background-color: var(--is-received-color);
		position: absolute;
		top: 30%;
	}
</style>