<!--
 * @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 class="line" style="margin-top: 5px;">
				<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.remaininspectionrtus }}</text>
				</view>
			</view>
			<uni-list>
				<uni-list-item v-for="item in list" :key="item.rtuCode">
					<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="map" size="18" color="lightblue" />
								<text class="item-text-lable">行政区划：</text>
								<text class="item-text-content">{{getAreaName(item)}}</text>
							</view>
							<view class="items-line">
								<uni-icons class="input-uni-icon" type="location" size="18" color="lightblue" />
								<text class="item-text-lable">安装位置：</text>
								<text class="item-text-content-ellipsis">{{item.locationDesc}}</text>
							</view>
							<view class="items-line">
								<uni-icons class="input-uni-icon" type="home" size="18" color="lightblue" />
								<text class="item-text-lable">测站类型：</text>
								<text class="item-text-content">{{getSiteKind(item)}}</text>
							</view>
							<view v-if="item.runStatusId==1" class="items-line">
								<image class="item-title-run-status-icon" mode="widthFix"
									src="/static/images/icon_warning.png">
								</image>
								<text class="item-text-lable">站点异常：</text>
								<text class="item-text-content-ellipsis">{{item.warnKindInfo}}</text>
							</view>
							<view class="item-button-group">
								<view class="item-button" @click="onLocationClick(item)">
									<view class="items-line">
										<uni-icons class="input-uni-icon" type="location" size="18" color="coral" />
										<text class="button-text">导航</text>
									</view>
								</view>
								<!-- 					<view v-if="item.runStatusId==1" class="item-button" @click="onWarnInfoViewClick(item.rtuCode)">
									<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.companyAdmin || permission.companyServciePerson) && item.orderStatus==1 && (item.orderConfirm ==0 || item.myOrder ==1)" class="item-button" @click="onComfireCheckOrderClick(item)">
									<view class="items-line">
										<uni-icons class="input-uni-icon" type="compose" size="18" color="coral" />
										<text class="button-text">异常处理</text>
									</view>
								</view> -->
								<!-- 						<view v-if="(permission.companyAdmin || permission.companyServciePerson) && item.orderStatus==1 && item.orderConfirm ==1 && item.myOrder ==0" class="item-button" @click="onCheckOrderReportClick(item)">
									<view class="items-line">
										<uni-icons class="input-uni-icon" type="compose" size="18" color="coral" />
										<text class="button-text">维修填报</text>
									</view>
								</view> -->
								<view v-if="item.orderStatus==1" class="item-button"
									@click="onCheckOrderProcessClick(item)">
									<view class="items-line">
										<uni-icons class="input-uni-icon" type="compose" size="18" color="coral" />
										<text class="button-text">维修任务</text>
									</view>
								</view>
								<view v-if="permission.companyAdmin || permission.companyServciePerson"
									class="item-button" @click="onReportClick(item.rtuCode)">
									<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) {
			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,
				},
				countInfo: {
					rainKind: 0,
				},
				//planId: 0,
				//orgId: '',
				//projectId: '',
				list: [],

				pageSize: 10,
				// 当前页
				pageCurrent: 1,
				// 数据总量
				total: 0,
				regionTree: [],
				regionCode: '',
				selectedTreeNode: '',
				searchRtuNameVal: '',
				searchRtuCodeVal: '',
				query: {},
				inputStyles: {
					color: '#808080',
					borderColor: '#d3d3d3'
				}
			}
		},
		computed: {
			getIcon() {
				return path => {
					return 'https://cdn.uviewui.com/uview/example/' + path + '.png';
				}
			},
		},
		onShow() {
			this.pageCurrent = 1;
			this.getPage()
		},
		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);
				}
			},
			onDetailViewClick(rtuCode) {
				console.log("onDetailViewClick " + rtuCode)
				var url = '/pages/equipment-inspection/inspectionreportview?rtuCode=' + rtuCode;
				uni.navigateTo({
					url: url
				})
			},
			onReportClick(rtuCode) {
				console.log("onReportClick " + rtuCode)
				var url = '/pages/equipment-inspection/equipmentinspectionreport?rtuCode=' + rtuCode;
				uni.navigateTo({
					url: url
				})
			},
			onLocationClick(item) {
				if (item.lat && item.lat) {
					let lat = item.lat;
					let lng = item.lng;
					let name = item.rtuName;
					let add = '';
					if (item.locationDesc) {
						add = item.locationDesc;
					}
					uni.openLocation({
						latitude: Number(lat),
						longitude: Number(lng),
						name: name,
						address: "",
						success() {}
					})
				} else {
					uni.showModal({
						content: '经纬度为空，请确认！',
						showCancel: true,
						success(res) {
							if (res.confirm) {

							}
						}
					});
				}
			},
			onWarnInfoViewClick(rtuCode) {
				uni.navigateTo({
					url: '/pages/warning/rtuwarninglist?rtuCode=' + rtuCode
				})
			},
			onCheckOrderProcessClick(item) {
				var that = this;
				console.log("order id " + item.orderId)
				if (this.permission.admin || this.permission.orgAdmin) {
					let url = '/pages/check-order/orderprocessreportdetail?orderId=' + item.orderId;
					uni.navigateTo({
						url: url
					})
				} else {
					if (item.orderConfirm == 0) {
						// uni.showModal({
						// 	content: '确定接受该维修任务？',
						// 	showCancel: true,
						// 	success(res) {
						// 		if (res.confirm) {
						// 			let url =
						// 				'/pages/check-order/orderconfirm?id=' + item.orderId;
						// 			uni.navigateTo({
						// 				url: url
						// 			})
						// 		}
						// 	}
						// });
						let url =
							'/pages/check-order/orderconfirm?id=' + item.orderId;
						uni.navigateTo({
							url: url
						})
					} else {
						if (item.myOrder == 1) {
							uni.showModal({
								content: '确定继续进行维修任务填报？',
								showCancel: true,
								success(res) {
									if (res.confirm) {
										let url = '/pages/check-order/orderprocessreport?orderId=' + item.orderId;
										uni.navigateTo({
											url: url
										})
									}
								}
							});
						} else {
							let url = '/pages/check-order/orderprocessreportdetail?orderId=' + item.orderId;
							uni.navigateTo({
								url: url
							})
						}
					}
				}
			},
			// onCheckOrderReportClick(item){
			// 	console.log("order id" + item.orderId)
			// 	var url = '/pages/check-order/orderprocessreport?orderId=' + item.orderId;
			// 	uni.navigateTo({
			// 		url: url
			// 	})
			// },
			// onViewCheckOrderInfoClick(item){
			// 	let url = '/pages/check-order/orderprocessreportdetail?orderId=' + item.orderId;
			// 	uni.navigateTo({
			// 		url: url
			// 	})
			// },
			//录入查询
			search() {
				this.pageCurrent = 1;
				//	console.log(JSON.stringify(res))
				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);
					}
				}
			},
			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)
				})
			},
			getSiteKind(val) {
				let htmltext = '';
				if (val.isRain === 1) {
					htmltext = htmltext + "雨量站";
				}
				if (val.isRiver == 1 || val.isRes == 1) {
					if (htmltext.length > 0) {
						htmltext = htmltext + ' / ';
					}
					htmltext = htmltext + '水位站';
				}
				if (val.isGround == 1) {
					if (htmltext.length > 0) {
						htmltext = htmltext + ' / ';
					}
					htmltext = htmltext + '墒情站';
				}
				if (val.isVideo == 1) {
					if (htmltext.length > 0) {
						htmltext = htmltext + ' / ';
					}
					htmltext = htmltext + '视频站';
				}
				return htmltext;
			},
			getAreaName(item) {
				let htmltext = '';
				if (item.adCity) {
					htmltext = htmltext + item.adCity;
				}
				if (item.adDist) {
					if (htmltext.length > 0) {
						htmltext = htmltext + ' / ';
					}
					htmltext = htmltext + item.adDist;
				}
				return htmltext;
			},
			getPage(params = {}) {
				let that = this;
				const current = this.pageCurrent;
				const size = this.pageSize;
				let postData = Object.assign(params, this.query);
				http.request({
					url: '/galaxy-business/equipment/inspection/rtu/page',
					method: 'GET',
					params: {
						current,
						size,
					},
					data: postData,
				}).then(res => {
					if (res.data != null) {
						//console.log(JSON.stringify(res.data))
						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: darkorange;
		font-size: 0.7rem;
	}

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

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