<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">
			<uSection title="查询" 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="searchVal"
					@blur="blur" @focus="focus" @input="input" @cancel="cancel" @clear="clear">
				</uni-search-bar>
			</view>
			<uSection title="">
				<uni-list>
					<uni-list-item v-for="item in list" :key="item.id">
						<template v-slot:body>
							<view style="min-height: 110px;width: 100%;display: flex;flex-direction: column;">
								<view style="display: flex;flex-direction: row;align-items: center;">
									<image class="order-title-image" style="box-shadow:0 0 2px 2px lightblue"
										src="/static/images/logo_app.png" mode="widthFix">
									</image>
									<text style="margin-left: 5px;font-size: 1rem;font-weight: bold;">{{item.rtuName}}</text>
									<text style="margin-left: 5px;font-size: 0.9rem;">[{{item.rtuCode}}]</text>
								</view>
								
								<view v-if="item.orderClose == 1" style="display: flex;flex-direction: row;align-items: center; ">
									<uIcons class="input-uni-icon" type="loop" size="18" color="skyblue" />
									<view style="margin-left:5px;font-size: 0.8rem;">工单状态:</view>
									<view style="margin-left:5px;font-size: 0.8rem;color: coral;">已关闭</view>
								</view>
								<view v-else-if="item.orderConfirm == 1" style="display: flex;flex-direction: row;align-items: center; ">
									<uIcons class="input-uni-icon" type="loop" size="18" color="skyblue" />
									<view style="margin-left:5px;font-size: 0.8rem;">工单状态:</view>
									<view style="margin-left:5px;font-size: 0.8rem;color: coral;">处理中</view>
								</view>
								<view v-else style="display: flex;flex-direction: row;align-items: center; ">
									<uIcons class="input-uni-icon" type="loop" size="18" color="skyblue" />
									<view style="margin-left:5px;font-size: 0.8rem;">工单状态:</view>
									<view style="margin-left:5px;font-size: 0.8rem;color: coral;">等待接单</view>
								</view>
								
								<view style="display: flex;flex-direction: row;align-items: center; min-height: 30px;">
									<uIcons class="input-uni-icon" type="notification" size="18" color="skyblue" />
									<view style="margin-left:5px;font-size: 0.8rem;">报单时间:</view>
									<view style="margin-left:5px;font-size: 0.8rem;color:gray;">{{item.createTime}}
									</view>
								</view>
								
								<view v-if="item.orderConfirm == 1"
									style="display: flex;flex-direction: row;align-items: center; min-height: 30px;">
									<view style="width: 35%;display: flex;flex-direction: row;align-items: center;">
										<uIcons class="input-uni-icon" type="auth" size="18" color="skyblue" />
										<view style="margin-left: 5px;font-size: 0.8rem;color: gray;">
											{{item.processorName}}
										</view>
									</view>
									<view style="font-size: 0.8rem;">接单时间:</view>
									<view style="margin-left:5px;font-size: 0.8rem;color:gray;">
										{{item.orderConfirmTime}}
									</view>
								</view>
								
								<view v-if="item.orderClose == 1"
									style="display: flex;flex-direction: row;align-items: center; min-height: 30px;">
									<uIcons class="input-uni-icon" type="checkbox" size="18" color="skyblue" />
									<view style="margin-left:5px;font-size: 0.8rem;">关闭时间:</view>
									<view style="margin-left:5px;font-size: 0.8rem;color:gray;">{{item.updateTime}}
									</view>
								</view>

							

							<!-- 	<view v-if="item.orderClose == 0"
									style="display:flex;flex-direction:row;align-items: center;">
									<image class="slot-image" src="/static/images/icon_warning.png" mode="widthFix">
									</image>
									<text style="font-size:0.8rem;padding-left: 10rpx;">{{item.orderDesc}}</text>
								</view> -->

								<view
									style="margin-top:4px;display: flex;flex-direction: row;justify-content: flex-end;">
									<view v-if="item.orderClose == 1 || item.orderConfirm == 1"
										style="display:flex;flex-direction: row;justify-content: center;width: 90px;height:28px;margin-right: 10px;border-radius:7px;background-color:lightgreen"
										@click="toDetailPage(item.id)">
										<view style="display:flex;flex-direction: column;justify-content: center;">
											<uIcons class="input-uni-icon" type="info" size="18" color="gray" />
										</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 v-else-if="item.orderConfirm == 1"
										style="display:flex;flex-direction: row;justify-content: center;width: 90px;height:28px;margin-right: 10px;border-radius:7px;background-color:lightblue"
										@click="toOrderReport(item.id)">
										<view style="display:flex;flex-direction: column;justify-content: center;">
											<uIcons class="input-uni-icon" type="compose" size="18" color="gray" />
										</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 v-else
										style="display:flex;flex-direction: row;justify-content: center;width: 90px;height:28px;margin-right: 10px;border-radius:7px;background-color:lightpink"
										@click="toOrderConfirm(item.id)">
										<view style="display:flex;flex-direction: column;justify-content: center;">
											<uIcons class="input-uni-icon" type="location" size="18" color="gray" />
										</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>
			</uSection>
			<uGroup>
				<view class="uni-pagination-box">
					<uPagination show-icon :page-size="pageSize" :current="pageCurrent" :total="total"
						@change="change" />
				</view>
			</uGroup>
		</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 http from '@/http/api.js';

	export default {
		components: {
			uNavBar,
			uList,
			uListItem,
			uIcons,
			uGroup,
			uPagination,
			uBreadcrumb,
			uSection,
			uDataPicker
		},
		onLoad(option) {
			this.getProjectTree();
		},
		data() {
			return {
				list: [],
				title: '工单查询',
				desc: '',
				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() {

		},
		methods: {
			toBack() {
				uni.navigateBack({
					delta: 1
				})
			},
			// 分页触发
			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() {
				const current = this.pageCurrent;
				const size = this.pageSize;
				const isSubmit = '0';
				var postData = {};
				postData['rtuCode'] = this.searchVal;
				postData['rtuName'] = this.searchVal;
				postData['orgId'] = this.orgId;
				postData['projectId'] = this.projectId;
				var that = this;
				http.request({
					url: '/galaxy-test/rtu/check/order/page',
					method: 'GET',
					params: {
						current,
						size,
						isSubmit
					},
					data: postData,
				}).then(res => {
					if (res.data.records != null) {
						that.list = res.data.records;
					}
					this.total = res.data.total;
				}).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>
