<template>
	<view class="content">
		<view class="order-wrap" v-for="item in list">
			<view class="tit">
				订单编号：{{item.subscribe_id || item.order_id}}
			</view>
			<view class="tit" v-if="type == 1">
				支付方式：{{item.pay_type == 'yue'?'余额': (item.pay_type == 'weixin'?'微信':'支付宝')}}
			</view>
			<view class="tit" v-if="type == 1">
				打赏金额：{{item.pay_price}}
			</view>
			<view class="tit" v-if="type == 2">
				投诉原因：{{item.reason}}
			</view>
			<view class="tit">
				{{type == 1? '打赏时间':'投诉时间'}}：{{showTime( type == 1 ? item.add_time: item.create_time)}}
			</view>
		</view>
		<emptyPage title="暂无充值记录～" v-if="list.length == 0 && loaded"></emptyPage>
	</view>
</template>

<script>
	import emptyPage from '@/components/emptyPage.vue'
	import {
		getLifeOrder,
		getReward,
		getComplaint
	} from '@/api/three.js'
	export default {
		components: {
			emptyPage
		},
		data() {
			return {
				list: [],
				page: 1,
				limit: 10,
				loaded: false,
				loadingType: 'more',
				type: 1,
			}
		},
		onLoad(opt) {
			this.type = opt.type;
			this.getLifeOrder()
		},
		onShow() {

		},
		onReachBottom() {
			this.getLifeOrder()
		},
		onReady() {

		},
		methods: {
			showTime(time) {
				// 创建一个Date对象，参数为时间戳
				let timestamp = time * 1000; // 例如：时间戳为1626864000000
				let date = new Date(timestamp);

				// 获取年、月、日等信息
				let year = date.getFullYear();
				let month = date.getMonth() + 1; // 月份是从0开始计数的，所以要加1
				let day = date.getDate();
				let hours = date.getHours();
				let minutes = date.getMinutes();
				let seconds = date.getSeconds();

				// 格式化输出时间
				return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;

			},
			getLifeOrder() {
				let that = this
				if (that.loadingType == 'loading' || that.loadingType == 'noMore') {
					return
				}
				that.loadingType = 'loading'
				let getList;
				if (that.type == 1) {
					getList = getReward
				} else if (that.type == 2) {
					getList = getComplaint
				}
				getList({
					page: that.page,
					limit: that.limit,
				}).then(res => {
					let arr = res.data.data
					that.list = that.list.concat(arr)
					if (arr.length == that.limit) {
						that.loadingType = 'more'
						that.page++
					} else {
						that.loadingType = 'noMore'
					}
					that.loaded = true
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		padding-top: 20rpx;
	}

	.order-wrap {
		width: 690rpx;
		background-color: #fff;
		margin: 0 auto 20rpx;
		padding: 20rpx 34rpx;
		border-radius: 20rpx;

		.tit {
			font-size: 30rpx;
			font-weight: bold;
		}

		.price {
			text-align: right;
		}
	}
</style>