<template>
	<view class="pay">
		<view class="item" v-for="(a,i) in list" :key="i">
			<view class="a">
				<view class="fl">订单号</view>
				<view class="fr">{{a.order_no}}</view>
			</view>
			<view class="a">
				<view class="fl">事件标题</view>
				<view class="fr">{{a.title}}</view>
			</view>
			<view class="a">
				<view class="fl">支付时间</view>
				<view class="fr">{{a.paytime}}</view>
			</view>
			<view class="a">
				<view class="fl">订单金额</view>
				<view class="fr frs">￥{{a.money}}<text @click="openPage(a.content_id)">查看事件</text></view>
			</view>
		</view>
		
		<view class="empty" v-if="total == 0">
			<image src="https://www.lijkj.cn/static/empty.png"></image>
			<view class="txt">暂无数据 ~</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				offset: 1,
				total: 1,
				list: [],
			};
		},
		mounted() {
			this.getList();
		},
		onReachBottom() {
			const that = this;
			uni.showLoading({
				title: "加载中"
			})
			if(this.list.length <= this.total){
				that.offset ++;
				setTimeout(function() {
					that.getList(1);
				}, 1000);
			}
		},
		methods: {
			//数组对象去重
			arrayUnique (arr, name) {
				var hash = {};
				return arr.reduce(function (item, next) {
					hash[next[name]]
						? ""
						: (hash[next[name]] = true && item.push(next));
					return item;
				}, []);
			},
			async getList(type) {
				const that = this;
				const { code, data } = await that.$api.getorderlist({
					offset: this.offset,
					limit: 20,
					token: uni.getStorageSync("token")
				})
				if(code == 1){
					if(type==1){
						uni.hideLoading();
					}
					that.list = this.arrayUnique([...that.list,...data.rows],'order_no');
					that.total = data.total;
				}
			},
			openPage(id){
				uni.navigateTo({
					url: "/pages/release/detail?id="+id
				})
			},
		}
	}
</script>

<style scoped lang="scss">
.pay{
	padding: 0 25rpx 25rpx;
	overflow: hidden;
	.empty{
		padding: 150rpx 0;
		text-align: center;
		font-size: 26rpx;
		color: #666;
		image{
			width: 460rpx;
			height: 400rpx;
			margin-bottom: 30rpx;
		}
	}
	.item{
		width: 100%;
		height: 257rpx;
		background: #FFFFFF;
		box-shadow: 0px 3rpx 10rpx 0px rgba(9,44,39,0.05);
		border-radius: 20rpx;
		padding: 20rpx 30rpx;
		box-sizing: border-box;
		margin-top: 20rpx;
		.a{
			font-weight: 500;
			font-size: 28px;
			color: #999999;
			display: flex;
			align-items: center;
			justify-content: space-between;
			line-height: 55rpx;
			.fl{
				width: 140rpx;
				text-align: left;
				font-weight: 500;
				font-size: 28rpx;
				color: #999999;
			}
			.fr{
				flex: 1;
				font-weight: 500;
				font-size: 28rpx;
				color: #333333;
				text{
					float: right;
					font-weight: 500;
					font-size: 28rpx;
					color: #00C6A9;
					float: right;
				}
			}
			.frs{
				color: #D80C0C;
			}
		}
	}
}
</style>
