<template>
	<view class="content">
		<view class="top-content">
			<view class="example-body">
				<!-- <uni-datetime-picker v-model="state.range" type="daterange" /> -->
				<text>请选择月份：</text>
				<picker mode="date" @change="bindDateChange" fields="month">
					<view class="uni-input">{{state.date}}</view>
				</picker>
				<button size="mini" style="color: #ffffff;
				backgroundColor: rgb(118, 200, 77);
				borderColor: rgb(118, 200, 77);
				font-size: 26rpx;
				flex-shrink: 0;margin-left: 20rpx;" @click="search()">搜索</button>
			</view>
		</view>


		<view class="uni-container" v-if="state.listData.length>0">
			<view class="list-item" v-for="(item,index) in state.listData">
				<view><text>姓名：</text><text>{{item.customerName}}</text></view>
				<view><text>证件号码：</text><text>{{item.customerIdNum}}</text></view>
				<view><text>通行次数：</text><text>{{item.num}}</text></view>
				<view><text>通行年月：</text><text>{{item.handleDate}}</text></view>
				<view><text>通行车牌号：</text><text>{{state.vehicleNum}}</text></view>
				<view><text>通行车牌颜色：</text><text>{{state.vehicleColor}}</text></view>
				<view><text>月通行总额：</text><text>{{item.money/100}}元</text></view>
			</view>
			<view class="bottom-line" v-if="state.flags">我是有底线的~~~</view>
		</view>
		<!-- <view v-else class="uni-container" style="text-align: center;">
			暂无数据
		</view> -->

	</view>

</template>

<script setup lang="ts">
	import { reactive } from "vue";
	import {
		businessType
	} from "@/datas/businessType.js"
	import empty from "@/components/empty/empty.vue";
	import { onLoad, onReachBottom } from "@dcloudio/uni-app";
	import { monthStatementApi, getUserMsg } from "@/utils/network/api.js";
	import { stringToJson } from "@/utils/network/encryption";
	import { request } from "@/utils/network/request.js";
	import { getItem, StorageKeys } from "@/utils/storage";
	import { getVehiclePlateColor } from "@/datas/vehiclePlateColor";
	import { msg } from "@/utils/utils";
	const state = reactive({
		startTime: Date.now(), //日期
		listData: [],
		range: ['', ''],
		flags: false,
		vehicleId: "",
		customerIdNum: "",
		vehicleNum: "",
		vehicleColor: "",
		date: "请选择月份"
	})
	onLoad((option) => {
		console.log("option", option.vehicleId)
		state.vehicleId = option.vehicleId;
		state.vehicleNum = option.vehicleId.split('_')[0];
		console.log("option.vehicleId.split('_')[1]", getVehiclePlateColor(option.vehicleId.split('_')[1]))
		state.vehicleColor = getVehiclePlateColor(option.vehicleId.split('_')[1]);
		getUserinfo()
	})
	const bindDateChange = (e) => {
		state.date = e.detail.value
	}
	const getUserinfo = () => {
		const options = {
			type: 2,
			data: { openId: getItem('openId') },
			method: "POST",
			showLoading: true,
		};
		request(getUserMsg, options).then((res) => {
			const data = stringToJson(res.bizContent);
			console.log(data, "用户信息");
			state.customerIdNum = data.customerIdNum
		});
	}
	//业务完成日志
	const search = () => {
		if (state.date == '请选择月份') {
			msg("请选择月份");
			return;
		}
		var data = {
			startTime: state.date,
			// endTime: state.range[1],
			vehicleId: state.vehicleId,
			customerIdNum: state.customerIdNum
		};
		const options = {
			type: 2,
			data: data,
			method: "POST",
			showLoading: true,
		};

		request(monthStatementApi, options).then((res) => {
			const data = stringToJson(res.bizContent);
			state.listData = stringToJson(res.bizContent).data
			console.log("业务完成日志", state.listData,)
		});
	}
</script>

<style scoped>
	.top-content {
		position: fixed;
		left: 0;
		top: 0;
		background-color: white;
		width: 100%;
		padding: 20rpx;
		box-sizing: border-box;
	}

	.content {
		font-size: 32rpx;
		padding: 20rpx 30rpx;
		background-color: #EEF7F7;
		min-height: 100vh;
	}

	.card {
		display: flex;
		margin: 0 20rpx;
		align-items: center;
	}

	.title {
		margin-bottom: 20rpx;
	}

	.uni-container {
		margin: 50rpx 0;
		margin-top: 150rpx;
	}

	/* /deep/.uni-table-th,
	/deep/.uni-table-td {
		padding: 0 !important;
		font-size: 12px !important;
	}

	/deep/.uni-date__x-input,
	/deep/.uni-select {
		font-size: 13px;
		height: 30px;
		line-height: 30px;
	}

	/deep/.uni-stat__select {
		width: 360rpx;
	}

	/deep/.uni-select__selector-empty,
	/deep/.uni-select__selector-item {
		font-size: 13px !important;
	}

	/deep/.uni-date {
		width: 73% !important;
	} */

	.example-body {
		display: flex;
		align-items: center;
		margin-top: 20rpx;
	}

	/deep/.uni-date-x {
		height: 76rpx !important;
	}

	.list-item {
		width: 95%;
		border-radius: 10rpx;
		margin: 30rpx auto;
		font-size: 28rpx;
		border: 1rpx solid #ccc;
		padding: 12rpx;
		box-sizing: border-box;
		background-color: white;
	}

	.list-item>view {
		margin-bottom: 10rpx;
	}

	.bottom-line {
		text-align: center;
		margin: 30rpx 0;
	}

	.uni-input {
		width: 200rpx;
		border: 1rpx solid #ccc;
		border-radius: 10rpx;
	}
</style>