<template>
	<view class="wrap">
		<uNavBar dark :fixed="true" backgroundColor="#3F9EFF" status-bar left-icon="left" left-text="返回"
			@clickLeft="toBack">
			<view style="width: 100%;display: flex;flex-direction: row;justify-content: center;align-items: center;">
				<text style="color: white;font-size: 1rem;">{{title}}</text>
			</view>
		</uNavBar>
		<view class="container">
			<uni-section 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>
			</uni-section>
			<uni-section title="">
				<uni-search-bar placeholder="请录入测站编码或测站名称" @confirm="search" :focus="false" v-model="searchValue"
					@blur="blur" @focus="focus" @input="input" @cancel="cancel" @clear="clear">
				</uni-search-bar>
			</uni-section>
			<uni-section title="">
				<uni-table ref="table" :loading="loading" border stripe type="" emptyText="暂无更多数据">
					<uni-tr>
						<uni-th width="120" align="center">上报时间</uni-th>
						<uni-th align="center">测站名称</uni-th>
						<uni-th width="120" align="center">水位</uni-th>
					</uni-tr>
					<uni-tr v-for="(item, index) in tableData" :key="index">
						<uni-td>
							<view style="text-align: center;">{{ item.tm }}</view>
						</uni-td>
						<uni-td>
							<view v-if="item.rtuName" style="text-align: center;">
								{{ item.rtuName }}
							</view>
							<view v-else style="text-align: center;">
								{{ item.rtuCode }}
							</view>
						</uni-td>
						<uni-td align="center">
							<view style="text-align: center;color: coral;">{{ item.z }}</view>
						</uni-td>
					</uni-tr>
				</uni-table>
				<view style="margin-top: 5px;background-color: azure;">
					<uniPagination show-icon :page-size="pageSize" :current="pageCurrent" :total="total"
						@change="change" />
				</view>
			</uni-section>
		</view>
	</view>
</template>

<script>
	import uniSearchBar from '@/uni_modules/uni-search-bar/components/uni-search-bar/uni-search-bar.vue'
	import uNavBar from '@/uni_modules/uni-nav-bar/components/uni-nav-bar/uni-nav-bar.vue'
	import uniDataPicker from '@/uni_modules/uni-data-picker/components/uni-data-picker/uni-data-picker.vue'
	import uniGroup from '@/uni_modules/uni-group/uni-group.vue'
	import uniSection from '@/uni_modules/uni-section/uni-section.vue'
	import uniTable from '@/uni_modules/uni-table/components/uni-table/uni-table.vue'
	import uniPagination from '@/uni_modules/uni-pagination/components/uni-pagination/uni-pagination.vue'
	import uniBreadcrumb from '@/uni_modules/uni-breadcrumb/components/uni-breadcrumb/uni-breadcrumb.vue'
	import http from '@/http/api.js';
	import tableData from './data.js'
	export default {
		components: {
			uniSearchBar,
			uniGroup,
			uniSection,
			uniTable,
			uniPagination,
			uniBreadcrumb,
			uNavBar,
		},
		onLoad(option) {
			this.selectedIndexs = [];
			this.getProjectTree();
		},
		data() {
			return {
				selectedTreeNode: '',
				orgId: '',
				projectId: '',
				title: '河道水情实时数据',
				desc: '',
				searchValue: '',
				tableData: [],
				// 每页数据量
				pageSize: 10,
				// 当前页
				pageCurrent: 1,
				// 数据总量
				total: 0,
				loading: false,
				selectedIndexs: [],
				projectTree: [],
			}
		},
		computed: {
			getIcon() {
				return path => {
					return 'https://cdn.uviewui.com/uview/example/' + path + '.png';
				}
			},
		},
		onShow() {},
		methods: {
			toBack() {
				uni.navigateBack({
					delta: 1
				})
			},
			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.getData();
					}
				}).catch(err => {
					console.log(err)
				})
			},
			onnodeclick(e) {
				this.orgId = node.orgId;
				this.projectId = node.projectId;
				this.searchValue = '';
				this.pageCurrent = 1;
				this.getData();
			},
			onpopupopened(e) {
				//console.log('popupopened');
			},
			onpopupclosed(e) {
				//	console.log('popupclosed');
			},
			onchange(e) {

			},
			openProjectSelect() {

			},
			// 多选处理
			selectedItems() {
				return this.selectedIndexs.map(i => this.tableData[i])
			},
			// 多选
			// selectionChange(e) {
			// 	console.log(e.detail.index)
			// 	this.selectedIndexs = e.detail.index
			// },
			//批量删除
			delTable() {
				//console.log(this.selectedItems())
			},
			// 分页触发
			change(e) {
				this.$refs.table.clearSelection()
				this.selectedIndexs.length = 0
				this.pageCurrent = e.current;
				this.getData(e.current)
			},
			// 获取数据
			getData() {
				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/data/river/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
				})
			},
			search(res) {
				this.getData();
			},
			input(res) {
				//	console.log('----input:', res)
			},
			clear(res) {
				this.getData();
			},
			blur(res) {

			},
			focus(e) {

			},
			cancel(res) {
				this.getData();
			},
			onBackPress() {
				// #ifdef APP-PLUS
				plus.key.hideSoftKeybord();
				// #endif
			},
		}
	}
</script>

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

<style lang="scss" scoped>
	.wrap {
		padding: 0 0 100rpx;
	}
	
	.container {
		background-color: #f7f7f7;
		min-height: 100vh;
		overflow: hidden;
	}


	.goods-carts {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: column;
		position: absolute;
		left: 0;
		right: 0;
		/* #ifdef H5 */
		left: var(--window-left);
		right: var(--window-right);
		/* #endif */
		top: 0;
	}

	.button {
		display: flex;
		align-items: center;
		height: 35px;
		margin-left: 10px;
	}

	.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: 30px;
		height: 30px;
	}

	.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;
	}

	.uni-group {
		display: flex;
		align-items: center;
	}

	.data-pickerview {
		height: 400px;
		border: 1px #e5e5e5 solid;
	}

	.popper__arrow {
		top: -6px;
		left: 50%;
		margin-right: 3px;
		border-top-width: 0;
		border-bottom-color: #EBEEF5;
	}

	.popper__arrow {
		top: -6px;
		left: 50%;
		margin-right: 3px;
		border-top-width: 0;
		border-bottom-color: #EBEEF5;
	}
</style>
