<template>
	<view class='content'>
		<view class='item' v-for="(item,index) in state.newList">
			<view>ETC卡号:{{item.cardId}}<text class="payStatus">{{item.payStatusC}}</text></view>
			<view>充值金额:￥{{item.rechargeMoney/100}}</view>
			<view>申请时间:{{item.insertTime}}</view>
			<view>圈存状态:{{item.chargeStatus}}</view>
		</view>
		<view style="text-align: center;margin: 20rpx;" v-if="state.flags">我是有底线的~</view>
	</view>
	<view class="noContent" v-if="!state.newList.length">暂无消费明细</view>
</template>

<script lang="ts" setup>
	import { reactive } from "vue";
	import { request } from "@/utils/network/request.js";
	import { queryCardRecord } from "@/utils/network/api.js";
	import { stringToJson } from "@/utils/network/encryption.js";
	import { onLoad, onReachBottom } from "@dcloudio/uni-app";
	import { getItem } from "@/utils/storage";
	import { getCodeName } from "@/datas/queryKey.js";
	const state = reactive({
		list: '',  //所有数据
		newList: '', //最终展示的
		cardId: '',
		value: '',//input框里的值
		pageNo: 1,
		pageSize: 16,
		flags: false,
	})
	onLoad((option : any) => {
		console.log("option", option)
		state.cardId = option.cardId;
		getList();
	})
	const getList = () => {
		const options = {
			type: 2,
			data: {
				'cardId': state.cardId,
				'openId': getItem('openId'),
				'pageNo': state.pageNo,
				'pageSize': state.pageSize
			},
			method: "POST",
			showLoading: true,
		};
		request(queryCardRecord, options).then((res) => {
			state.newList = [...stringToJson(res.bizContent).data, ...state.newList]
			for (var i = 0; i < state.newList.length; i++) {
				console.log("getCodeName", getCodeName('VCR_ORDER_STATUS', state.newList[i]['status']))
				state.newList[i]['payStatusC'] = getCodeName('VCR_ORDER_PAY_STATUS', state.newList[i]['payStatus'])
			}
			console.log("交易记录", state.newList)
		})
	}
	// 触底加载
	onReachBottom(() => {
		if (state.newList.length < state.pageNo * 16) return state.flags = true
		console.log("触底了")
		state.pageNo++
		getList()
	})
</script>

<style scoped>
	.noContent {
		text-align: center;
		margin-top: 100rpx;
	}

	.content {
		background-color: #EEF7F7;
		padding: 0 30rpx;
		overflow: hidden;
		font-size: 32rpx;
	}

	.search_wrap {
		display: flex;
		margin: 20rpx 0;
	}

	.search_wrap>input {
		background-color: white;
		width: 76%;
		height: 40rpx;
		line-height: 40rpx;
		padding: 10rpx 10rpx;
		border-radius: 10rpx 0 0 10rpx;
	}

	.item {
		width: 100%;
		border-radius: 10rpx;
		box-sizing: border-box;
		padding: 30rpx 20rpx;
		margin-top: 30rpx;
		/* background:linear-gradient(-90deg, #43a1e0 0%, #13e7c1 100%); */
		background: white;
		color: black;
	}

	.time {
		display: flex;
		margin-bottom: 16rpx;
		justify-content: space-between;
	}

	.payStatus {
		color: red;
		float: right;
	}
</style>