<template>
	<view class="container">
		<!-- 顶部分段器区域 -->
		<view class="control">
			<view class="control_item" :class="{ active: current === index }" v-for="(item, index) in items" :key="index" @click="onClickItem(index)">{{ item }}</view>
		</view>

		<!-- 主体内容区域 -->
		<view class="body">
			<!-- 每一个记录区域 -->
			<view class="body_item" v-for="item in list" :key="item.id">
				<!-- 工单编号 -->
				<view class="item_title" @click="handleLookDetail(item)">
					<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" v-if="item.type === 3">待确认</view>
					<view class="time_type color_type2" v-if="item.type === 4">已完成</view>
					<view class="time_type" v-if="item.type === 5">已取消</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" @click="handleCallPhone('13820846714')">
						{{ 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 === 3 || item.type === 4">
					<view class="time_msg">
						维修师傅：
						<text>{{ item.workerName }}</text>
					</view>
				</view>

				<!-- 师傅电话 -->
				<view class="item_box" v-if="item.type === 3 || item.type === 4">
					<view class="box_key">师傅电话：</view>
					<view class="box_value phone" @click="handleCallPhone('13820846714')">
						{{ 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>

				<!-- 维修费用弹窗 -->
				<uni-popup :is-mask-click="false" ref="popup_fee">
					<view class="pop_fee">
						<view class="fee_title">
							维修费用
							<text @click="$refs.popup_fee[0].close()">×</text>
						</view>
						<view class="fee_box">
							耗材：
							<text>螺丝刀</text>
						</view>
						<view class="fee_box">
							耗材单价：
							<text>1元</text>
						</view>
						<view class="fee_box">
							耗材数量：
							<text>2</text>
						</view>
						<view class="fee_box">
							耗材费用：
							<text>2元</text>
						</view>
					</view>
				</uni-popup>

				<!-- 按钮 -->
				<view class="item_btn" v-if="item.type !== 5">
					<view class="btn_box type" v-if="item.type === 1 || item.type === 2">催单</view>
					<view class="btn_box type" v-if="item.type === 3" @click="handleBackOffice">转后勤</view>
					<view class="btn_box type" v-if="item.type === 3">支付</view>
					<view class="btn_box type2" v-if="item.type < 4">撤销</view>
					<view class="btn_box type" v-if="item.type === 4" @click="handleEvaluate">去评价</view>
				</view>
				<view class="item_btn2" v-else></view>

				<!-- 转后勤弹窗 -->
				<uni-popup ref="popup_logistics" :is-mask-click="false">
					<view class="pop_logistics">
						<view class="logistics_title">转后勤</view>
						<view class="logistics_body">
							<textarea placeholder-style="color:#CCCCCC" placeholder="请输入您宝贵的留言"></textarea>
						</view>
						<view class="logistics_btn">
							<view class="btn_box cancel" @click="$refs.popup_logistics[0].close()">取消</view>
							<view class="btn_box confirm" @click="$refs.popup_logistics[0].close()">确定</view>
						</view>
					</view>
				</uni-popup>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			items: ['未完成（2）', '待确认（4）', '已完成（5）'],
			current: 0,
			list: [],
			// type为 1 是 待接单,type为 2 是维修中,
			// type为 3 是 待确认,type为 4 是已完成,
			// type为 5 是已取消
			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: ''
				}
			],
			dataList2: [
				{
					id: 19999,
					order: '656262219626262',
					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
				}
			],
			dataList3: [
				{
					id: 1854,
					order: '656262219626262',
					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: 2789,
					order: '656262219626262',
					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
				}
			]
		}
	},
	mounted() {
		this.list = this.dataList
	},
	methods: {
		// 分段器切换回调
		onClickItem(index) {
			console.log(index)
			if (this.current != index) {
				this.current = index
			}
			if (this.current === 0) {
				this.list = this.dataList
			} else if (this.current === 1) {
				this.list = this.dataList2
			} else {
				this.list = this.dataList3
			}
		},
		// 查看维修费用回调
		checkFeeDetail() {
			this.$refs.popup_fee[0].open('center')
		},
		// 转后勤按钮回调
		handleBackOffice() {
			this.$refs.popup_logistics[0].open('center')
		},
		// 去评价按钮回调
		handleEvaluate() {
			uni.navigateTo({
				url: '/pagesRepairs/evaluate/evaluate'
			})
		},
		// 点击工单编号区域回调
		handleLookDetail(item) {
			const detailInfo = JSON.stringify(item)
			uni.navigateTo({
				url: `/pagesRepairs/repairDetails/repairDetails?detailInfo=${detailInfo}`
			})
		},
		// 点击电话号码回调
		handleCallPhone(phone) {
			console.log(phone)
			uni.makePhoneCall({
				phoneNumber: phone
			})
		}
	}
}
</script>

