<template>
	<view class="container">
		<!-- 接单考核时间区域 -->
		<view class="box">
			接单考核时间
			<view class="box_time">
				<input type="number" v-model="receivingTime" />
				<img src="../../static/images/repairsImg/clock.png" />
			</view>
			分钟
		</view>

		<!-- 维修考核时间区域 -->
		<view class="box">
			维修考核时间
			<view class="box_time">
				<input type="number" v-model="repairsTime" />
				<img src="../../static/images/repairsImg/clock.png" />
			</view>
			分钟
		</view>

		<!-- 提交按钮区域 -->
		<view class="btn" @click="handleSub">提交</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			// 接单考核时间
			receivingTime: null,
			// 维修考核时间
			repairsTime: null,
			// 订单id
			id: ''
		}
	},
	onLoad(options) {
		this.id = options.id
	},
	methods: {
		// 提交按钮回调
		handleSub() {
			// 验证输入为整数
			const reg = /^\+?[1-9][0-9]*$/
			if (!this.receivingTime) {
				uni.showToast({
					title: '请输入接单考核时间',
					icon: 'none'
				})
				return
			}
			if (!reg.test(this.receivingTime)) {
				uni.showToast({
					title: '接单考核时间格式错误,请重新输入',
					icon: 'none'
				})
				return
			}
			if (!this.repairsTime) {
				uni.showToast({
					title: '请输入维修考核时间',
					icon: 'none'
				})
				return
			}
			if (!reg.test(this.repairsTime)) {
				uni.showToast({
					title: '维修考核时间格式错误,请重新输入',
					icon: 'none'
				})
				return
			}
			uni.showModal({
				title: '提示',
				content: '确定延时吗？',
				success: async (res) => {
					if (res.confirm) {
						const res = await this.$myRequest_repairs({
							url: '/repairRecord/delayed',
							method: 'post',
							data: {
								recordId: this.id,
								receiving: this.receivingTime,
								maintain: this.repairsTime
							}
						})
						// console.log(res)
						if (res.code === '200') {
							uni.showToast({
								title: '延时成功',
								icon: 'success'
							})
							setTimeout(() => {
								uni.redirectTo({
									url: '/pagesRepairs/box/box'
								})
							}, 1500)
						}
					}
				}
			})
		}
	}
}
</script>

<style lang="scss" scoped>
.container {
	box-sizing: border-box;
	padding: 0 30rpx;
	width: 100vw;
	height: 100vh;

	.box {
		display: flex;
		align-items: center;
		height: 100rpx;
		font-size: 32rpx;
		font-weight: bold;

		.box_time {
			display: flex;
			justify-content: space-between;
			align-items: center;
			box-sizing: border-box;
			padding: 0 23rpx;
			margin: 0 25rpx;
			width: 237rpx;
			height: 68rpx;
			font-weight: 400;
			border-radius: 4rpx;
			border: 1rpx solid #a6a6a6;

			input {
				flex: 1;
			}

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

	.btn {
		position: absolute;
		bottom: 66rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		margin: auto;
		width: 690rpx;
		height: 100rpx;
		color: #fff;
		font-size: 32rpx;
		border-radius: 12rpx;
		background-color: #6fb6b8;
	}
}
</style>
