<template>
	<view class="container">
		<view class="top_bg" @click="permission = !permission"></view>

		<!-- 状态统计区域 -->
		<view class="top_types" v-if="!permission">
			<view class="types_box">
				<view class="box_num">100</view>
				<view class="box_info">待接单</view>
			</view>

			<view class="types_box">
				<view class="box_num">10</view>
				<view class="box_info">维修中</view>
			</view>
			<view class="types_box">
				<view class="box_num">50</view>
				<view class="box_info">已超时</view>
			</view>
			<view class="types_box">
				<view class="box_num">60</view>
				<view class="box_info">待审核</view>
			</view>
		</view>

		<view class="top_types2" v-else>
			<view class="top">
				<uni-segmented-control :current="current" :values="items" @clickItem="onClickItem" styleType="text" activeColor="#6FB6B8"></uni-segmented-control>
			</view>
			<view class="bottom">
				<view class="bottom_box">
					<view class="box_num">100</view>
					<view class="box_info">工单数</view>
				</view>

				<view class="bottom_box">
					<view class="box_num">10</view>
					<view class="box_info">处理中</view>
				</view>
				<view class="bottom_box">
					<view class="box_num">50</view>
					<view class="box_info">已完成</view>
				</view>
				<view class="bottom_box">
					<view class="box_num">60</view>
					<view class="box_info">已超时</view>
				</view>
				<view class="bottom_box">
					<view class="box_num">60</view>
					<view class="box_info">已完成</view>
				</view>
				<view class="bottom_box">
					<view class="box_num">60</view>
					<view class="box_info">已关单</view>
				</view>
			</view>
		</view>

		<!-- 订单列表区域 -->
		<view class="body" :class="{ body2: permission }">
			<!-- 每一个订单区域 -->
			<view class="body_item" v-for="item in dataList" :key="item.id">
				<!-- 工单编号 -->
				<view class="item_title">
					<img src="../../static/images/repairsImg/order.png" />
					<view class="title_info">工单编号：{{ item.order }}</view>
					<view class="title_type" v-if="item.overtime">超时未接</view>
				</view>
				<!-- 报修时间 -->
				<view class="item_time">
					<view class="time_msg">
						报修时间：
						<text>{{ item.time }}</text>
					</view>
					<view class="time_type" v-if="item.type === 1">待接单</view>
					<view class="time_type color_type" v-if="item.type === 2">维修中</view>

					<view class="time_type color_type2" v-if="item.type === 3">待审核</view>
					<view class="time_type color_type3" v-if="item.type === 4">已完成</view>
					<view class="time_type" v-if="item.type === 5">待确认</view>
					<view class="time_type color_type4" v-if="item.type === 6">已关单</view>
				</view>

				<!-- 报修姓名 -->
				<view class="item_box">
					<view class="box_key">报修姓名：</view>
					<view class="box_value">{{ item.name }}</view>
				</view>

				<!-- 报修电话 -->
				<view class="item_box">
					<view class="box_key">报修电话：</view>
					<view class="box_value phone">
						{{ item.phone }}
						<img src="../../static/images/repairsImg/phone.png" />
					</view>
				</view>

				<!-- 报修区域 -->
				<view class="item_box">
					<view class="box_key">报修区域：</view>
					<view class="box_value">{{ item.area }}</view>
				</view>

				<!-- 详细地址 -->
				<view class="item_box">
					<view class="box_key">详细地址：</view>
					<view class="box_value">{{ item.address }}</view>
				</view>

				<!-- 报修物品 -->
				<view class="item_box">
					<view class="box_key">报修物品：</view>
					<view class="box_value">{{ item.goods }}</view>
				</view>

				<!-- 故障描述 -->
				<view class="item_box">
					<view class="box_key">故障描述：</view>
					<view class="box_value">{{ item.description }}</view>
				</view>

				<!-- 上传图片 -->
				<view class="item_img">
					<view class="img_key">上传图片：</view>
					<view class="img_value"></view>
				</view>

				<!-- 维修师傅 -->
				<view class="item_time" v-if="item.type === 2 || item.type === 3 || item.type === 4 || item.type === 6">
					<view class="time_msg">
						维修师傅：
						<text>{{ item.workerName }}</text>
					</view>
				</view>

				<!-- 师傅电话 -->
				<view class="item_box" v-if="item.type === 2 || item.type === 3 || item.type === 4 || item.type === 6">
					<view class="box_key">师傅电话：</view>
					<view class="box_value phone">
						{{ item.workerPhone }}
						<img src="../../static/images/repairsImg/phone.png" />
					</view>
				</view>

				<!-- 维修费用 -->
				<view class="item_box" v-if="item.type === 3 || item.type === 4">
					<view class="box_key">维修费用：</view>
					<view class="box_value2 phone" @click="checkFeeDetail">
						{{ item.money }}元
						<img src="../../static/images/repairsImg/eye.png" />
					</view>
				</view>

				<!-- 按钮区域 -->
				<view class="item_btn">
					<img v-if="item.type < 3" src="../../static/images/repairsImg/close.png" @click="handleClose" />
					<img class="img" src="../../static/images/repairsImg/help.png" v-if="item.type === 1 && !permission" @click="handleHelp" />
					<view class="btn_box type" v-if="item.type < 3 && permission">延时</view>
					<view class="btn_box type" v-if="item.type === 1">接单</view>
					<view class="btn_box type2" v-if="item.type === 1 && !permission" @click="handleTransferOrder">转单</view>
					<view class="btn_box type2" v-if="item.type === 1 && permission">派单</view>
					<view class="btn_box type" v-if="item.type === 2" @click="handleOffer">报价</view>
					<view class="btn_box type2" v-if="item.type === 2" @click="handleFinish">维修完成</view>

					<view class="btn_box type" v-if="item.type === 3 && permission">审核</view>
					<view class="btn_box type" v-if="item.type === 5">改价</view>
					<view class="btn_box type2" v-if="item.type === 5">留言</view>
				</view>

				<!-- 关闭按钮弹窗 -->
				<uni-popup ref="popup_close" :is-mask-click="false">
					<view class="popup_close">
						<view :class="{ active: activeIndex === 1 }" class="close_box radius" @click="handleChangeItem(1)">重复报单</view>
						<view :class="{ active: activeIndex === 2 }" class="close_box" @click="handleChangeItem(2)">不属于维修范围</view>
						<view :class="{ active: activeIndex === 3 }" class="close_box" @click="handleChangeItem(3)">已维修完成</view>
						<view class="close_btn">
							<view class="btn_box cancel" @click="$refs.popup_close[0].close()">取消</view>
							<view class="btn_box confirm" @click="$refs.popup_close[0].close()">确定</view>
						</view>
					</view>
				</uni-popup>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			permission: true,
			items: ['团队工单', '个人工单'],
			current: 0,
			activeIndex: 1,
			// type为 1 是 待接单,type为 2 是维修中,
			// type为 3 是 待审核,type为 4 是已完成,
			// type为 5 是 待确认,type为 6 是已关单,
			dataList: [
				{
					id: 1,
					order: '656262219626262',
					overtime: true,
					time: '2023.07.05  09:25:26',
					type: 1,
					name: '张三',
					phone: '13659585689',
					area: '行政楼',
					address: '3楼309',
					goods: '电脑',
					description: '水龙头坏了',
					img: ''
				},
				{
					id: 2,
					order: '956262219626262',
					overtime: false,
					time: '2023.07.05  09:25:26',
					type: 2,
					name: '李四',
					phone: '13659585689',
					area: '行政楼',
					address: '3楼309',
					goods: '电脑',
					description: '电脑坏了',
					img: '',
					workerName: '老张',
					workerPhone: '13659585689'
				},
				{
					id: 3,
					order: '956262219626262',
					overtime: false,
					time: '2023.07.05  09:25:26',
					type: 3,
					name: '李四',
					phone: '13659585689',
					area: '行政楼',
					address: '3楼309',
					goods: '电脑',
					description: '电脑坏了',
					img: '',
					workerName: '老张',
					workerPhone: '13659585689',
					money: 50
				},
				{
					id: 4,
					order: '956262219626262',
					overtime: false,
					time: '2023.07.05  09:25:26',
					type: 4,
					name: '李四',
					phone: '13659585689',
					area: '行政楼',
					address: '3楼309',
					goods: '电脑',
					description: '电脑坏了',
					img: '',
					workerName: '老张',
					workerPhone: '13659585689',
					money: 50
				},
				{
					id: 5,
					order: '956262219626262',
					overtime: false,
					time: '2023.07.05  09:25:26',
					type: 5,
					name: '李四',
					phone: '13659585689',
					area: '行政楼',
					address: '3楼309',
					goods: '电脑',
					description: '电脑坏了',
					img: '',
					workerName: '老张',
					workerPhone: '13659585689',
					money: 50
				},
				{
					id: 6,
					order: '956262219626262',
					overtime: false,
					time: '2023.07.05  09:25:26',
					type: 6,
					name: '李四',
					phone: '13659585689',
					area: '行政楼',
					address: '3楼309',
					goods: '电脑',
					description: '电脑坏了',
					img: '',
					workerName: '老张',
					workerPhone: '13659585689',
					money: 50
				}
			]
		}
	},
	methods: {
		handleClose() {
			this.$refs.popup_close[0].open('center')
		},
		handleChangeItem(val) {
			this.activeIndex = val
		},
		handleOffer() {
			uni.navigateTo({
				url: '/pagesRepairs/offer/offer'
			})
		},
		handleFinish() {
			uni.navigateTo({
				url: '/pagesRepairs/repairRecord/repairRecord'
			})
		},
		handleTransferOrder() {
			uni.navigateTo({
				url: '/pagesRepairs/transferOrder/transferOrder'
			})
		},
		handleHelp() {
			uni.navigateTo({
				url: '/pagesRepairs/help/help'
			})
		},
		onClickItem(e) {
			if (this.current != e.currentIndex) {
				this.current = e.currentIndex
				console.log(this.current)
			}
		}
	}
}
</script>

