<!--
 * @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">
			<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">
								<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>
								<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="loop" size="18" color="lightblue" />
								<text class="item-text-lable">维修状态：</text>
								<text v-if="item.orderStatus==1" class="item-text-content"
									style="color: red;">等待确认</text>
								<text v-if="item.orderStatus==2" class="item-text-content"
									style="color: orange;">处理中</text>
								<text v-if="item.orderStatus==3" class="item-text-content"
									style="color: blue;">已处理</text>
								<text v-if="item.orderStatus==4" class="item-text-content"
									style="color: green;">已完成</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" style="color: red;">{{item.taskProcessDuration}}</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="person" size="18" color="lightblue" />
								<text class="item-text-lable">处理人：</text>
								<text class="item-text-content">{{item.contactUserName}}</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.contactPhone != null"
									@click="call(item.contactPhone)">
									<text class="item-text-content-phone">{{item.contactPhone}}</text>
								</view>
							</view>
							<view v-if="item.orderStatus==3" class="item-button-group">
								<view class="item-button" style="background-color:lightblue"
									@click="onOrderReportItemClick(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>
		</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.type = option.type;
			if (this.type == '1') {
				this.query['orderClose'] = 0;
				this.title = "全部维修任务信息";
			} else if (this.type == '2') {
				this.query['orderStatus'] = 2;
				this.query['orderClose'] = 0;
				this.title = "处理中维修任务信息";
			} else if (this.type == '3') {
				this.query['orderStatus'] = 3;
				this.query['orderClose'] = 0;
				this.title = "已处理维修任务信息";
			}
			let userId = option.userId;
			if (userId) {
				this.query['servicePersonId'] = userId;
			}
			this.pageCurrent = 1;
			this.getPage()
		},
		data() {
			return {
				title: '维修任务信息',
				permission: {
					'admin': false,
					'orgAdmin': false,
					'companyAdmin': false,
					'companyServciePerson': false,
				},
				type: '',
				pageSize: 10,
				pageCurrent: 1,
				total: 0,
				list: [],
				query: {},
				inputStyles: {
					color: '#808080',
					borderColor: '#d3d3d3'
				}
			}
		},
		computed: {},
		onShow() {},
		methods: {
			//返回上一页
			toBack() {
				uni.navigateBack({
					delta: 1
				})
			},
			onBackPress() {
				// #ifdef APP-PLUS
				plus.key.hideSoftKeybord();
				// #endif
			},
			// 分页触发
			pageChange(e) {
				this.pageCurrent = e.current;
				this.getPage()
			},
			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
				})
			},
			onOrderReportItemClick(id) {
				console.log("opne record ", id)
				var url = '/pages/check-order/orderprocessreportdetail?orderId=' + id;
				uni.navigateTo({
					url: url
				})
			},
			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() {}
				})
			},
			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
				})
			},
			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/rtu/check/order/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>

</style>