<style lang="scss" scoped>
.container {
	display: flex;
	flex-direction: column;
	box-sizing: border-box;
	padding: 0 30rpx;
	width: 100vw;
	height: calc(100vh - 102rpx);
	overflow-y: auto;

	.control {
		display: flex;
		box-sizing: border-box;
		margin: 26rpx 0 29rpx;
		padding: 6rpx;
		width: 100%;
		height: 88rpx;
		border-radius: 18rpx;
		background-color: #f2f2f2;

		.control_item {
			flex: 1;
			display: flex;
			justify-content: center;
			align-items: center;
			height: 76rpx;
			font-size: 32rpx;
		}

		.active {
			border-radius: 18rpx;
			background-color: #fff;
		}
	}

	.body {
		// height: calc(100vh - 190rpx);
		// overflow-y: auto;

		.body_item {
			margin: 10rpx 10rpx 30rpx;
			// height: 799rpx;
			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: #6fb6b8;
				}
			}

			.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;
				height: 153rpx;

				.btn_box {
					display: flex;
					justify-content: center;
					align-items: center;
					margin-left: 16rpx;
					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;
				}
			}

			.item_btn2 {
				height: 50rpx;
			}

			.pop_fee {
				padding-bottom: 50rpx;
				border-radius: 19rpx;
				background-color: #fff;

				.fee_title {
					display: flex;
					justify-content: space-between;
					align-items: center;
					box-sizing: border-box;
					padding: 0 31rpx 0 42rpx;
					width: 690rpx;
					height: 110rpx;
					font-size: 32rpx;
					font-weight: bold;
					border-radius: 19rpx 19rpx 0 0;
					border-bottom: 1rpx solid #e6e6e6;

					text {
						font-size: 45rpx;
						font-weight: 400;
						color: #808080;
					}
				}

				.fee_box {
					display: flex;
					align-items: center;
					padding-left: 42rpx;
					height: 80rpx;
					font-size: 28rpx;
					color: #808080;

					text {
						color: #000000;
					}
				}
			}

			.pop_logistics {
				border-radius: 19rpx;
				background-color: #fff;

				.logistics_title {
					display: flex;
					justify-content: center;
					align-items: center;
					width: 690rpx;
					height: 110rpx;
					font-size: 32rpx;
					font-weight: bold;
					border-radius: 19rpx 19rpx 0 0;
					border-bottom: 1rpx solid #e6e6e6;
				}

				.logistics_body {
					height: 440rpx;
					border-bottom: 1rpx solid #e6e6e6;

					textarea {
						box-sizing: border-box;
						margin: 35rpx 40rpx;
						padding: 20rpx;
						width: 610rpx;
						height: 370rpx;
						font-size: 28rpx;
						border-radius: 14rpx;
						border: 1rpx solid #e6e6e6;
					}
				}

				.logistics_btn {
					display: flex;
					align-items: center;
					justify-content: space-evenly;
					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;
					}
				}
			}
		}
	}
}
</style>
