<!--
 * @Title: 
 * @Description: 当前维修任务列表
 * @Author: swp
 * @Date: 2022-08-24 10:49:21
 * @LastEditors: 
 * @LastEditTime: 2022-08-24 10:49:21
-->
<template>
	<view class="wrap">
		<uni-nav-bar dark :fixed="true" backgroundColor="#3F9EFF" statusBar="false" left-icon="left" left-text="返回"
			@clickLeft="toBack">
			<view class="nav-title">
				<text>{{title}}</text>
			</view>
		</uni-nav-bar>
		<view class="container">
			<view v-if="addType==1" class="view-flex-inline-center">
				<view style="width: 90%;margin-top: 20px;margin-bottom: 20px;">
					<button type="warn" @click="onServicePersonAddClick">
						<uni-icons class="input-uni-icon" type="plusempty" size="18" color="#ffffff" />
						<text style="color: #ffffff;font-size: 1rem;margin-left: 5px;">添加</text>
					</button>
				</view>
			</view>
			<uni-section title="查询条件" type="line">
				<view class="search-block">
					<view class="rtu-name">
						<uni-easyinput :styles="inputStyles" @input="searchNameValClear" prefixIcon="search"
							v-model="searchNameVal" placeholder="请输入姓名">
						</uni-easyinput>
					</view>
					<view style="margin-top: 10px;padding-left: 0px;padding-right: 0px;">
						<view class="select-checkbox">
							<uni-data-checkbox v-model="personPostOption" :localdata="personPostItems">
							</uni-data-checkbox>
						</view>
					</view>
					<view class="submit-btn">
						<button type="default" @click="search">查 询</button>
					</view>
				</view>
			</uni-section>
			<uni-section title="人员信息" type="line">
				<uni-list>
					<uni-list-item v-for="item in list" :key="item.id">
						<template v-slot:body>
							<view class="list-item-block">
								<view class="line">
									<text class="title">{{item.personName}}</text>
								</view>
								<view class="line">
									<uni-icons class="input-uni-icon" type="person-filled" size="18"
										color="lightblue" />
									<text class="text">岗位：{{item.postName}}</text>
								</view>
								<view class="line">
									<uni-icons class="input-uni-icon" type="phone" size="18" color="lightblue" />
									<text class="text">电话：{{item.contactPhone}}</text>
								</view>
								<view class="line">
									<uni-icons class="input-uni-icon" type="email" size="18" color="lightblue" />
									<text class="text">邮箱：{{item.mail}}</text>
								</view>
								<view v-if="addType==1" class="item-button-group">
									<view class="item-button" @click="onEditClick(item.id)">
										<view class="items-line">
											<uni-icons class="input-uni-icon" type="phone" size="18" color="coral" />
											<text class="button-text">修改</text>
										</view>
									</view>
									<view class="item-button" style="background-color:lightblue"
										@click="onDelClick(item.id)">
										<view class="items-line">
											<uni-icons class="input-uni-icon" type="info" size="18" color="coral" />
											<text class="button-text">删除</text>
										</view>
									</view>
								</view>
							</view>
						</template>
					</uni-list-item>
				</uni-list>
				<uni-group>
					<view class="pagination-block">
						<uni-pagination show-icon :pageSize="pageSize" :current="pageCurrent" :total="total"
							@change="pageChange" />
					</view>
				</uni-group>
			</uni-section>
		</view>
	</view>
</template>

