<template>
	<view class="wrap">
		<uNavBar :fixed="true" backgroundColor="#3F9EFF" statusBar="false" height="75px">
			<block slot="left">
				<view style="display: flex;flex-direction: column;justify-content: center;">
					<image src="/static/images/nav_logo.png" class="logo" mode="widthFix"></image>
				</view>
			</block>
			<view style="width:100%;display: flex;flex-direction: row;justify-content: center;align-items: center;">
				<text style="color: #ffffff; font-size: 1rem;font-family: Microsoft YaHei;">{{title}}</text>
			</view>
		</uNavBar>
		<view class="container">
			<uSection title="查询" titleFontSize="0.8rem" type="line" style="padding-left: 10px;padding-right: 10px;">
				<uni-data-picker placeholder="请选择机构" popup-title="请选择所在地区" :localdata="projectTree"
					v-model="selectedTreeNode" @change="onchange" @nodeclick="onnodeclick" @popupopened="onpopupopened"
					@popupclosed="onpopupclosed">
				</uni-data-picker>
			</uSection>
			<view>
				<uni-search-bar placeholder="请录入测站编码或测站名称" @confirm="search" :focus="false" v-model="searchValue"
					@blur="blur" @focus="focus" @input="input" @cancel="cancel" @clear="clear">
				</uni-search-bar>
			</view>
			<uSection title="">
				<uni-list>
					<uni-list-item v-for="(item, index) in tableData" :key="index">
						<template v-slot:body>
							<view style="height: 125px;width: 100%;display: flex;flex-direction: column;">
								<!-- 测站名称 -->
								<view
									style="height:22%; width:100%;display:flex;flex-direction: row;justify-content: flex-start;align-items: center;">
									<image class="order-title-image" style="box-shadow:0 0 2px 2px lightblue"
										src="/static/images//manage//site.png" mode="widthFix">
									</image>
									<text style="margin-left: 10rpx; font-size: 1rem;font-weight: bold;">{{item.rtuName}}</text>
									<text
										style="margin-left:8rpx;font-size: 0.9rem;color:grey;">[{{item.rtuCode}}]</text>
								</view>
								<!-- 运行状态 -->
								<view
									style="height:18%;width: 100%;display: flex;flex-direction: row;align-items: center;">
									<view v-if="item.runStatusId==1"
										style="display: flex; flex-direction: row;align-items: center;">
										<image class="slot-image" src="/static/images/icon_warning.png" mode="widthFix">
										</image>
										<text style="color: orangered;font-size:0.7rem">预警</text>
									</view>
									<view v-else style="display: flex; flex-direction: row;align-items: center;">
										<image class="slot-image" src="/static/images/tabbar/demo_selected.png"
											mode="widthFix">
										</image>
										<text style="color: green;font-size:0.7rem">正常</text>
									</view>
									<text style="margin-left: 10px;color:gray;font-size:0.7rem;">最近上报时间</text>
									<text
										style="margin-left: 4px;color:gray;font-size:0.7rem;">{{item.lastUpTime}}</text>
								</view>
								<!-- 测站类型 -->
								<view
									style="height:18%;width: 100%;display: flex;flex-direction:row;justify-content: flex-start;align-items: center;">
									<text style="color:gray;font-size:0.7rem;margin-right: 5px;">测站类型:</text>
									<view v-if="item.isRain===1">
										<text style="color:gray;font-size:0.7rem">雨量站</text>
									</view>
									<view v-if="item.isRiver===1">
										<text v-if="item.isRain===1"
											style="margin-left:2px;margin-right:2px;color:skyblue;font-size:0.7rem">
											/
										</text>
										<text style="color:gray;font-size:0.7rem">河道站</text>
									</view>
									<view v-if="item.isRes===1">
										<text v-if="item.isRain===1 || item.isRiver===1"
											style="margin-left:2px;margin-right:2px;color:skyblue;font-size:0.7rem">
											/
										</text>
										<text style="color:gray;font-size:0.7rem">水库站</text>
									</view>
								</view>
								<!-- 业务数据 -->
								<view
									style="height:18%;display: flex;flex-direction:row;justify-content: flex-start;align-items: center;">
									<view>
										<text style="color:gray;font-size:0.6rem;margin-right: 5px;">实时数据:</text>
									</view>
									<view v-if="item.isRain===1">
										<text style="color:gray;font-size:0.6rem">降水(mm)</text>
										<text v-if="item.drp"
											style="margin-left:2px;color:gray;font-size:0.6rem">:{{item.drp}}</text>
										<text v-else style="margin-left:2px;color:gray;font-size:0.6rem">:</text>
									</view>
									<view v-if="item.isRiver===1">
										<text v-if="item.isRain===1"
											style="margin-left:2px;margin-right:2px;color:skyblue;font-size:0.6rem">
											/
										</text>
										<text style="color:gray;font-size:0.6rem">水位(m)</text>
										<text v-if="item.z"
											style="margin-left:2px;color:gray;font-size:0.6rem">:{{item.z}}</text>
										<text v-else style="margin-left:2px;color:gray;font-size:0.6rem">: </text>

									</view>
									<view v-if="item.isRes===1">
										<text v-if="item.isRain===1 || item.isRiver===1"
											style="margin-left:2px;margin-right:2px;color:skyblue;font-size:0.6rem">
											/
										</text>
										<text style="color:gray;font-size:0.6rem">库上水位(m)</text>
										<text v-if="item.rz"
											style="margin-left:2px;color:gray;font-size:0.6rem">:{{item.rz}}</text>
										<text v-else style="margin-left:2px;color:gray;font-size:0.6rem">: </text>

									</view>
								</view>
								<!-- 操作 -->
								<view
									style="height:22%;padding-top:4px;display:  flex;flex-direction: row;justify-content: flex-end;">
									<view
										style="display:flex;flex-direction: row;justify-content: center;width: 90px;height:28px;margin-right: 10px;border-radius:7px;background-color:lightblue"
										@click="toWarningPage(item.rtuCode)">
										<view style="display:flex;flex-direction: column;justify-content: center;">
											<uIcons class="input-uni-icon" type="notification" size="18"
												color="coral" />
										</view>
										<view
											style="display:flex;flex-direction: column;justify-content: center;padding-left:5px;">
											<text style="color:black;font-size:0.7rem">预警信息</text>
										</view>
									</view>
									<view
										style="display:flex;flex-direction: row;justify-content: center;width: 90px;height:28px;margin-right: 10px;border-radius:7px;background-color:lightblue"
										@click="toCheckOrderPage(item.rtuCode)">
										<view style="display:flex;flex-direction: column;justify-content: center;">
											<uIcons class="input-uni-icon" type="gear" size="18" color="coral" />
										</view>
										<view
											style="display:flex;flex-direction: column;justify-content: center;padding-left:5px;">
											<text style="color:black;font-size:0.7rem">工单管理</text>
										</view>
									</view>
									<view
										style="display:flex;flex-direction: row;justify-content: center;width: 90px;height:28px;margin-right: 10px;border-radius:7px;background-color:lightblue"
										@click="toLocation(item)">
										<view style="display:flex;flex-direction: column;justify-content: center;">
											<uIcons class="input-uni-icon" type="location" size="18" color="coral" />
										</view>
										<view
											style="display:flex;flex-direction: column;justify-content: center;padding-left:5px;">
											<text style="color:black;font-size:0.7rem">导航</text>
										</view>
									</view>
								</view>
							</view>
						</template>
					</uni-list-item>
				</uni-list>
				<uGroup>
					<view class="uni-pagination-box">
						<uni-pagination show-icon :page-size="pageSize" :current="pageCurrent" :total="total"
							@change="change" />
					</view>
				</uGroup>
			</uSection>
		</view>
	</view>