<style lang="scss" scoped>
.container {
	width: 100vw;
	height: calc(100vh - 102rpx);

	.top_bg {
		height: 165rpx;
		background-color: #6fb6b8;
	}

	.top_types {
		display: flex;
		justify-content: space-evenly;
		margin: auto;
		margin-top: -100rpx;
		width: 690rpx;
		height: 188rpx;
		border-radius: 10rpx;
		box-shadow: 0px 0px 4rpx rgba(0, 0, 0, 0.25);
		background-color: #fff;

		.types_box {
			flex: 1;
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;
			.box_num {
				font-size: 46rpx;
				color: #ff5733;
			}
			.box_info {
				margin-top: 10rpx;
				font-size: 34rpx;
			}
		}
	}

	.top_types2 {
		box-sizing: border-box;
		margin: auto;
		margin-top: -100rpx;
		padding: 0 30rpx;
		width: 690rpx;
		height: 402rpx;
		border-radius: 10rpx;
		box-shadow: 0px 0px 4rpx rgba(0, 0, 0, 0.25);
		background-color: #fff;

		.top {
			height: 112rpx;
			border-bottom: 1rpx solid #e6e6e6;
		}

		.bottom {
			display: flex;
			flex-wrap: wrap;
			justify-content: space-evenly;
			height: 290rpx;

			.bottom_box {
				width: 25%;
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;
				.box_num {
					font-size: 46rpx;
					color: #ff5733;
				}
				.box_info {
					margin-top: 10rpx;
					font-size: 34rpx;
				}
			}
		}
	}

	.body {
		box-sizing: border-box;
		padding: 0 30rpx 30rpx 30rpx;
		height: calc(100vh - 355rpx);
		overflow-y: auto;

		.body_item {
			margin-top: 20rpx;
			border-radius: 11rpx;
			box-shadow: 0 0 8rpx #d9d9d9;

			.item_title {
				display: flex;
				align-items: center;
				padding: 0 30rpx;
				height: 87rpx;
				border-bottom: 1rpx solid #e6e6e6;

				img {
					width: 30rpx;
					height: 30rpx;
				}

				.title_info {
					margin: 0 21rpx 0 13rpx;
					font-size: 28rpx;
				}

				.title_type {
					width: 137rpx;
					height: 47rpx;
					line-height: 47rpx;
					text-align: center;
					border-radius: 136rpx;
					color: #ff5733;
					font-size: 24rpx;
					border: 1rpx solid #ff5733;
				}
			}

			.item_time {
				display: flex;
				justify-content: space-between;
				align-items: center;
				padding: 0 30rpx;
				height: 79rpx;

				.time_msg {
					font-size: 28rpx;
					color: #808080;

					text {
						color: #000000;
					}
				}

				.time_type {
					font-size: 32rpx;
					color: #ff5733;
				}

				.color_type {
					color: #1e7dfb;
				}
				.color_type2 {
					color: #d43030;
				}
				.color_type3 {
					color: #6fb6b8;
				}
				.color_type4 {
					color: #a6a6a6;
				}
			}

			.item_box {
				display: flex;
				padding: 0 30rpx;
				height: 60rpx;
				font-size: 28rpx;

				.box_key {
					color: #808080;
				}

				.box_value {
					display: flex;

					img {
						margin-top: 5rpx;
						margin-left: 10rpx;
						width: 28rpx;
						height: 28rpx;
					}
				}

				.box_value2 {
					display: flex;

					img {
						margin-top: -2rpx;
						margin-left: 14rpx;
						width: 46rpx;
						height: 46rpx;
					}
				}

				.phone {
					color: #6fb6b8;
				}
			}

			.item_img {
				display: flex;
				align-items: center;
				padding: 0 30rpx;
				height: 120rpx;
				color: #808080;
				font-size: 28rpx;

				.img_key {
				}

				.img_value {
					width: 120rpx;
					height: 120rpx;
					border-radius: 14rpx;
					background-color: salmon;
				}
			}

			.item_btn {
				display: flex;
				align-items: center;
				justify-content: flex-end;
				padding: 0 30rpx;
				line-height: 153rpx;

				img {
					margin-right: auto;
					margin-top: 45rpx;
					margin-bottom: 40rpx;
					width: 56rpx;
					height: 56rpx;
				}

				.img {
					margin-right: auto;
					margin-left: -55rpx;
					margin-top: 45rpx;
					margin-bottom: 40rpx;
					width: 62rpx;
					height: 62rpx;
				}

				.btn_box {
					display: flex;
					justify-content: center;
					align-items: center;
					margin-left: 16rpx;
					margin-top: 45rpx;
					margin-bottom: 40rpx;
					width: 174rpx;
					height: 68rpx;
					font-size: 28rpx;
					border-radius: 11rpx;
				}

				.type {
					color: #fff;
					background-color: #6fb6b8;
				}

				.type2 {
					color: #6fb6b8;
					background-color: #fff;
					border: 1rpx solid #6fb6b8;
				}
			}

			.popup_close {
				width: 690rpx;
				border-radius: 19rpx;
				background-color: #fff;

				.close_box {
					height: 100rpx;
					line-height: 100rpx;
					text-align: center;
					font-size: 32rpx;
					border: 1rpx solid #e6e6e6;
				}

				.radius {
					border-radius: 19rpx 19rpx 0 0;
				}

				.active {
					color: #fff;
					background-color: #6fb6b8;
				}

				.close_btn {
					display: flex;
					align-items: center;
					justify-content: space-evenly;
					margin-top: 100rpx;
					height: 121rpx;

					.btn_box {
						display: flex;
						justify-content: center;
						align-items: center;
						width: 203rpx;
						height: 72rpx;
						border-radius: 9rpx;
						font-size: 32rpx;
					}

					.cancel {
						background-color: #e5e5e5;
						color: #6fb6b8;
					}

					.confirm {
						background-color: #6fb6b8;
						color: #fff;
					}
				}
			}
		}
	}

	.body2 {
		height: calc(100vh - 555rpx);
	}
}
</style>
