<template>
	<view class="content">
		<view class="top-content">
			<view class="input">
				<text>车牌号：</text>
				<input placeholder="请输入车牌号" v-model="state.vehiclePlate" />
			</view>
			<view class="item last">
				<text>车牌颜色：</text>
				<uni-data-select v-model="state.vehiclePlateColor" :localdata="state.colorRange" @change="changeColor"
					:clear="false"></uni-data-select>
				<button size="mini" style="color: #ffffff;
					background-color: rgb(118, 200, 77);
					border-color: rgb(118, 200, 77);
					font-size: 26rpx;
					flex-shrink: 0;margin-left: 30rpx;" @click="search(1)">搜索</button>
			</view>
		</view>


		<view class="uni-container">
			<view class="list-item" v-for="(item,index) in state.listData">
				<view>
					<view><text>车牌号：</text><text>{{item.vehiclePlate}}</text></view>
					<view><text>金额：</text><text>{{item.amount/100}}元</text></view>
					<view v-if="item.cardId"><text>卡号：</text><text>{{item.cardId}}</text></view>
					<view><text>单号：</text><text>{{item.orderNo}}</text></view>
					<view><text>状态：</text><text>{{item.statusC}}</text></view>
					<view><text>退费类型：</text><text>{{item.businessPortC}}</text></view>
					<view><text>创建时间：</text><text>{{item.insertTime}}</text></view>
					<view><text>审核时间：</text><text>{{item.updateTime}}</text></view>
				</view>
			</view>
			<view style="text-align: center;" v-if="state.noData">暂无数据</view>
		</view>
		<view class="bottom-line" v-if="state.flags">我是有底线的~~~</view>
	</view>

</template>

<script setup lang="ts">
	import { reactive } from "vue";
	import {
		msg
	} from "@/utils/utils";
	import {
		businessType
	} from "@/subpackage/after-sale/js/businessType.js"
	import { onLoad, onReachBottom } from "@dcloudio/uni-app";
	import { cancellRefoundApi } from "@/utils/network/api.js";
	import { stringToJson } from "@/utils/network/encryption";
	import { request } from "@/utils/network/request.js";
	import { getItem, StorageKeys } from "@/utils/storage";
	const state = reactive({
		startTime: Date.now(), //日期
		colorRange: [],
		listData: [],
		range: ['', ''],
		pageSize: 10,  //每页数据量
		pageNo: 1,	// 当前页
		total: 0,	// 数据总量
		flags: false,
		vehiclePlate: "",
		vehiclePlateColor: "",
		statusArr: [],//状态
		refundBusinessArr: [],
		noData: false  //是否有数据
	})
	onLoad((option) => {
		let getColor = getItem('key')['VEHICLE_COLOR_TYPE'];
		for (var k = 0; k < getColor.length; k++) {
			let obj = {};
			obj['value'] = getColor[k]['code']
			obj['text'] = getColor[k]['name']
			state.colorRange.push(obj)
		}
		// REFUND_STATUS 退费管理-退费状
		let getStatus = getItem('key')['REFUND_STATUS'];
		for (var k = 0; k < getStatus.length; k++) {
			let obj = {};
			obj['value'] = getStatus[k]['code']
			obj['text'] = getStatus[k]['name']
			state.statusArr.push(obj)
		}
		console.log("state.statusArr", state.statusArr)
		// REFUND_BUSINESS 退费管理-退费业务类型
		let refundBusiness = getItem('key')['REFUND_BUSINESS'];
		for (var k = 0; k < refundBusiness.length; k++) {
			let obj = {};
			obj['value'] = refundBusiness[k]['code']
			obj['text'] = refundBusiness[k]['name']
			state.refundBusinessArr.push(obj)
		}
	})

	const changeColor = (e) => {
		state.vehiclePlateColor = e
		console.log(e)
	}
	//业务完成日志
	const search = (val) => {
		if (!state.vehiclePlate) {
			msg("请输入车牌号")
			return;
		}
		if (!state.vehiclePlateColor) {
			msg("请选择车牌颜色")
			return;
		}
		if (val == 1) {
			state.pageNo = 1
		}
		if (state.pageNo == 1 && state.listData.length > 0) {
			state.listData = []
		}
		var data = {
			vehicleId: state.vehiclePlate + "_" + state.vehiclePlateColor,
			pageNo: state.pageNo,
			pageSize: state.pageSize,
		};
		const options = {
			type: 2,
			data: data,
			method: "POST",
			showLoading: true,
		};
		request(cancellRefoundApi, options).then((res) => {
			const data = stringToJson(res.bizContent);
			console.log("getData", data)
			if (data.totalCount == 0) {
				state.noData = true
			} else {
				state.noData = false
			}
			if (data.data) {
				var getData = [...stringToJson(res.bizContent).data, ...state.listData]
				for (var i = 0; i < getData.length; i++) {
					for (var m = 0; m < state.statusArr.length; m++) {
						if (getData[i]['status'] == state.statusArr[m]['value']) {
							getData[i]['statusC'] = state.statusArr[m]['text']
							break;
						}
					}
					for (var m = 0; m < state.refundBusinessArr.length; m++) {
						if (getData[i]['businessPort'] == state.refundBusinessArr[m]['value']) {
							getData[i]['businessPortC'] = state.refundBusinessArr[m]['text']
							break;
						}
					}
				}
				state.listData = getData
				state.total = state.listData.length
			}

		});
	}
	// 触底加载
	onReachBottom(() => {
		if (state.listData.length < state.pageNo * 10) return state.flags = true
		console.log("触底了")
		state.pageNo++
		search(2)
	})
</script>

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

	.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: 180rpx;
	}

	/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: 24px;
		line-height: 24px;
	}

	/deep/.last .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: 56rpx !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;
		display: flex;
		align-items: center;
	}

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

	.list-item>view>view>text:first-child {
		width: 25%;
		display: inline-block;
	}

	.list-item>view>view>text:last-child {
		width: 75%;
		display: inline-block;
	}

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

	.item {
		display: flex;
		font-size: 30rpx;
		margin-top: 20rpx;
		align-items: center;
	}

	input,
	.uni-input {
		border: 1rpx solid #ccc;
		padding: 0 10rpx;
		height: 28rpx;
		line-height: 28rpx;
	}


	.input {
		display: flex;
		align-items: center;

	}

	.input>input {
		width: 47%;
		margin-top: 10rpx;
		font-size: 30rpx;
		margin-left: 20rpx;
	}
</style>