</template>

<script>
	import http from '@/http/api.js';
	import uSearchBar from '@/uni_modules/uni-search-bar/components/uni-search-bar/uni-search-bar.vue'
	import uGroup from '@/uni_modules/uni-group/uni-group.vue'
	import uSection from '@/uni_modules/uni-section/uni-section.vue'
	import uNavBar from '@/uni_modules/uni-nav-bar/components/uni-nav-bar/uni-nav-bar.vue'
	import uDataPicker from '@/uni_modules/uni-data-picker/components/uni-data-picker/uni-data-picker.vue'
	import uTable from '@/uni_modules/uni-table/components/uni-table/uni-table.vue'
	import uPagination from '@/uni_modules/uni-pagination/components/uni-pagination/uni-pagination.vue'
	import uBreadcrumb from '@/uni_modules/uni-breadcrumb/components/uni-breadcrumb/uni-breadcrumb.vue'
	import uList from '@/uni_modules/uni-list/components/uni-list/uni-list.vue'
	import uListItem from '@/uni_modules/uni-list/components/uni-list-item/uni-list-item.vue'
	import uIcons from '@/uni_modules/uni-icons/components/uni-icons/uni-icons.vue'
	export default {
		name: '',
		components: {
			uGroup,
			uSection,
			uNavBar,
			uDataPicker,
			uList,
			uListItem,
			uTable,
			uBreadcrumb,
			uPagination,
			uIcons,
		},
		onLoad(option) {
			this.getProjectTree();
		},
		data() {
			return {
				title: '管理工作台',
				desc: '',
				tableData: [],
				// 每页数据量
				pageSize: 10,
				// 当前页
				pageCurrent: 1,
				// 数据总量
				total: 0,
				loading: false,
				selectedIndexs: [],
				projectTree: [],
				orgId: '',
				projectId: '',
				searchValue: '',
				selectedTreeNode: '',
			}
		},
		computed: {
			getIcon() {
				return path => {
					return 'https://cdn.uviewui.com/uview/example/' + path + '.png';
				}
			},
		},
		onShow() {
			this.loadList();
		},
		methods: {
			onnodeclick(node) {
				if (node.projectId != null) {
					this.orgId = node.orgId;
					this.projectId = node.projectId;
					this.searchValue = '';
					this.pageCurrent = 1;
					this.loadList();
				}
			},
			onpopupopened(e) {

			},
			onpopupclosed(e) {

			},
			onchange(e) {
               console.log("onchange++++++"+e)
			},
			// 分页触发
			change(e) {
				//this.$refs.table.clearSelection()
				this.selectedIndexs.length = 0
				this.pageCurrent = e.current;
				this.loadList()
			},
			search(res) {
				this.loadList();
			},
			input(res) {

			},
			clear(res) {
				this.searchVal = '';
				this.loadList();
			},
			blur(res) {

			},
			focus(e) {

			},
			cancel(res) {
				this.searchVal = '';
				this.loadList();
			},
			onBackPress() {
				// #ifdef APP-PLUS
				plus.key.hideSoftKeybord();
				// #endif
			},
			getProjectTree() {
				var that = this;
				http.request({
					url: '/galaxy-test/rtu/manage/tree',
					method: 'GET',
				}).then(res => {
					if (res.data != null) {
						that.projectTree = res.data;
						that.selectedTreeNode = that.projectTree[0].value;
						that.orgId = that.projectTree[0].orgId;
						that.projectId = that.projectTree[0].projectId;
						that.loadList();
					}
				}).catch(err => {
					console.log(err)
				})
			},
			loadList() {
				this.loading = true
				const current = this.pageCurrent;
				const size = this.pageSize;
				const isSubmit = '0';
				var formData = {};
				formData['rtuName'] = this.searchValue;
				formData['projectId'] = this.projectId;
				formData['orgId'] = this.orgId;
				var that = this;
				http.request({
					url: '/galaxy-test/rtu/manage/page',
					method: 'GET',
					params: {
						current,
						size,
						isSubmit
					},
					data: formData,
				}).then(res => {
					if (res.data.records != null) {
						that.tableData = res.data.records;
					}
					that.total = res.data.total;
					this.loading = false
				}).catch(err => {
					console.log(err)
					this.loading = false
				})
			},
			toWarningPage(rtuCode) {
				uni.navigateTo({
					url: '/pages/warning/rtuwarninglist?rtuCode=' + rtuCode
				})
			},
			toLocation(item) {
				let lat = item.lat;
				let lng = item.lng;
				let name = item.rtuName;
				let add = item.locationDesc;
				uni.openLocation({
					latitude: Number(lat),
					longitude: Number(lng),
					name: name,
					address: "",
					success() {}
				})
			},
			toCheckOrderPage(rtuCode) {
				uni.navigateTo({
					url: '/pages/check-order/rtu/rtucheckorderlist?rtuCode=' + rtuCode
				})
			},
		}
	}
