<template>
	<view class="wrap">
		<uni-nav-bar dark :fixed="true" backgroundColor="#3F9EFF" statusBar="false" 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>
		</uni-nav-bar>
		<view class="container">
			<uni-segmented-control :current="current" :values="items" @clickItem="onClickItem" styleType="text"
				activeColor="#4cd964"></uni-segmented-control>
			<view class="content">
				<view v-show="current === 0">
					<uGroup>
						<uni-table ref="order_table" border stripe type="" emptyText="暂无更多数据">
							<uni-tr>
								<uni-th width="120" align="center">机构名称</uni-th>
								<uni-th width="120" align="center">工单数量</uni-th>
								<uni-th width="120" align="center">未完成工单</uni-th>
							</uni-tr>
							<uni-tr v-for="(item, index) in orderTableData" :key="index">
								<uni-td>
									<view style="text-align: center;">{{ item.orgName }}</view>
								</uni-td>
								<uni-td align="center">
									<view style="text-align: center;color: coral;">{{ item.orderCount }}</view>
								</uni-td>
								<uni-td align="center">
									<view style="text-align: center;color: coral;">{{ item.processingOrderCount }}
									</view>
								</uni-td>
							</uni-tr>
						</uni-table>
					</uGroup>
				</view>
				<view v-show="current === 1">
					<uGroup>
						<uni-table ref="equipment_inspection_table" border stripe type="" emptyText="暂无更多数据">
							<uni-tr>
								<uni-th width="150" align="center">机构名称</uni-th>
								<uni-th align="center">巡检任务</uni-th>
								<uni-th align="center">已完成巡检任务</uni-th>
							</uni-tr>
							<uni-tr v-for="(item, index) in equipmentInspectionTableData" :key="index">
								<uni-td>
									<view style="text-align: center;">{{ item.orgName }}</view>
								</uni-td>
								<uni-td align="center">
									<view style="text-align: center;color: coral;">{{ item.rtuCount }}</view>
								</uni-td>
								<uni-td align="center">
									<view style="text-align: center;color: coral;">{{ item.completeCount }}</view>
								</uni-td>
							</uni-tr>
						</uni-table>
					</uGroup>
				</view>
			</view>
		</view>
	</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 uSegmentedControl from '@/uni_modules/uni-segmented-control/components/uni-segmented-control/uni-segmented-control.vue'
	import uniTable from '@/uni_modules/uni-table/components/uni-table/uni-table.vue'
	import http from '@/http/api.js';

	export default {
		components: {
			uNavBar,
			uList,
			uListItem,
			uIcons,
			uGroup,
			uPagination,
			uBreadcrumb,
			uSection,
			uDataPicker,
			uSegmentedControl,
			uniTable
		},
		onLoad(option) {

		},
		data() {
			return {
				list: [],
				title: '统计报表',
				items: ['工单统计', '巡检统计'],
				current: 0,
				desc: '',
				orderTableData: [],
				equipmentInspectionTableData: [],
				pageSize: 10,
				// 当前页
				pageCurrent: 1,
				// 数据总量
				total: 0,
				orgId: '',
				projectId: '',
				projectTree: [],
				selectedTreeNode: '',
				searchVal: '',
			}
		},
		computed: {
			getIcon() {
				return path => {
					return 'https://cdn.uviewui.com/uview/example/' + path + '.png';
				}
			},
		},
		onShow() {
			this.getOrderList();
			this.getInspectionCountList();
		},
		methods: {
			toBack() {
				uni.navigateBack({
					delta: 1
				})
			},
			onClickItem(e) {
				if (this.current != e.currentIndex) {
					this.current = e.currentIndex;
				}
			},
			// 分页触发
			change(e) {
				//this.$refs.table.clearSelection()
				//this.selectedIndexs.length = 0
				this.pageCurrent = e.current;
				this.getOrderList()

			},
			onnodeclick(node) {

				if (node.projectId != null) {
					this.orgId = node.orgId;
					this.projectId = node.projectId;
					this.searchVal = '';
					this.pageCurrent = 1;
					this.getOrderList();
				}
			},
			onpopupopened(e) {

			},
			onpopupclosed(e) {

			},
			onchange(e) {

			},
			search(res) {
				this.getOrderList();
			},
			input(res) {

			},
			clear(res) {
				this.searchVal = '';
				this.getOrderList();
			},
			blur(res) {},
			focus(e) {},
			cancel(res) {
				this.searchVal = '';
				this.getOrderList();
			},
			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;
						that.selectedTreeNode = that.projectTree[0].value;
						that.orgId = that.projectTree[0].orgId;
						that.projectId = that.projectTree[0].projectId;
						that.getOrderList();
					}
				}).catch(err => {
					console.log(err)
				})
			},
			getOrderList() {
				var that = this;
				http.request({
					url: '/galaxy-test/rtu/check/order/org/statistics',
					method: 'GET',
				}).then(res => {
					if (res.data != null) {
						that.orderTableData = res.data;
					}
				}).catch(err => {
					console.log(err)
				})
			},
			getInspectionCountList() {
				var that = this;
				http.request({
					url: '/galaxy-test/equipment/inspection/org/statistics',
					method: 'GET',
				}).then(res => {
					if (res.data != null) {
						that.equipmentInspectionTableData = res.data;
					}
				}).catch(err => {
					console.log(err)
				})
			},
			toDetailPage(id) {
				var url = '/pages/check-order/orderprocessrecord?id=' + id;
				uni.navigateTo({
					url: url
				})
			},
			toOrderReport(id) {
				var url = '/pages/check-order/orderprocesslist?id=' + id;
				uni.navigateTo({
					url: url
				})
			},
			toOrderConfirm(id) {
				var that = this;
				uni.showModal({
					content: '确定进行接单确认操作？',
					showCancel: true,
					success(res) {
						if (res.confirm) {
							var postData2 = {};
							postData2['id'] = id;
							http.request({
								url: '/galaxy-test/rtu/check/order/confirm',
								method: 'POST',
								data: postData2
							}).then(res => {
								console.log(res)
								if (res.success) {
									uni.showModal({
										content: '接单已成功，是否立即填报？',
										showCancel: true,
										success(res) {
											if (res.confirm) {
												var url =
													'/pages/check-order/orderprocesslist?id=' + id;
												uni.navigateTo({
													url: url
												})
											}
										}
									});
								}
							}).catch(err => {
								console.log(err)
							})
						}
					}
				});
			},
			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() {}
				})
			},
		}
	}
</script>

<style>

</style>

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

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

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

	}

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