<template>
	<view class="selectCar-box">
		<view class="details">
			<view class="title">
				基础信息
			</view>
			<view class="details-item">
				<view>
					用户名称：
				</view>
				<text>{{state.data.name}}</text>
			</view>
			<view class="details-item">
				<view>
					用户证件类型：
				</view>
				<text>{{getCredentialType(state.data.customerIdtype)}}</text>
			</view>
			<view class="details-item">
				<view>
					用户证件号：
				</view>
				<text>{{desensitization(state.data.idNum)}}</text>
			</view>
			<view class="details-item">
				<view>
					订单车牌号：
				</view>
				<text style="color: #00B38B;;">{{state.data.vehiclePlate}}</text>
			</view>
			<view class="details-item">
				<view>
					收费车型：
				</view>
				<text>{{state.data.vehicleType}}</text>
			</view>
		</view>
		<view class="title">
			卡信息
		</view>
		<view class="card">
			<view class="card-left">
				<image :src="`${$imgUrl}card2.png`" mode=""></image>
				<view class="card-center">
					<view class="card-center-head">
						{{state.data.cardId}}
					</view>
					<view class="tips">
						<text>{{state.cardType=="23"?'记账卡':'储值卡'}}</text>
						<text class="tips-card">{{getCodeName('CARD_STATE_TYPE',state.data.cardStatus)}}</text>
					</view>
				</view>
			</view>
			<view class="choose-item">
				<view class="active">

				</view>
			</view>
		</view>

		<view class="title">
			OBU设备信息
		</view>
		<view class="card">
			<view class="card-left">
				<image :src="`${$imgUrl}card1.png`" mode=""></image>
				<view class="card-center">
					<view class="card-center-head">
						{{state.data.obuId}}
					</view>
					<view class="tips">
						<!-- <text>储蓄卡</text> -->
						<text class="tips-card">{{getCodeName('OBU_STATE_TYPE',state.data.obuStatus)}}</text>
					</view>
				</view>
			</view>
			<view class="choose-item">
				<view class="active">

				</view>
			</view>
		</view>
		<button class="submit" @click="nextACtion">下一步</button>
	</view>
</template>

<script lang="ts" setup>
	import {
		getCodeName
	} from "@/datas/queryKey.js";

	import {
		reactive,
		ref
	} from "vue"
	import {
		navTo,desensitization
	} from "@/utils/utils"
	import {
		onLoad,
		onUnload,
		onShow
	} from "@dcloudio/uni-app";
	import {requestNew
	} from "@/utils/network/request.js";
	import {commGetDetail,relieveHandUp
	} from "@/utils/network/api.js";
	import {
		getCredentialType
	} from "@/subpackage/after-sale/js/credentialType.js";
	import {
		msg
	} from "@/utils/utils";

	const state = reactive({
		vehicleId: "",
		data: {
			cardStatus: undefined,
			obuStatus: undefined,
		},
		successTip: ""  ,//成功提示
		cardType:"",
		name:""
	});
	const flag = reactive([1,2])
	const type = ref('')
	/*视图进入后操作*/
	onShow(() => {
		queryOrderDetail(state.vehicleId).then((val : any) => {
			console.log("val",val)
			state.data = val
			state.cardType=val.cardId.substring(8,10)
			console.log(state.cardType)
		})
	})
	onLoad((option) => {
		state.vehicleId = option.vehicleId
		/*监听手机号验证后的回调*/
		uni.$on('queryCardlossStatus', function (type) {
			console.log("1111", type)
			queryCardlossStatusType(type.type).then((val : any) => {
				console.log("val", val)
				navTo(
					`/subpackage/after-sale/releaseSuspension/card-result?successTip=${type.successTip}`
				)
			});
		})
	});

	onUnload(() => {
		/*移除监听*/
		uni.$off('queryCardlossStatus')
	});
	/*下一步*/
	const nextACtion = () => {
		console.log(flag.length)
		// 
		showModelAction('解除挂起', '请确认是否执行解除挂起',3)

	}

	const showModelAction = (title, content, type) => {
		uni.showModal({
			title: title,
			content: content,
			success: function (res) {
				if (res.confirm) {
					navTo(
						`/subpackage/after-sale/releaseSuspension/cardloss?type=${type}&&mobile=${state.data.mobile}&&successTip=${title}`
					)

				}
			}
		});
	}

	const choose = (data) => {
		if (!flag.includes(data)) {
			flag.push(data)
			console.log(flag);

		} else {
			flag.splice(flag.indexOf(data), 1)
			console.log(flag);
		}

		if (flag.length == 2) {
			type.value = '3'
		} else if (flag[0] == 1) {
			type.value = '1'
		} else {
			type.value = '2'
		}
	}

	const queryOrderDetail = (vehicleId) => {
		return new Promise(async (resolve, reject) => {
			const res = await requestNew(commGetDetail, {
				type: 2,
				data: {
					vehicleId,
					deviceStatus: [1, 6]
				},
				method: "POST",
				showLoading: true,
			});
			const data = res;
			resolve(data);
		}).catch((error) => {

			reject(error);
		});
	}
	const queryCardlossStatusType = (val : any) => {
		var data = {
			cardId: state.data.cardId,
			obuId: state.data.obuId,
			businessType: val,
			orderId: state.data.orderId,
			vehicleId:state.data.vehicleId
		};
		const options = {
			type: 2,
			data: data,
			method: "POST",
			showLoading: true,
		};
		return new Promise(async (resolve, reject) => {
			const res = await requestNew(relieveHandUp, options);
			const data = res
			resolve(data);
		}).catch((error) => {
			reject(error);
		});

	}
