<!--
 * @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 style="padding-left: 5px;padding-right: 5px;">
				<uni-collapse v-model="value">
					<uni-collapse-item title="异常类别筛选条件" :show-animation="true">
						<view class="select-checkbox">
							<uni-data-checkbox v-model="warnKindOption" :localdata="warnKindItems"
								@change="warnKindOptionChange">
							</uni-data-checkbox>
						</view>
					</uni-collapse-item>
				</uni-collapse>
			</view>
			<uni-list>
				<uni-list-item v-for="item in list" :key="item.id">
					<template v-slot:body>
						<view class="list-item-block">
							<view class="items-line">
								<view class="block">
									<image class="item-title-run-status-icon" style="box-shadow:0 0 2px 2px lightblue"
										src="/static/images/list/order_item.png" mode="widthFix">
									</image>
								</view>
								<text class="item-title-rtu-name">{{item.rtuName}}</text>
								<text class="item-title-rtu-code">[{{item.rtuCode}}]</text>
							</view>
							<view class="items-line">
								<uni-icons class="input-uni-icon" type="location" size="18" color="lightblue" />
								<text class="item-text-lable">行政区划：</text>
								<text class="item-text-content">{{item.areaName}}</text>
							</view>
							<view class="items-line">
								<uni-icons class="input-uni-icon" type="bars" size="18" color="lightblue" />
								<text class="item-text-lable">异常类型：</text>
								<text class="item-text-content-ellipsis">{{item.warnKindInfo}}</text>
							</view>
							<view class="items-line">
								<uni-icons class="input-uni-icon" type="calendar" size="18" color="lightblue" />
								<text class="item-text-lable">任务创建时长：</text>
								<text class="item-text-content">{{item.taskCreateDuration}}</text>
							</view>
							<view class="items-line">
								<uni-icons class="input-uni-icon" type="auth" size="18" color="lightblue" />
								<text class="item-text-lable">运维公司管理员：</text>
								<text class="item-text-content">{{item.manageCompanyAdminName}}</text>
							</view>
							<view class="items-line">
								<uni-icons class="input-uni-icon" type="phone" size="18" color="lightblue" />
								<text class="item-text-lable">联系电话：</text>
								<view v-if="item.manageCompanyAdminPhone != null" @click="call(item.manageCompanyAdminPhone)">
									<text class="item-text-content-phone">{{item.manageCompanyAdminPhone}}</text>
								</view>
							</view>
							<view class="item-button-group">
								<view class="item-button" @click="onLocationClick(item)">
									<view class="items-line">
										<uni-icons class="input-uni-icon" type="location" size="18" color="coral" />
										<text class="button-text">导航</text>
									</view>
								</view>
								<view class="item-button" @click="call(item.manageCompanyAdminPhone)">
									<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" @click="onComfireCheckOrderClick(item.id)">
									<view class="items-line">
										<uni-icons class="input-uni-icon" type="auth" 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>
		</view>
	</view>
</template>

<script>
	import {
		role
	} from "@/api/role.js";
	import http from '@/http/api.js';
	export default {
		components: {},
		onLoad(option) {
			if (this.userInfo.role_name === role['admin']) {
				this.permission.admin = true;
			} else if (this.userInfo.role_name === role['orgAdmin']) {
				this.permission.orgAdmin = true;
			} else if (this.userInfo.role_name === role['companyAdmin']) {
				this.permission.companyAdmin = true;
			} else if (this.userInfo.role_name === role['companyServciePerson']) {
				this.permission.companyServciePerson = true;
			}
			this.query = {};
			this.query['orderConfirm'] = 0;
			this.query['orderClose'] = 0;
			this.getPage();
		},
		data() {
			return {
				title: '新任务',
				permission: {
					'admin': false,
					'orgAdmin': false,
					'companyAdmin': false,
					'companyServciePerson': false,
				},
				value: ['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,
				pageSize: 10,
				pageCurrent: 1,
				total: 0,
				list: [],
				query: {},
			}
		},
		computed: {},
		onShow() {},
		methods: {
			//返回上一页
			toBack() {
				uni.navigateBack({
					delta: 1
				})
			},
			onBackPress() {
				// #ifdef APP-PLUS
				plus.key.hideSoftKeybord();
				// #endif
			},
			// 分页触发
			pageChange(e) {
				this.pageCurrent = e.current;
				this.getPage()
			},
			warnKindOptionChange: function(evt) {
				let params = {};
				this.getPage(params);
			},
			call(phone) {
				console.log(phone)
				uni.showModal({
					content: '是否需要拨打[' + phone + ']?',
					showCancel: true,
					success(res) {
						if (res.confirm) {
							uni.makePhoneCall({
								phoneNumber: phone
							});
						}
					}
				});
			},
			onLocationClick(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() {}
				})
			},
			onComfireCheckOrderClick(id) {
				let url =
					'/pages/check-order/orderconfirm?id=' + id;
				uni.navigateTo({
					url: url
				})
			},
			getPage(params = {}) {
				if (this.warnKindOption == 0) {} else {
					params['warnKind'] = this.warnKindOption;
				}
				const current = this.pageCurrent;
				const size = this.pageSize;
				let postData = Object.assign(params, this.query);
				let that = this;
				http.request({
					url: '/galaxy-business/rtu/check/order/unconfirm/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;
	}
</style>
