<!--
 * @Title: 
 * @Description: 巡检遗留问题列表
 * @Author: swp
 * @Date: 2022-08-24 10:49:21
 * @LastEditors: 
 * @LastEditTime: 2022-08-24 10:49:21
-->
<template>
	<view class="wrap">
		<uni-nav-bar dark :fixed="true" backgroundColor="#3F9EFF" statusBar="false" left-icon="left" left-text="返回"
			@clickLeft="toBack">
			<view class="nav-title">
				<text>{{title}}</text>
			</view>
		</uni-nav-bar>
		<view class="container">
			<uni-section title="查询条件" titleFontSize="0.7rem" type="line" style="padding-left: 0px;padding-right: 0px;">
				<view style="margin-top: 5px;margin-bottom: 5px;padding-left: 10px;padding-right: 10px;">
					<uni-easyinput :styles="inputStyles" @input="searchRtuCodeValClear" prefixIcon="search"
						v-model="searchRtuCodeVal" placeholder="请输入测站编码">
					</uni-easyinput>
				</view>
				<view style="margin-top: 5px;margin-bottom: 5px;padding-left: 10px;padding-right: 10px;">
					<uni-easyinput :styles="inputStyles" @input="searchRtuNameValClear" prefixIcon="search"
						v-model="searchRtuNameVal" placeholder="请输入测站名称">
					</uni-easyinput>
				</view>
				<view style="margin-top: 5px;margin-bottom: 5px;padding-left: 10px;padding-right: 10px;">
					<view class="inspectionYear">
						<picker pa mode="date" fields="year" :value="inspectionYear" @change="inspectionYearChange">
							<view class="item-text-line">
								<uni-icons class="input-uni-icon" type="calendar" size="18" color="skyblue" />
								<text
									style="margin-left: 4px;font-size: 0.7rem;color:grey;">{{getInspectionYear}}</text>
							</view>
						</picker>
					</view>
				</view>
				<view style="margin-top: 5px;margin-bottom: 5px;padding-left: 10px;padding-right: 10px;">
					<uni-data-select placeholder="请选择汛期" v-model="rainSeasonKind" :localdata="rainDictData"
						@change="rainSelectChange" :clear="false"></uni-data-select>
				</view>
				<view style="margin-top: 5px;margin-bottom: 5px;padding-left: 10px;padding-right: 10px;">
					<button type="default" @click="search">查 询</button>
				</view>
			</uni-section>
			<uni-list>
				<uni-list-item v-for="item in list" :key="item.id">
					<template v-slot:body>
						<view class="list-item-block">
							<view class="items-line">
								<image class="item-title-run-status-icon" style="box-shadow:0 0 2px 2px lightblue"
									src="/static/images/list/inspection_item.png" mode="widthFix">
								</image>
								<text class="item-title-rtu-name">{{item.rtuName}}</text>
								<text class="item-title-rtu-code">[{{item.rtuCode}}]</text>
							</view>
							<view class="items-line">
								<uni-icons class="input-uni-icon" type="calendar" size="18" color="lightblue" />
								<text class="item-text-lable">填报时间：</text>
								<text class="item-text-content">{{item.createTime}}</text>
							</view>
							<view class="items-line">
								<uni-icons class="input-uni-icon" type="compose" size="18" color="lightblue" />
								<text class="item-text-lable">汛期：</text>
								<text v-if="item.rainSeasonKind == 1" class="item-text-content">汛前巡检</text>
								<text v-else-if="item.rainSeasonKind == 2" class="item-text-content">汛中第一次巡检</text>
								<text v-else-if="item.rainSeasonKind == 3" class="item-text-content">汛中第二次巡检</text>
								<text v-else></text>
							</view>
							<view class="items-line">
								<uni-icons class="input-uni-icon" type="list" size="18" color="lightblue" />
								<text class="item-text-lable">问题处理状态：</text>
								<text v-if="item.remainQuestionState ==1" class="item-text-content"
									style="color:red;">待处理</text>
								<text v-else class="item-text-content" style="color:blue;">已完成</text>
							</view>
							<view class="item-button-group">
								<view class="item-button" style="width: 120px;"
									@click="onDetailViewClick(item.id,item.rainSeasonKind)">
									<view class="items-line">
										<uni-icons class="input-uni-icon" type="info" size="18" color="coral" />
										<text class="button-text">巡检填报详情</text>
									</view>
								</view>
								<view v-if="(permission.admin || permission.orgAdmin) && item.remainQuestionState == 1"
									class="item-button" style="width: 120px;"
									@click="onCloseRemainingProblemClick(item.id)">
									<view class="items-line">
										<uni-icons class="input-uni-icon" type="compose" size="18" color="coral" />
										<text class="button-text">关闭问题</text>
									</view>
								</view>
							</view>
						</view>
					</template>
				</uni-list-item>
			</uni-list>
			<uni-group>
				<view class="pagination-block">
					<uni-pagination show-icon :page-size="pageSize" :current="pageCurrent" :total="total"
						@change="pageChange" />
				</view>
			</uni-group>
		</view>
	</view>
</template>