</script>

<style>
	page {
		width: 100%;
		height: 100%;
		background-color: #fff;
	}
</style>
<style lang="scss" scoped>
	.selectCar-box {
		padding: 30rpx;

		.title {
			font-size: 30rpx;
			font-family: Microsoft YaHei UI;
			font-weight: 400;
			color: #333333;
			margin-bottom: 30rpx;
		}

		.details {
			.title {
				font-size: 30rpx;
				font-family: Microsoft YaHei UI;
				font-weight: 400;
				color: #333333;
				margin-bottom: 30rpx;
			}

			.details-item {
				display: flex;
				font-size: 26rpx;
				font-family: Noto Sans S Chinese;
				font-weight: 400;
				color: #999999;
				margin-bottom: 30rpx;

				text {
					font-size: 26rpx;
					font-family: Noto Sans S Chinese;
					font-weight: 400;
					color: #333333;
				}
			}

		}

		.card {
			height: 150rpx;
			background: #FFFFFF;
			box-shadow: 0rpx 4rpx 13rpx 3rpx rgba(223, 223, 223, 0.8);
			border-radius: 20rpx;
			padding: 30rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;
			margin-bottom: 60rpx;

			.card-left {
				display: flex;
				align-items: center;

				image {
					width: 100rpx;
					height: 90rpx;
				}

				.card-center {
					margin-left: 30rpx;

					.card-center-head {
						font-size: 32rpx;
						font-family: Noto Sans S Chinese;
						font-weight: 400;
						color: #333333;
					}

					.tips {
						font-size: 26rpx;
						font-family: Noto Sans S Chinese;
						font-weight: 400;
						color: #666666;

						.tips-card {
							width: 70rpx;
							height: 40rpx;
							background: #D3F2EF;
							border-radius: 6rpx;
							font-size: 20rpx;
							font-family: Noto Sans S Chinese;
							font-weight: 400;
							color: #0A8F8A;
							padding: 5rpx 10rpx;
							margin-left: 20rpx;
						}
					}
				}
			}

			.choose-item {
				margin-right: 20rpx;
				width: 50rpx;
				height: 50rpx;
				border: 1rpx solid #00B38B;
				border-radius: 50%;
				display: flex;
				justify-content: center;
				align-items: center;

				.active {
					width: 38rpx;
					height: 38rpx;
					background: #00B38B;
					border-radius: 50%;
				}
			}
		}

		.remark {
			font-size: 26rpx;
			font-family: Microsoft YaHei UI;
			font-weight: 400;
			color: #666666;
			text-indent: 30rpx;
			margin-bottom: 30rpx;
		}

		.submit {
			margin-top: 100rpx;
			width: 670rpx;
			height: 80rpx;
			background: linear-gradient(-90deg, #43A1E0 0%, #13E7C1 100%);
			border-radius: 40rpx;
			font-size: 32rpx;
			font-family: Noto Sans S Chinese;
			font-weight: 400;
			color: #FFFFFF;
			line-height: 80rpx;
		}
	}
</style>