<template>
	<view class="wrap">
		<uni-nav-bar dark :fixed="true" backgroundColor="#3F9EFF" statusBar="false" left-icon="left" left-text="返回"
			:title="title" @clickLeft="toBack" >
		</uni-nav-bar>
<!-- 		<u-gap height="75px"></u-gap> -->
		<view class="container">
			<uSection title="">
				<uni-search-bar placeholder="请录入测站编码或测站名称" @confirm="search" :focus="false" v-model="searchVal"
					@blur="blur" @focus="focus" @input="input" @cancel="cancel" @clear="clear">
				</uni-search-bar>
			</uSection>
			<uSection title="">
				<uList>
					<uni-list-item v-for="item in list" :key="item.id">
						<!-- 自定义 body -->
						<template v-slot:body>
							<view style="height: 100px;width: 100%;display: flex;flex-direction: column;">
								<view
									style="display: flex;flex-direction: row;width: 100%;justify-content: flex-start;">
									<view
										style="font-size: 1rem;font-weight: bold;white-space: nowrap;overflow: hidden;text-overflow: ellipsis;">
										{{item.rtuName}}
									</view>
								</view>
								<view style="margin-top: 10rpx;">
									<text style="font-size: 0.9rem;color: gray;">{{item.rtuCode}}</text>
								</view>
								<view
									style="margin-top: 10rpx;padding-left: 0rpx;padding-right: 0rpx;display: flex;flex-direction: row;justify-content: center;">
									<view v-if="item.reportStatus == 0" style="width: 100%;">
										<button style="background-color: lightblue;" type="default"
											@click="openPage(item.rtuCode)">开始填报</button>
									</view>
									<view v-if="item.reportStatus == 1" style="width: 100%;">
										<button type="default" @click="toPlanClose(item.id)">已提交</button>
									</view>
								</view>
							</view>

						</template>
					</uni-list-item>
				</uList>
			</uSection>
			<uGroup>
				<view class="uni-pagination-box">
					<uni-pagination show-icon :page-size="pageSize" :current="pageCurrent" :total="total"
						@change="change" />
				</view>
			</uGroup>
		</view>

		<u-gap height="70"></u-gap>
	</view>
</template>

<script>
	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 uGroup from '@/uni_modules/uni-group/uni-group.vue'
	import uSection from '@/uni_modules/uni-section/uni-section.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'
	import http from '@/http/api.js';
	export default {
		components: {
			uNavBar,
			uList,
			uListItem,
			uIcons,
			uGroup,
			uSection,
		},
		onLoad(option) {
			this.planId = option.id;
			this.getProjectTree();
		},
		data() {
			return {
				planId: 0,
				orgId: '',
				projectId: '',
				list: [],
				title: '测站巡检填报管理',
				desc: '',
				pageSize: 10,
				// 当前页
				pageCurrent: 1,
				// 数据总量
				total: 0,
				projectTree: [],
				selectedTreeNode: '',
				searchVal: '',
			}
		},
		computed: {
			getIcon() {
				return path => {
					return 'https://cdn.uviewui.com/uview/example/' + path + '.png';
				}
			},
		},
		onShow() {
			// uni.setNavigationBarTitle({
			// 	title: ""
			// });
			//this.getProjectTree();
			//this.getRtuList();
		},

		methods: {
			toBack() {
				uni.navigateBack({
					delta: 1
				})
			},
			// 分页触发
			change(e) {
				//this.$refs.table.clearSelection()
				//this.selectedIndexs.length = 0
				this.pageCurrent = e.current;
				this.getRtuList()
			},
			onnodeclick(node) {
				this.orgId = node.orgId;
				this.projectId = node.projectId;
				console.log('1111111orgId:', this.orgId);
				console.log('1111111projectId:', this.projectId);

			},
			onpopupopened(e) {
				//console.log('popupopened');
			},
			onpopupclosed(e) {
				//	console.log('popupclosed');
			},
			onchange(e) {
				console.log('onchange:', e.detail.value);
				this.searchVal = '';
				this.pageCurrent = 1;
				// this.orgId = e.detail.orgId;
				// this.projectId = e.detail.projectId;

				// 	if (e.detail.value.length > 0) {
				// 		let ids = this.selectedTreeNode.split("-");
				// 		this.orgId = ids[0];
				// 		if (ids[1] === '0') {
				// 			this.projectId = '';
				// 		} else {
				// 			this.projectId = ids[1];
				// 		}
				// console.log('1111111orgId:', this.orgId);
				// console.log('1111111projectId:', this.projectId);


				// 	} else {
				// 		this.orgId = '';
				// 		this.projectId = '';


				// 	}

				this.getRtuList();
			},
			search(res) {
				// uni.showToast({
				// 	title: '搜索：' + res.value,
				// 	icon: 'none'
				// })

				this.getRtuList();
			},
			input(res) {
				//	console.log('----input:', res)
			},
			clear(res) {
				// uni.showToast({
				// 	title: 'clear事件，清除值为：' + res.value,
				// 	icon: 'none'
				// })
				this.searchVal = '';
				this.getRtuList();
			},
			blur(res) {
				// uni.showToast({
				// 	title: 'blur事件，输入值为：' + res.value,
				// 	icon: 'none'
				// })
			},
			focus(e) {
				// uni.showToast({
				// 	title: 'focus事件，输出值为：' + e.value,
				// 	icon: 'none'
				// })
			},
			cancel(res) {
				// uni.showToast({
				// 	title: '点击取消，输入值为：' + res.value,
				// 	icon: 'none'
				// })
				this.searchVal = '';
				this.getRtuList();
			},
			onBackPress() {
				// #ifdef APP-PLUS
				plus.key.hideSoftKeybord();
				// #endif
			},
			getProjectTree() {
				var that = this;
				http.request({
					url: '/galaxy-test/rtu/manage/tree',
					method: 'GET',
				}).then(res => {
					console.log(res)
					if (res.data != null) {
						that.projectTree = res.data;
						console.log("ffffffff " + that.projectTree[0].orgId)
						that.selectedTreeNode = that.projectTree[0].value;
						that.orgId = that.projectTree[0].orgId;
						that.projectId = that.projectTree[0].projectId;

						//that.getRtuList();
					}
				}).catch(err => {
					console.log(err)
				})
			},
			getRtuList(res) {
				// uni.showToast({
				// 	title: '搜索：' + res.value,
				// 	icon: 'none'
				// })
				this.getRtuList();
			},
			getRtuList() {
				var that = this;
				const current = this.pageCurrent;
				const size = this.pageSize;
				const isSubmit = '0';
				var postData = {};

				postData['id'] = this.planId;
				postData['orgId'] = this.orgId;
				postData['projectId'] = this.projectId;

				console.log(postData)

				http.request({
					url: '/galaxy-test/equipment/inspection/plan/my/rtu/page',
					method: 'GET',
					params: {
						current,
						size,
						isSubmit
					},
					data: postData,
				}).then(res => {
					console.log(res)
					if (res.data.records != null) {
						that.list = res.data.records;
					}
					this.total = res.data.total;
				}).catch(err => {
					console.log(err)
				})
			},
			openPage(rtuCode) {
				var url = '/pages/equipment-inspection/equipmentinspectionreport?planId=' + this.planId +
					'&rtuCode=' +
					rtuCode;
				uni.navigateTo({
					url: url
				})
			},
			toPlanClose(id) {

			},
		}
	}
</script>

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

<style lang="scss" scoped>
	.container {
		padding: 0 0 150rpx;
	}

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