</script>

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

<style lang="scss" scoped>
	.logo {
		flex-shrink: 0;
		width: 100rpx;
		height: auto;
	}

	.order-title-image {
		/* #ifndef APP-NVUE */
		display: block;
		/* #endif */
		// margin-right: 10px;
		width: 20px;
		height: 20px;
		border-radius: 50%;

	}

	.u-cell-icon {
		width: 36rpx;
		height: 36rpx;
		margin-right: 8rpx;
	}

	.slot-box {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
		align-items: center;
	}

	.slot-image {
		/* #ifndef APP-NVUE */
		display: block;
		/* #endif */
		margin-right: 10px;
		width: 20px;
		height: 20px;
	}

	.slot-text {
		flex: 1;
		font-size: 14px;
		color: #4cd964;
		margin-right: 10px;
	}

	.content-box {
		flex: 1;
		/* #ifdef APP-NVUE */
		justify-content: center;
		/* #endif */
		height: 100%;
		line-height: 44px;
		padding: 0 15px;
		position: relative;
		background-color: #fff;
		border-bottom-color: #f5f5f5;
		border-bottom-width: 1px;
		border-bottom-style: solid;
	}

	.content-text {
		font-size: 15px;
	}

	.example-body {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
		justify-content: center;
		padding: 10px 0;
		background-color: #fff;
	}

	.button {
		border-color: #e5e5e5;
		border-style: solid;
		border-width: 1px;
		padding: 4px 8px;
		border-radius: 4px;
	}

	.button-text {
		font-size: 15px;
	}

	.slot-button {
		/* #ifndef APP-NVUE */
		display: flex;
		height: 100%;
		/* #endif */
		flex: 1;
		flex-direction: row;
		justify-content: center;
		align-items: center;
		padding: 0 20px;
		background-color: #ff5a5f;
	}

	.slot-button-text {
		color: #ffffff;
		font-size: 14px;
	}

	.search-result {
		padding-top: 10px;
		padding-bottom: 20px;
		text-align: center;
	}

	.search-result-text {
		text-align: center;
		font-size: 14px;
		color: #666;
	}

	.example-body {
		/* #ifndef APP-NVUE */
		display: block;
		/* #endif */
		padding: 0px;
	}

	.uni-mt-10 {
		margin-top: 10px;
	}
</style>
