<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 style="text-align: center;margin: 20rpx;font-size: 30rpx;" v-if="state.flags">我是有底线的~</view>
		
	</view>
</template>

<script lang="ts" setup>
	import { reactive, ref } from "vue";
	import { onLoad,onReachBottom } from "@dcloudio/uni-app";
	import { orderList } from "@/utils/network/api.js";
	import { request } from "@/utils/network/request.js";
	import { getItem, StorageKeys } from "@/utils/storage";
	import { stringToJson } from "@/utils/network/encryption";
	import {
		getCodeName
	} from "@/datas/queryKey.js";
	import {
		getVehiclePlateColor
	} from "@/datas/vehiclePlateColor";
	import { deviceType } from "@/utils/network/difference";
		import { jump } from "@/datas/9901Jump.js";
	const state = reactive({
		list: [],
		starts: false,
		pageSize: 10,
		pageNo: 1,
		flags: false,
	});
	onLoad(() => {
		quanCheckActionTrue()
	});


	const quanCheckActionTrue = () => {
		let source = ""
		// #ifdef MP-ALIPAY
		source = "ALI"
		// #endif
		// #ifdef MP-WEIXIN
		source = "WECHAT"
		// #endif
		var data = {
			opId: getItem(StorageKeys.OpenId),
			source: source,
			tabIndex: "0",
			isValueCard: "",
			pageNo: state.pageNo,
			pageSize: state.pageSize,
		};
		const options = {
			type: 2,
			data: data,
			method: "POST",
			showLoading: true,
		};
		request(orderList, options).then((res) => {
			let dataAll = [...state.list, ...stringToJson(res.bizContent).data]
			state.list =dataAll;
			console.log("state.list",state.list)
		})
	};

	const flag = ref("0");
	const choose = (i,item) => {
		console.log("item", item);
		if (item.deviceType == deviceType) {
			const params = encodeURIComponent(JSON.stringify(item))
			jump('19', params)
		}else{
			// #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
		}
	};
	onReachBottom(() => {
		if (state.list.length < state.pageNo * 10) return state.flags = true
		console.log("触底了")
		state.pageNo++
		quanCheckActionTrue();
	});
</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>