<template>
	<ax-body>
		<view class="body app-hide-scrollbar">
			<view v-if="logs.data.length" class="list">
				<view v-for="(item, index) in logs.data" :key="index" class="item">
					<view class="title">
						<view class="name">{{ item.params.levelName }}</view>
						<view class="state" :style="{ backgroundColor: item.orderStatus == 2 ? '' : '#FF5D50' }">
							{{ getStatusTips(item.orderStatus) }}</view>
					</view>
					<view class="cell">
						<view>订单编号：{{ item.orderNo }}</view>
						<view>购券时间：{{ item.createTime }}</view>
						<view>实付金额：{{ item.orderMoney }}元</view>
						<view class="backTaxAmount" v-if="item.backTaxAmount && item.backTax === 0">
							<view class="">超充金额：{{ item.backTaxAmount }}元</view>
							<view>|</view>
							<view class="check-backTaxAmount" @click="topage_order(item)">查看超充订单</view>
						</view>
						<view v-if="item.ZTBackMoney">返回智停端补缴金额：{{ item.ZTBackMoney }}</view>
						<view v-if="item.backTaxAmount && item.backTax === 0">可抵扣余量：{{ item.orderMoney -
							item.backTaxAmount }}元
						</view>
						<view v-if="item.orderStatus == 4">退款时间：{{ item.refundTime }}</view>
						<view v-if="item.orderStatus == 4">退款金额：{{ item.refundMoney }}元</view>
					</view>
				</view>
				<view v-if="logs.total > logs.data.length" @click="loadData(true)" class="loadmore">
					<text>点击加载更多数据</text>
				</view>
			</view>
			<view v-else class="nothing">
				<image src="@/static/img/empty.svg" mode="widthFix" class="icon"></image>
				<view>暂无可展示数据</view>
			</view>
		</view>
	</ax-body>
</template>

<script>
export default {
	onLoad() {
		this.loadData();
	},
	data() {
		return {
			logs: {
				total: 0,
				data: [],
			},
			search_data: {
				pageNum: 1,
				pageSize: 10
			}
		}
	},
	methods: {
		getStatusTips(status) {
			if (status == 2) {
				return "已到账"
			} else if (status == 4) {
				return "已退款"
			} else if (status == 5) {
				return "退款中"
			} else if (status == 3) {
				return "已取消"
			} else if (status == 1) {
				return "待支付"
			}
		},
		loadData(append) {
			const currentPage = this.search_data.pageNum;
			if (append) {
				this.search_data.pageNum++;
			} else {
				this.search_data.pageNum = 1;
			}
			// 订单状态 1 待支付 2 已支付 3 已取消 4 已退款
			this.$api.base("post", "/applet/v1/order/getTicketRecords", this.search_data, {})
				.then(res => {
					if (!append || currentPage + 1 === this.search_data.pageNum) {
						if (append) {
							this.logs.data = this.logs.data.concat(res.data.records);
						} else {
							this.logs.total = res.data.total;
							this.logs.data = res.data.records;
						}
					}
				})
				.catch(error => {
					if (append) {
						this.search_data.pageNum = currentPage;
					}
					console.error('获取充值记录失败:', error);
				});
		},
		topage_order(item) {
			this.$app.url.goto('/subPackages/order/order-detail/order-detail?orderId=' + item.chargeOrderId);
		}
	}
}
</script>

<style scoped>
@import url("recharge-log.css");
</style>