<script>
	import {
		role
	} from "@/api/role.js";
	import http from '@/http/api.js';
	export default {
		components: {},
		onLoad(option) {
			let date = new Date();
			this.inspectionYear = date.getFullYear();
			if (this.userInfo.role_name === role['admin']) {
				this.permission.admin = true;
			} else if (this.userInfo.role_name === role['orgAdmin']) {
				this.permission.orgAdmin = true;
			} else if (this.userInfo.role_name === role['companyAdmin']) {
				this.permission.companyAdmin = true;
			} else if (this.userInfo.role_name === role['companyServciePerson']) {
				this.permission.companyServciePerson = true;
			}
			this.pageCurrent = 1;
			this.getPage()
		},
		data() {
			return {
				permission: {
					'admin': false,
					'orgAdmin': false,
					'companyAdmin': false,
					'companyServciePerson': false,
				},
				list: [],
				title: '设备巡检遗留问题信息',
				pageSize: 10,
				// 当前页
				pageCurrent: 1,
				// 数据总量
				total: 0,
				regionTree: [],
				regionCode: '',
				selectedTreeNode: '',
				searchRtuNameVal: '',
				searchRtuCodeVal: '',
				query: {},
				inputStyles: {
					color: '#808080',
					borderColor: '#d3d3d3'
				},
				inspectionYear: '2023',
				rainSeasonKind: 0,
				rainDictData: [{
						value: 1,
						text: "汛前巡检"
					},
					{
						value: 2,
						text: "汛中第一次巡检"
					},
					{
						value: 3,
						text: "汛中第二次巡检"
					},
				],
			}
		},
		computed: {
			getInspectionYear() {
				return this.inspectionYear + "年";
			}
		},
		onShow() {},
		methods: {
			toBack() {
				uni.navigateBack({
					delta: 1
				})
			},
			onBackPress() {
				// #ifdef APP-PLUS
				plus.key.hideSoftKeybord();
				// #endif
			},
			// 分页触发
			pageChange(e) {
				this.pageCurrent = e.current;
				this.getPage()
			},
			onTreeNodeClick(node) {
				console.log(JSON.stringify(node))
			},
			onTreePopupOpened(e) {
				console.log(JSON.stringify(e))
			},
			onTreePopupClosed(e) {
				console.log(JSON.stringify(e))
			},
			onTreeChange(e) {
				console.log(JSON.stringify(e))
				let nodes = e.detail.value;
				if (nodes.length > 0) {
					let node = nodes[nodes.length - 1];
					this.regionCode = node.value;
					this.query = {};
					this.query['adCode'] = this.regionCode;
					this.searchRtuNameVal = '';
					this.searchRtuCodeVal = '';
					this.pageCurrent = 1;
					this.getPage();
				} else {
					this.regionCode = '';
					this.query = {};
					this.searchRtuNameVal = '';
					this.searchRtuCodeVal = '';
					this.pageCurrent = 1;
					this.getPage();
				}
			},
			onDetailViewClick(id, rainSeasonKind) {
				let url = '/pages/equipment-inspection/inspectionreportview?id=' + id + "&type=" + rainSeasonKind;
				uni.navigateTo({
					url: url
				})
			},
			onCloseRemainingProblemClick(id) {
				let url = '/pages/equipment-inspection/inspectionremainingproblemsclose?id=' + id;
				uni.navigateTo({
					url: url
				})
			},
			//录入查询
			search() {
				this.pageCurrent = 1;
				let params = {};
				if (this.searchRtuCodeVal.length > 0) {
					params['rtuCode'] = this.searchRtuCodeVal;
				}
				if (this.searchRtuNameVal.length > 0) {
					params['rtuName'] = this.searchRtuNameVal;
				}
				if (this.inspectionYear) {
					params['inspectionYear'] = this.inspectionYear + "-01-01";
				}
				if (this.rainSeasonKind) {
					params['rainSeasonKind'] = this.rainSeasonKind;
				}
				this.getPage(params);
			},
			searchRtuNameValClear(e) {
				if (e == null || e.length == 0) {
					this.searchRtuNameVal = '';
					if (this.searchRtuNameVal.length == 0) {
						let params = {};
						if (this.searchRtuCodeVal.length > 0) {
							params['rtuCode'] = this.searchRtuCodeVal;
						}
						this.getPage(params);
					}
				}
			},
			searchRtuCodeValClear(e) {
				if (e == null || e.length == 0) {
					this.searchRtuCodeVal = '';
					if (this.searchRtuCodeVal.length == 0) {
						let params = {};
						if (this.searchRtuNameVal.length > 0) {
							params['rtuName'] = this.searchRtuNameVal;
						}
						this.getPage(params);
					}
				}
			},
			inspectionYearChange(event) {
				this.inspectionYear = event.detail.value;
			},
			rainSelectChange(e) {
				if (e != null && e != '') {
					console.log("e:", e);
					this.rainSeasonKind = e;
				}
			},
			getPage(params = {}) {
				const that = this;
				const current = this.pageCurrent;
				const size = this.pageSize;
				let postData = Object.assign(params, this.query);
				http.request({
					url: '/galaxy-business/equipment/inspection/report/remainingproblems/page',
					method: 'GET',
					params: {
						current,
						size,
					},
					data: postData,
				}).then(res => {
				//	console.log(JSON.stringify(res))
					if (res.data != null) {
						if (res.data.records != null) {
							that.list = res.data.records;
						}
						this.total = res.data.total;
					}
				}).catch(err => {
					console.log(err)
				})
			},
		}
	}
</script>

<style>
	/* page {
		background-color: rgb(240, 242, 244);
	} */
</style>

<style lang="scss" scoped>

</style>
