<template>
	<view class="selectCar-box">
		<view v-if="state.list.length > 0" @click="choose(i, item)" class="item" v-for="(item, i) in state.list"
			:key="i">
			<view class="iten-left">
				<image :src="`${$imgUrl}che.png`" mode="aspectFill"></image>
				<view class="message">
					<view>车牌号：{{ item.vehiclePlate }}</view>
					<view>车牌颜色：{{ getVehiclePlateColor(item.vehiclePlateColor) }}</view>
					<view v-if="item.cardId">卡号：{{ item.cardId }}</view>
					<view v-if="item.cardStatus">卡状态：{{getCodeName('CARD_STATE_TYPE',item.cardStatus)}}</view>
					<view v-if="item.obuId">签号：{{ item.obuId }}</view>
					<view v-if="item.obuStatus">签状态：{{ getCodeName('OBU_STATE_TYPE',item.obuStatus) }}</view>
				</view>
			</view>
			<view class="choose-item">
				<view class="active" v-if="flag == i"> </view>
			</view>
		</view>
		<view v-else class="flex"> 暂无车辆订单信息 </view>
	</view>
</template>

<script lang="ts" setup>
	import { reactive, ref } from "vue";
	import { navTo} from "@/utils/utils";
	import { onLoad,onShow} from "@dcloudio/uni-app";
	import { afterSaleCommQuery,queryPage } from "@/utils/network/api.js";
	import { requestNew } from "@/utils/network/request.js";
	import { getItem, StorageKeys} from "@/utils/storage";
	import { jump } from "@/datas/9901Jump.js";
