<!-- 车辆提交记录 -->
<template>
	<!-- <view class="hint">电子标签请到线下网点领取</view> -->

	<view class="list">
		<view class="item" v-for="(item, index) in state.list" :key="item.name">
			<view class="head">
				<view class="name">
					<image :src="`${$imgUrl}issueActivation/icon-car.png`" class="icon"></image>
					<text class="title">{{ item.fvehPlateNo }}</text>
				</view>
				<view class="status text-green">{{ item.describe }}</view>
			</view>
			<view class="detail">
				<view class="orders">
					<view class="order-text">
						<text class="type">卡类型：</text>
						<text class="value">{{ cardType(item.fcardItemType) }}</text>
					</view>
					<view class="order-text">
						<text class="type">申请时间：</text>
						<text class="value">{{ item.fregisterDate }}</text>
					</view>
				</view>
			</view>
			<view class="btns" v-if="item.handleStatus === 4 || item.handleStatus === 5">
				<view class="btn btn-primary as-gravity-center" @click="btnClick(item)" v-if="item.handleStatus === 4">
					增补OBU
				</view>
				<view class="btn btn-primary as-gravity-center" @click="btnClick(item)" v-if="item.handleStatus === 5">
					增补OBU
				</view>
			</view>
		</view>
	</view>

	<!-- 支付承诺popup -->
	<u-popup v-model="state.showPayPopup" mode="center">
		<pay-undertake @paySuccess="state.showPayPopup = false"></pay-undertake>
	</u-popup>
</template>

<script setup lang="ts">
	import {
		reactive
	} from "vue";
	import {
		onLoad
	} from "@dcloudio/uni-app";
	import {
		msg,
		navTo
	} from '@/utils/utils';
	import {
		request
	} from "@/utils/network/request.js";
	import {
		gongWuCheTiJiaoJiLu
	} from "@/utils/network/api.js";
	import {
		stringToJson
	} from "@/utils/network/encryption";
	import {
		getVehiclePlateColor
	} from "@/datas/vehiclePlateColor.js";

	import payUndertake from "./components/popup-pay-undertake";

	const state = reactive({
		//显示支付承诺弹窗
		showPayPopup: false,
		deptId: 0,
		//记录列表 status: 1-审核中 2-制卡中 3-待支付 4-待激活 5-已完成
		list: [],
	});
	onLoad((option) => {
		state.deptId = option.deptId ? option.deptId : null;
		getListByDeptId(state.deptId)
	})
	const btnClick = (item : any) => {
		console.log(item);
		//去增补OBU
		if (item.handleStatus === 4 || item.handleStatus === 5) {
			navTo("/subpackage/personal-center/address?deptId=" + item.funitID + "&vehicleId=" + item.fvehPlateNo + "_" + item.fvehPlateColor);
		}
	};

	const cardType = (type : number) => {

		if (type == 51) {
			return "制式警车卡";
		} else if (type == 52) {
			return "路政执法卡";
		} else if (type == 53) {
			return "应急通行卡";
		} else if (type == 55) {
			return "国安特通卡";
		} else {
			return "未知卡类型";
		}

	}

	/* 搜索 */
	const getListByDeptId = (id : number) => {
		if (!state.deptId) {
			msg("请输入搜索关键字");
			return
		}
		// msg(state.searchInput);
		const options = {
			type: 2,
			data: {
				deptId: id,
			},
			method: "POST",
			showLoading: true,
		};
		request(gongWuCheTiJiaoJiLu, options).then((res) => {
			const result = stringToJson(res.bizContent)
			if (result.vehicleS && result.vehicleS.length > 0) {
				state.list = result.vehicleS
			}
		})
	}
</script>

<style>
	page {
		background-color: #eef7f7;
	}

	:deep(.u-mode-center-box) {
		border-radius: 20rpx;
	}
</style>
<style lang="scss" scoped>
	.hint {
		font-size: 26rpx;
		color: #ff8000;
		padding: 37rpx 34rpx 8rpx;
	}

	.list {
		padding: 30rpx 30rpx 0rpx;
		display: flex;
		flex-direction: column;
	}

	.list .item {
		background: #ffffff;
		box-shadow: 0rpx 2rpx 6rpx 0rpx rgba(223, 223, 223, 0.8);
		border-radius: 20rpx;
		box-sizing: border-box;
		display: flex;
		flex-direction: column;
		margin-bottom: 30rpx;
		min-height: 260rpx;
	}

	.list .item .head {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 20rpx 28rpx;
		border-bottom: 1px solid #dcdcdc;
	}

	.list .item .head .icon {
		width: 48rpx;
		height: 48rpx;
	}

	.list .item .head .name {
		display: flex;
		align-items: center;
	}

	.list .text-green {
		font-size: 26rpx;
		color: #00b38b;
	}

	.list .text-orange {
		font-size: 26rpx;
		color: #ff8000;
	}

	.list .title {
		font-size: 30rpx;
		color: #333;
		padding-left: 13rpx;
	}

	.list .detail {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 30rpx 32rpx;
	}

	.list .detail .type {
		font-size: 26rpx;
		color: #999;
	}

	.list .detail .value {
		font-size: 26rpx;
		color: #333;
	}

	.list .finished .detail .value {
		color: #999;
	}

	.list .detail .odd {
		margin: 20rpx 0;
	}

	.list .cny {
		font-size: 26rpx;
		color: #333;
	}

	.list .finished .cny {
		color: #999;
	}

	.list .amount {
		font-size: 40rpx;
		font-weight: bold;
	}

	.list .finished .amount {
		color: #999;
	}

	.list .btns {
		display: flex;
		align-items: center;
		justify-content: flex-end;
		border-top: 1px solid #dcdcdc;
		margin: 0 30rpx;
		padding: 20rpx 0;
	}

	.list .btn {
		height: 60rpx;
		// line-height: 60rpx;
		border-radius: 30rpx;
		padding: 0 24rpx;
		font-size: 26rpx;
		box-sizing: border-box;
		margin-right: 20rpx;
	}

	.list .btns .btn:last-child {
		margin: 0;
	}

	.list .btn-primary {
		border: 1px solid #00b38b;
		color: #00b38b;
	}

	.list .btn-normal {
		border: 1px solid #dcdcdc;
		color: #333;
	}
</style>