<!--
 * @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.8rem" type="line">
				<view class="search-block">
					<view class="adcd-adnm">
						<uni-data-picker placeholder="请选择地区" popup-title="请选择所在地区" :localdata="regionTree"
							v-model="selectedTreeNode" @change="onTreeChange" @nodeclick="onTreeNodeClick"
							@popupopened="onTreePopupOpened" @popupclosed="onTreePopupClosed" :clear-icon="false">
						</uni-data-picker>
					</view>
					<view class="rtu-code">
						<uni-easyinput :styles="inputStyles" @input="searchRtuCodeValClear" prefixIcon="search"
							v-model="searchRtuCodeVal" placeholder="请输入测站编码">
						</uni-easyinput>
					</view>
					<view class="rtu-name">
						<uni-easyinput :styles="inputStyles" @input="searchRtuNameValClear" prefixIcon="search"
							v-model="searchRtuNameVal" placeholder="请输入测站名称">
						</uni-easyinput>
					</view>
					<view class="submit-btn">
						<button type="default" @click="search">查 询</button>
					</view>
				</view>
			</uni-section>
			<view style="margin-top: 5px;padding-left: 10px;padding-right: 10px;margin-bottom: 5px;">
				<view class="line">
					<view class="lineText">
						<text class="inspectionCount">当前汛期: </text>
						<text v-if="countInfo.rainKind==1" class="content">汛前巡检</text>
						<text v-else-if="countInfo.rainKind==2" class="content">汛中（一）巡检</text>
						<text v-else-if="countInfo.rainKind==3" class="content">汛中（二）巡检</text>
						<text v-else class="content">--</text>
					</view>
					<view class="lineText">
						<text class="beforeRainInspectionCount">巡检设备总数量: </text>
						<text class="content">{{ countInfo.rtus }}</text>
					</view>

					<view class="lineText">
						<text class="rainSencodInspectionCount">汛前已巡检数量: </text>
						<text class="content">{{ countInfo.beforeRainInspectionCount }}</text>
					</view>
					<view class="lineText">
						<text class="rainSencodInspectionCount">汛中（一）已巡检数量: </text>
						<text class="content">{{ countInfo.firstRainInspectionCount }}</text>
					</view>
					<view class="lineText">
						<text class="rainSencodInspectionCount">汛中（二）已巡检数量: </text>
						<text class="content">{{ countInfo.sencodRainInspectionCount }}</text>
					</view>
					<view style="margin-top: 5px;">
						<uni-data-checkbox v-model="countOption" :localdata="countItems" @change="countOptionChange">
						</uni-data-checkbox>
					</view>
				</view>
			</view>
			<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="compose" size="18" color="lightblue" />
								<text class="item-text-lable">汛前填报：</text>
								<view v-if="item.beforeRainSeasonStatus ==1">
									<text class="item-text-content" style="color:dodgerblue;">已填报</text>
									<text class="item-text-content" style="color:gray;">/</text>
									<text class="item-text-content"
										style="color:gray;">{{item.beforeRainSeasonReportTime}}</text>
								</view>
								<text v-else class="item-text-content" style="color:darkorange;">未填报</text>
							</view>
							<view class="items-line">
								<uni-icons class="input-uni-icon" type="compose" size="18" color="lightblue" />
								<text class="item-text-lable">汛中（一）填报：</text>
								<view v-if="item.rainSeasonFirstStatus ==1">
									<text class="item-text-content" style="color:dodgerblue;">已填报</text>
									<text class="item-text-content" style="color:gray;">/</text>
									<text class="item-text-content"
										style="color:gray;">{{item.rainSeasonFirstReportTime}}</text>
								</view>
								<text v-else class="item-text-content" style="color:darkorange;">未填报</text>
							</view>
							<view class="items-line">
								<uni-icons class="input-uni-icon" type="compose" size="18" color="lightblue" />
								<text class="item-text-lable">汛中（二）填报：</text>
								<view v-if="item.rainSeasonSecondStatus ==1">
									<text class="item-text-content" style="color:dodgerblue;">已填报</text>
									<text class="item-text-content" style="color:gray;">/</text>
									<text class="item-text-content"
										style="color:gray;">{{item.rainSeasonSecondReportTime}}</text>
								</view>
								<text v-else class="item-text-content" style="color:darkorange;">未填报</text>
							</view>
							<view class="item-button-group">
								<view v-if="item.beforeRainSeasonStatus ==1" class="item-button" style="width: 120px;"
									@click="onBeforeRainDetailViewClick(item.beforeRainSeasonReportId)">
									<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-else class="item-button-disabled" style="width: 120px;">
									<view class="items-line">
										<uni-icons class="input-uni-icon" type="info" size="18" color="gray" />
										<text class="button-text">汛前详情</text>
									</view>
								</view>
								<view v-if="item.rainSeasonFirstStatus ==1" class="item-button" style="width: 120px;"
									@click="onRainFirstDetailViewClick(item.rainSeasonFirstReportId)">
									<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-else class="item-button-disabled" style="width: 120px;">
									<view class="items-line">
										<uni-icons class="input-uni-icon" type="info" size="18" color="gray" />
										<text class="button-text">汛中(一)详情</text>
									</view>
								</view>
								<view v-if="item.rainSeasonSecondStatus ==1" class="item-button" style="width: 120px;"
									@click="onRainSencodDetailViewClick(item.rainSeasonSecondReportId)">
									<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-else class="item-button-disabled" style="width: 120px;">
									<view class="items-line">
										<uni-icons class="input-uni-icon" type="info" size="18" color="gray" />
										<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) {
			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.getRegionTree();
		},
		data() {
			return {
				title: '设备巡检填报信息',
				permission: {
					'admin': false,
					'orgAdmin': false,
					'companyAdmin': false,
					'companyServciePerson': false,
				},
				countItems: [{
					'value': 0,
					'text': '全部'
				}, {
					'value': 1,
					'text': '汛前巡检'
				}, {
					'value': 2,
					'text': '汛中(一)巡检'
				}, {
					'value': 3,
					'text': '汛中(二)巡检'
				}],
				countOption: 0,
				countInfo: {
					rainKind: 0,
				},
				list: [],
				pageSize: 10,
				// 当前页
				pageCurrent: 1,
				// 数据总量
				total: 0,
				regionTree: [],
				regionCode: '',
				selectedTreeNode: '',
				searchRtuNameVal: '',
				searchRtuCodeVal: '',
				query: {},
				inputStyles: {
					color: '#808080',
					borderColor: '#d3d3d3'
				}
			}
		},
		computed: {},
		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();
					this.getCountInfo(this.regionCode);
				} else {
					this.regionCode = '';
					this.query = {};
					this.searchRtuNameVal = '';
					this.searchRtuCodeVal = '';
					this.pageCurrent = 1;
					this.getPage();
					this.getCountInfo(this.regionCode);
				}
			},
			onBeforeRainDetailViewClick(id) {
				console.log("onDetailViewClick " + id)
				var url = '/pages/equipment-inspection/inspectionreportview?type=1&id=' + id;
				uni.navigateTo({
					url: url
				})
			},
			onRainFirstDetailViewClick(id) {
				console.log("onDetailViewClick " + id)
				var url = '/pages/equipment-inspection/inspectionreportview?type=2&id=' + id;
				uni.navigateTo({
					url: url
				})
			},
			onRainSencodDetailViewClick(id) {
				console.log("onDetailViewClick " + id)
				var url = '/pages/equipment-inspection/inspectionreportview?type=3&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;
				}
				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);
					}
				}
			},
			countOptionChange: function(evt) {
				//console.log("sensor" + JSON.stringify(evt))
				let params = {};
				// if (this.countOption == 0) {

				// } else if (this.countOption == 1) {
				// 	params['rainSeasonKind'] = 1;
				// } else if (this.countOption == 2) {
				// 	params['rainSeasonKind'] = 2;
				// } else if (this.countOption == 3) {
				// 	params['rainSeasonKind'] = 3;
				// }
				this.pageCurrent=1;
				this.getPage(params);
			},
			getCountInfo(adCode) {
				let that = this;
				http.request({
					url: '/galaxy-business/equipment/inspection/count',
					method: 'GET',
					data: {
						adCode
					}
				}).then(res => {
					that.countInfo = res.data;
				})
			},
			getRegionTree() {
				var that = this;
				http.request({
					url: '/galaxy-business/baseinfo/region/tree',
					method: 'GET',
				}).then(res => {
					if (res.data != null) {
						that.regionTree = res.data;
						that.selectedTreeNode = that.regionTree[0].value;
						that.regionCode = that.regionTree[0].value;
						that.query = {};
						that.query['adCode'] = that.regionCode;
						//that.orgId = that.projectTree[0].orgId;
						//that.projectId = that.projectTree[0].projectId;
						that.getPage();
						that.getCountInfo(that.regionCode);
					}
				}).catch(err => {
					console.log(err)
				})
			},
			getPage(params = {}) {
				let that = this;
				const current = this.pageCurrent;
				const size = this.pageSize;
				if (this.countOption == 0) {
				
				} else if (this.countOption == 1) {
					params['rainSeasonKind'] = 1;
				} else if (this.countOption == 2) {
					params['rainSeasonKind'] = 2;
				} else if (this.countOption == 3) {
					params['rainSeasonKind'] = 3;
				}
				let postData = Object.assign(params, this.query);
				http.request({
					url: '/galaxy-business/equipment/inspection/rain/page',
					method: 'GET',
					params: {
						current,
						size,

					},
					data: postData,
				}).then(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>
	.line {
		display: flex;
		flex-direction: column;
		justify-content: flex-start;
	}

	.line .lineText {
		margin-left: 10px;
		margin-right: 0px;
		display: flex;
		flex-direction: row;
		justify-content: flex-start;
	}

	.line .lineText .inspectionCount {
		color: dodgerblue;
		font-size: 0.7rem;
	}

	.line .lineText .content {
		margin-left: 10px;
		color: gray;
		font-size: 0.7rem;
	}

	.line .lineText .beforeRainInspectionCount {
		color: dodgerblue;
		font-size: 0.7rem;
	}

	.line .lineText .rainFirstInspectionCount {
		color: dodgerblue;
		font-size: 0.7rem;
	}

	.line .lineText .rainSencodInspectionCount {
		color: dodgerblue;
		font-size: 0.7rem;
	}
</style>