import { deviceType } from "@/utils/network/difference";
	import {
		getCodeName
	} from "@/datas/queryKey.js";
	import {
		getVehiclePlateColor
	} from "@/datas/vehiclePlateColor";
	const state = reactive({
		list: [],
		type: "",//1 OBU重新激活   2 卡签注销   3 更换设备  4卡签续期  5挂失解挂  6增补设备（单卡单签补）  7补卡签（设备丢了补卡签） 8解除挂起
		// 30 储值卡转记账卡  31卡pin码解锁  32ETC车牌过户  33 卡签停用/卡签启用   
		// 34月结单查询  35ETC通行流水记录  36 黑名单查询  37恢复签约 
	});
	onLoad((options) => {
		console.log("options", options)
		state.type = options.type
		if (options.type == "2") {
			uni.setNavigationBarTitle({
				title: 'ETC注销-选择车辆'
			});
		} else if (options.type == "3") {
			uni.setNavigationBarTitle({
				title: '更换ETC设备-选择车辆'
			});
		} else if (options.type == "4") {
			uni.setNavigationBarTitle({
				title: '卡签续期-选择车辆'
			});
		}else if (options.type == "5") {
			uni.setNavigationBarTitle({
				title: '卡签挂失/解除挂失-选择车辆'
			});
		}else if (options.type == "6") {
			uni.setNavigationBarTitle({
				title: '增补设备-选择车辆'
			});
		}else if (options.type == "7") {
			uni.setNavigationBarTitle({
				title: '补卡补签-选择车辆'
			});
		}else if (options.type == "8") {
			uni.setNavigationBarTitle({
				title: '解除挂起-选择车辆'
			});
		}else if (options.type == "30") {
			uni.setNavigationBarTitle({
				title: '储值卡转记账卡-选择车辆'
			});
		}else if (options.type == "31") {
			uni.setNavigationBarTitle({
				title: '卡pin码解锁-选择车辆'
			});
		}else if (options.type == "32") {
			uni.setNavigationBarTitle({
				title: 'ETC车牌过户-选择车辆'
			});
		}else if (options.type == "33") {
			uni.setNavigationBarTitle({
				title: '卡签停用/卡签启用-选择车辆'
			});
		}else if (options.type == "34") {
			uni.setNavigationBarTitle({
				title: '月结单查询-选择车辆'
			});
		}else if (options.type == "35") {
			uni.setNavigationBarTitle({
				title: 'ETC通行流水-选择车辆'
			});
		}else if (options.type == "36") {
			uni.setNavigationBarTitle({
				title: '黑名单查询-选择车辆'
			});
		}else if (options.type == "37") {
			uni.setNavigationBarTitle({
				title: '恢复签约-选择车辆'
			});
		}
		
	});
	onShow(()=>{
		if(state.type=='37'){
			// 恢复签约查询订单接口
			list().then((item : any) => {
				console.log("item",item)
				state.list = item.data;
			})
		}else{
			quanCheckActionTrue().then((item : any) => {
				if (state.type == "32") {
					let data = item.result
					for (var k = 0; k < data.length; k++) {
						if (data[k]['orderStatus'] != "99999") {
							state.list.push(data[k])
						}
					}
				}else{
					state.list = item.result;
				}
				console.log(item);
			});
		}
		
	})
	const list=()=>{
		let newsource = "WECHAT"
		// #ifdef MP-ALIPAY
		newsource = "ALI"
		// #endif
		const options = {
			type: 2,
			data: {
				"source": newsource,
				"orderStatus": "ACTIVE",
				"tabIndex":"-1"
			},
			method: "POST",
			showLoading: true,
		};
		return new Promise(async (resolve, reject) => {
			const res = await requestNew(queryPage, options);
			const data = res;
		
			resolve(data);
		}).catch((error) => {
			reject(error);
		});
	}
	const quanCheckActionTrue = () => {
		let source = ""
		// #ifdef MP-ALIPAY
		source = "ALI"
		// #endif
		// #ifdef MP-WEIXIN
		source = "WECHAT"
		// #endif
		var data={}
		if(state.type=="5"){
			data = {
				opId: getItem(StorageKeys.OpenId),
				loginSource:getItem("loginSource"),
				deviceStatus:[1,6],//挂失解挂设备状态
			};
		}else{
			data = {
				opId: getItem(StorageKeys.OpenId),
				loginSource:getItem("loginSource"),
			};
		}
		
		const options = {
			type: 2,
			data: data,
			method: "POST",
			showLoading: true,
		};
		return new Promise(async (resolve, reject) => {
			const res = await requestNew(afterSaleCommQuery, options);
			const data = res;

			resolve(data);
		}).catch((error) => {
			reject(error);
		});
	};
	const flag = ref("0");

	const choose = (i, item) => {
		console.log(item.cardId);
			flag.value = i
			// 判断9901
			// 月结单查询 etc通行流水记录  黑名单查询 目前不用跳转到插件
			if (state.type == "34") {
				navTo(`/subpackage/after-sale/month-statement/month-statement-query-list?vehicleId=${item.vehicleId}`)
			}else if (state.type == "35") {
				navTo(`/subpackage/personal-center/search/etcFlowingWater?vehicleId=${item.vehicleId}`)
			}else if (state.type == "36") {
				uni.navigateTo({
					url: `/subpackage/after-sale/blacklist-query/list?vehiclePlate=${item.vehiclePlate}&vehiclePlateColor=${item.vehiclePlateColor}&cardId=${item.cardId}`
				})
			}else{
				if (item.deviceType == deviceType) {
					// OBU重新激活跳转
					const params = encodeURIComponent(JSON.stringify(item))
					jump(state.type, params)
				} else {
					if (state.type == "1") {
						// #ifdef MP-WEIXIN
						navTo(
							`/subpackage/after-sale/activation-once-again/activation-once-again?vehicleId=${item.vehicleId}`
						);
						// #endif
						// #ifdef MP-ALIPAY
						navTo(
							`/subpackage/after-sale/activation-once-again/activation-once-again-ali?vehicleId=${item.vehicleId}`
						);
						// #endif
					} else if (state.type == "2") {
						navTo(`/subpackage/after-sale/ETC-log-off/log-off-confirm?vehicleId=${item.vehicleId}`)
					} else if (state.type == "3") {
						navTo(`/subpackage/after-sale/replace-equipment/replace-equipment-confirm?vehicleId=${item.vehicleId}`)
					} else if (state.type == "4") {
						navTo(`/subpackage/after-sale/card-Renewal/renewal-confirm?vehicleId=${item.vehicleId}`)
					} else if (state.type == "5") {
						navTo(`/subpackage/after-sale/card-loss-reporting/cardloss-confirm?vehicleId=${item.vehicleId}`)
					}else if (state.type == "6") {
						navTo(`/subpackage/after-sale/additional-equipment/additional-equipment-confirm?id=${item.id}`)
					}else if (state.type == "7") {
						navTo(`/subpackage/after-sale/replace-cardObu/replace-equipment-confirm?vehicleId=${item.vehicleId}`)
					}else if (state.type == "8") {
						navTo(`/subpackage/after-sale/releaseSuspension/cardloss-confirm?vehicleId=${item.vehicleId}`)
					}else if (state.type == "30") {
						navTo(`/subpackage/after-sale/to-bookkeeping-card/confirm?id=${item.id}`)
					}else if (state.type == "31") {
						navTo(`/subpackage/after-sale/pin-code-deblocking/pin-code-confirm?id=${item.id}`);
					}else if (state.type == "32") {
						navTo(`/subpackage/after-sale/transfer-ownership/transfer-confirm?id=${item.id}`)
					}else if (state.type == "33") {
						navTo(`/subpackage/after-sale/card-deactivation-activation/deactivation-activation-confirm?id=${item.id}`)
					}else  if (state.type == "37") {
						// #ifdef MP-ALIPAY
						uni.navigateTo({
							url: `/subpackage/orders/sign-up-ali?orderId=${item.orderId}&&channelSing=1&&vehiclePlate=${item.vehiclePlate}`,
						});
						// #endif
						// #ifdef MP-WEIXIN
						uni.navigateTo({
							url: `/subpackage/orders/sign-up?orderId=${item.orderId}&&channelSing=1&&vehiclePlate=${item.vehiclePlate}`,
						});
						// #endif
					}
				}
			}
	}
</script>

<style>
	page {
		width: 100%;
		height: 100%;
		background-color: #eef7f7;
	}
</style>
<style lang="scss" scoped>
	.flex {
		display: flex;
		justify-content: center;
	}

	.selectCar-box {
		height: 100%;
		padding: 30rpx;

		.item {
			padding: 20rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;
			// height: 130rpx;
			background: #ffffff;
			box-shadow: 0rpx 2rpx 6rpx 0rpx rgba(223, 223, 223, 0.8);
			border-radius: 20rpx;
			margin-bottom: 30rpx;

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

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

				text {
					margin-left: 20rpx;
					font-size: 32rpx;
					font-family: Noto Sans S Chinese;
					font-weight: 400;
					color: #333333;
				}
			}

			.choose-item {
				width: 44rpx;
				height: 44rpx;
				background: #ffffff;
				border: 2rpx solid #00b38b;
				border-radius: 50%;
				margin-right: 20rpx;
				display: flex;
				justify-content: center;
				align-items: center;
				box-sizing: content-box;
			}

			.active {
				width: 34rpx;
				height: 34rpx;
				background: #00b38b;
				border-radius: 50%;
			}
		}
	}
	.message{
		font-size: 26rpx;
		margin-left: 6rpx;
	}
</style>