<template>
	
	<vehicleDetail ref="vehicleDetailRef" :vehicleId="state.vehicleId" @getVehicleDetail="getVehicleDetail"></vehicleDetail>
	<!-- 
	<view class="main-block">
		<u-form :model="state.formData" ref="myForm" label-position="left">
			<view class="from">
				<u-form-item prop="phone">
					<view class="from_item" style="background-color: #f7f7f7">
						<text><text style="color: red"></text>手机号：</text>
						<u-input v-model="state.vehicleInfo.customerTel" :disabled="true" class="input" />
					</view>
				</u-form-item>
				<u-form-item prop="code">
					<view class="from_item">
						<text><text style="color: red"></text>验证码：</text>
						<u-input v-model="state.formData.code" placeholder="请输入验证码" class="input" type="number" />
						<view class="hint2">
							<view class="green">{{ codeDuration === 0 ? "" : codeDuration }}</view>
							<view class="grey" @click="getCode">{{ codeDuration === 0 ? "发送验证码" : "秒后可重发" }}</view>
						</view>
					</view>
				</u-form-item>
			</view>
		</u-form>
	</view> -->
	
	<view class="action"  >
		<button type="default" class="ui-btn" @click="submit">恢复卡签使用</button>
	</view>
	
	<view class="bottom-empty-box"></view>
</template>

<script lang="ts" setup>
import { reactive, ref } from "vue";
import { onLoad, onShow } from "@dcloudio/uni-app";
import { confirm, msg, objectToQueryString } from "@/utils/utils";
import { sendMessage, cardLossUndo } from '@/utils/network/api.js'
import { requestNew } from "@/utils/network/request.js";
import vehicleDetail from '@/components/vehicle-detail/vehicle-detail.vue'

const state = reactive({
	vehicleId: '',
	orderInfo: {
		
	}, 
	vehicleInfo: {
		customerName: '',
		customerIdType: '',
		customerIdNum: '',
		vehicleId: '',
		type: '',
		cardId: '',
		cardType: '',
		cardStatus: '',
		cardExpireTime: '',
		obuId: '',
		obuStatus: '',
		obuExpireTime: '',
		customerTel: ''
	},
	renewalStatus: '0',
	formData: {
		code: '',
		
	},
	flag: false // 是否可以操作挂失与解挂
});

const codeDuration = ref(0);
const vehicleDetailRef = ref(null)

let interval = null;

onLoad(({vehicleId}) => {
  if (vehicleId) {
	  state.vehicleId = decodeURIComponent(vehicleId)
  }
});

onShow(() => {
	
});

	
const submit = () => {
	let vehicleInfo = state.vehicleInfo
	let params = {
		routeType: '12',
		vehicleId: state.vehicleInfo.vehicleId,
		cardId: vehicleInfo.cardId,
		obuId: vehicleInfo.obuId,
		cardExpireTime: vehicleInfo.cardExpireTime,
		obuExpireTime: vehicleInfo.obuExpireTime
	}
	uni.showModal({
		title: '挂起恢复申请',
		content: '确定恢复当前挂起设备吗？',
		success: (e) => {
			if (e.confirm) {
				uni.navigateTo({
					url: `/pages/bluetooth/bluetooth?${objectToQueryString(params)}`
				})
				// uni.navigateTo({
				// 	url: `/subpackage/after-sale/releaseSuspension/cardloss?${objectToQueryString(params)}`
				// })
				
			}
		}
	})
}

// 获取车辆详情
const getVehicleDetail = (res) => {
	state.vehicleInfo = res
	
	if (state.vehicleInfo.cardStatus === 'YKGQ' || state.vehicleInfo.cardStatus === 'WKGQ') {
		state.flag = true
	} else if (state.vehicleInfo.obuStatus == 'YQGQ' || state.vehicleInfo.obuStatus == 'WQGQ') {
		state.flag = true
	} else {
		state.flag = false
	}
}

const getCode = () => {
	if (codeDuration.value !== 0) {
		return;
	}
	const options = {
		type: 2,
		data: {
			mobile: state.vehicleInfo.customerTel,
			businessType: 5
		},
		method: "POST",
		showLoading: true,
	};
	requestNew(sendMessage, options)
		.then(() => {
			codeInterval();

			msg("验证码发送成功！");
		})
		.catch((err) => {
			console.log(err);
		});
}

/* 验证码倒计时 */
const codeInterval = () => {
	codeDuration.value = 60;
	interval = setInterval(() => {
		codeDuration.value--;
		if (codeDuration.value === 0) {
			if (interval) {
				clearInterval(interval);
				interval = null;
			}
		}
	}, 1000);
};
</script>

<style lang="scss" scoped>
	.main-block {
		background-color: white;
		margin: 20rpx 30rpx 0 30rpx;
		border-radius: 12px;
		border: 1px solid #FFFFFF;
		padding: 20rpx;
		overflow: hidden;
	
		.title {
			font-weight: bold;
			font-size: 30rpx;
			color: #01243A;
			margin-bottom: 12rpx;
		}
	}
	.renwal-type{
		justify-content: space-around;
	}
	.action {
		position: absolute;
		left: 0;
		height: 270rpx;
		background-color: #fff;
		border-radius: 30rpx 30rpx 0 0;
		width: 100vw;
		display: flex;
		align-items: center;
		justify-content: space-evenly;
		flex-direction: column;
		margin-top: 20rpx;
	}
	
	.from {
		::v-deep .u-form-item {
			padding: 0;
			line-height: normal;
	
			.u-form-item__message {
				margin-bottom: 12rpx;
			}
		}
	
		.from_item {
			display: flex;
			flex-wrap: nowrap;
			justify-content: space-between;
			align-items: center;
			height: 80rpx;
			border-bottom: 1rpx solid #dcdcdc;
			padding: 0 24rpx;
			.btn {
				font-size: 24rpx;
				font-family: Microsoft YaHei;
				font-weight: 400;
				color: #ffffff;
				background: #00b38b;
				border-radius: 10rpx;
				padding: 10rpx 15rpx;
			}
	
			::v-deep .input {
				text-align: left;
				flex: 1;
	            background: transparent;
				input {
					text-align: left;
				}
			}
			.hint2{
				width: 180rpx;
				display: flex;
				align-items: center;
			}
		}
	}
</style>