<script>
	import {
		role
	} from "@/api/role.js";
	import http from '@/http/api.js';

	export default {
		components: {

		},
		data() {
			return {
				title: '',
				searchorderstatus: ['0'],
				searchwarnstatus: [],
				personPostItems: [{
					'value': 0,
					'text': '全部'
				}, {
					'value': 1,
					'text': '工程师'
				}, {
					'value': 2,
					'text': '服务员'
				}],
				personPostOption: 0,
				countInfo: {
					orderCount: 0,
					orderUnconfirm: 0,
					orderProcessing: 0,
					reportOrder: 0
				},
				warnKindItems: [{
					'value': 0,
					'text': '全部'
				}, {
					'value': 1,
					'text': '离线'
				}, {
					'value': 2,
					'text': '时钟异常'
				}, {
					'value': 3,
					'text': '雨量漏报'
				}, {
					'value': 4,
					'text': '水位漏报'
				}, {
					'value': 5,
					'text': '5分钟上报延时'
				}, {
					'value': 6,
					'text': '雨量小时上报延时'
				}, {
					'value': 7,
					'text': '水位小时上报延时'
				}, {
					'value': 8,
					'text': '雨量疑似异常值'
				}],
				warnKindOption: 0,
				selectUnconfirm: 0,
				selectProcess: 0,
				pageSize: 10,
				pageCurrent: 1,
				total: 0,
				list: [],
				regionTree: [],
				regionCode: '',
				selectedTreeNode: '',
				searchNameVal: '',
				searchRtuCodeVal: '',
				query: {},
				inputStyles: {
					color: '#808080',
					borderColor: '#d3d3d3'
				},
				addType: 0,
			}
		},
		computed: {

		},
		onLoad(option) {
			this.addType = option.add;
			if (this.addType == 0) {
				this.title = '人员通讯表';
			} else if (this.addType == 1) {
				this.title = '人员管理';
			}
			this.pageCurrent = 1;
			this.getPage()
		},
		onShow() {
            this.getPage();
		},
		methods: {
			//返回上一页
			toBack() {
				uni.navigateBack({
					delta: 1
				})
			},
			onBackPress() {
				// #ifdef APP-PLUS
				plus.key.hideSoftKeybord();
				// #endif
			},
			// 分页触发
			pageChange(e) {
				this.pageCurrent = e.current;
				this.getPage()
			},
			onServicePersonAddClick() {
				let url = '/pages/serviceperson/servicepersonadd';
				uni.navigateTo({
					url: url
				})
			},
			//行政区划选择
			onTreeNodeClick(node) {
				console.log(JSON.stringify(node))
			},
			onTreePopupOpened(e) {
				console.log(JSON.stringify(e))
			},
			onTreePopupClosed(e) {
				console.log(JSON.stringify(e))
			},
			onTreeChange(e) {
				console.log(JSON.stringify(e))
				let nodes = e.detail.value;
				if (nodes.length > 0) {
					let node = nodes[nodes.length - 1];
					this.regionCode = node.value;
					this.query = {};
					this.query['adCode'] = this.regionCode;
					this.searchRtuNameVal = '';
					this.searchRtuCodeVal = '';

					this.pageCurrent = 1;
					this.getPage();
					this.getCountInfo(this.regionCode);
				} else {
					this.regionCode = '';
					this.query = {};
					this.searchRtuNameVal = '';
					this.searchRtuCodeVal = '';

					this.pageCurrent = 1;
					this.getPage();
					this.getCountInfo(this.regionCode);
				}
			},
			//录入查询
			search() {
				this.pageCurrent = 1;
				let params = {};
				params['postCode'] = this.personPostOption;
				if (this.searchNameVal.length > 0) {
					params['personName'] = this.searchNameVal;
				}
				this.getPage(params);
			},
			searchNameValClear(e) {
				if (e == null || e.length == 0) {
					this.searchNameVal = '';
				}
			},
			searchRtuCodeValClear(e) {
				if (e == null || e.length == 0) {
					this.searchRtuCodeVal = '';
					if (this.searchRtuCodeVal.length == 0) {
						let params = {};
						if (this.searchRtuNameVal.length > 0) {
							params['rtuName'] = this.searchRtuNameVal;
						}
						this.getPage(params);
					}
				}
			},
			call(phone) {
				console.log(phone)
				uni.showModal({
					content: '是否需要拨打[' + phone + ']?',
					showCancel: true,
					success(res) {
						if (res.confirm) {
							uni.makePhoneCall({
								phoneNumber: phone
							});
						}
					}
				});
			},
			onDetailViewClick(id) {
				let url = '/pages/check-order/orderprocessreportdetail?orderId=' + id;
				uni.navigateTo({
					url: url
				})
			},
			onEditClick(id) {
				let url = '/pages/serviceperson/servicepersonedit?id=' + id;
				uni.navigateTo({
					url: url
				})
			},
			onDelClick(id) {
				let that = this;
				let p = {};
				p['ids'] = id;
				http.request({
					url: '/galaxy-business/serviceperson/remove',
					method: 'POST',
					params: p
				}).then(res => {
					if (res.success) {
						uni.showModal({
							content: '操作成功!',
							showCancel: false,
							success(res) {
								// if (res.confirm) {
								// 	that.toBack();
								// }
								that.getPage();
							}
						});
					} else {
						uni.showModal({
							content: '操作失败!',
							showCancel: false,
							success(res) {

							}
						});
					}
				}).catch(err => {
					console.log(err)
				})
			},
			onCheckOrderChangeClick(item) {
				let contactUserName = '无';
				if (item.orderConfirm == 1) {
					contactUserName = item.contactUserName;
				}
				let url = '/pages/check-order/orderprocesschange?orderId=' + item.id + "&contactUserName=" +
					contactUserName;
				uni.navigateTo({
					url: url
				})
			},
			onLocationClick(item) {
				if (item.lat && item.lat) {
					let lat = item.lat;
					let lng = item.lng;
					let name = item.rtuName;
					let add = '';
					if (item.locationDesc) {
						add = item.locationDesc;
					}
					uni.openLocation({
						latitude: Number(lat),
						longitude: Number(lng),
						name: name,
						address: "",
						success() {}
					})
				} else {
					uni.showModal({
						content: '经纬度为空，请确认！',
						showCancel: true,
						success(res) {
							if (res.confirm) {

							}
						}
					});
				}
			},
			onManuallyCloseOrderClick(id) {
				uni.navigateTo({
					url: '/pages/check-order/manuallyclosecheckorder?id=' + id
				})
			},
			onComfireCheckOrderClick(id) {
				let url =
					'/pages/check-order/orderconfirm?id=' + id;
				uni.navigateTo({
					url: url
				})
			},
			orderStatusOptionChange: function(evt) {
				console.log(JSON.stringify(evt))
				console.log(this.orderStatusOption)
				this.pageCurrent = 1;
				let params = {};
				this.getPage(params);
			},
			warnKindOptionChange: function(evt) {
				let params = {};
				this.pageCurrent = 1;
				this.getPage(params);
			},

			getPage(params = {}) {
				const current = this.pageCurrent;
				const size = this.pageSize;
				let postData = Object.assign(params, this.query);
				let that = this;
				http.request({
					url: '/galaxy-business/serviceperson/org/user/page',
					method: 'GET',
					params: {
						current,
						size,
					},
					data: postData,
				}).then(res => {
					if (res.data.records != null) {
						that.list = res.data.records;
					}
					this.total = res.data.total;
				}).catch(err => {
					console.log(err)
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.select-checkbox {
		margin-top: 0px;
		margin-bottom: 5px;
		padding-left: 15px;
	}

	.count-info-line {
		padding-top: 5px;
		padding-bottom: 5px;
		padding-left: 10px;
		padding-right: 10px;
		display: flex;
		flex-direction: row;
		justify-content: flex-start;
		flex-wrap: wrap;
	}

	.count-info-line .orderCount {

		display: flex;
		flex-direction: row;
		align-items: center;

		.name {
			color: dimgray;
			font-size: 0.7rem;
		}

		.count {
			margin-left: 5px;
			color: dodgerblue;
			font-size: 0.7rem;
		}
	}

	.count-info-line .unconfirmOrderCount {

		margin-left: 10px;
		display: flex;
		flex-direction: row;
		align-items: center;

		.name {
			color: dimgray;
			font-size: 0.7rem;
		}

		.count {
			margin-left: 5px;
			color: red;
			font-size: 0.7rem;
		}
	}

	.count-info-line .processOrderCount {
		margin-left: 10px;
		display: flex;
		flex-direction: row;
		align-items: center;

		.name {
			color: dimgray;
			font-size: 0.7rem;
		}

		.count {
			margin-left: 5px;
			color: orange;
			font-size: 0.7rem;
		}
	}

	.count-info-line .reportOrderCount {
		margin-left: 0px;
		display: flex;
		flex-direction: row;
		align-items: center;

		.name {
			color: dimgray;
			font-size: 0.7rem;
		}

		.count {
			margin-left: 5px;
			color: green;
			font-size: 0.7rem;
		}
	}
</style>