<template>
	<view class="page">
		<u-navbar title="账变明细" :border-bottom="false" :background="bgc" back-icon-color="#fff" title-color="#fff"
			title-size="36" height="36" id="navbar" />
		<scroll-view @scrolltolower="handqixing" scroll-y class="date-group">
			<view class="" v-for="(item,index) in billList" :key="index">
				<view class="date-title">{{ item.createTime }}</view>
				<view class="bill-item">
					<view class="bill-icon">
						<image src="https://api.ccttiot.com/smartmeter/img/static/uapbko4I0h8YiLO48kFD" mode="aspectFill"
							class="icon-img" />
					</view>
					<view class="bill-info">
						<view class="bill-type" v-if="item.type == 1">充值</view>
						<view class="bill-type" v-if="item.type == 2">赠送</view>
						<view class="bill-type" v-if="item.type == 3">消费</view>
						<view class="bill-detail">
							<text class="bill-time">{{ item.storeName }}</text>
							<text class="bill-id">| {{ item.reason }}</text>
						</view>
					</view>
					<view :class="['bill-amount', item.amount > 0 ? 'plus' : 'minus']">
					  <text v-if="item.type == 1">+</text>	
					  <text v-if="item.type == 2">+</text>
					  <text v-if="item.type == 3">-</text>
					  {{ item.amount.toFixed(2) }}
					</view>
				</view>
			</view>
			<view class="" style="width: 100%;text-align: center;margin-top: 30rpx;color: #ccc;">
				当前没有更多账变记录了...
			</view>
		</scroll-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				bgc: {
					backgroundColor: "#010000",
				},
				billList: [],
				pageNum: 1,
				total: 0
			}
		},
		onLoad() {
			this.getzb()
		},
		methods: {
			// 上拉加载更多
			handqixing() {
				if (this.total > this.billList.length) {
					this.getzb()
				} else {
					console.log(11);
				}
			},
			// 获取账变信息
			getzb() {
				this.$u.get(`/app/balanceLog/list?storeId=${this.$store.state.storeId}&pageNum=${this.pageNum}&pageSize=20`).then(res => {
					if (res.code == 200) {
						this.total = res.total
						if (this.pageNum == 1) {
							this.billList = res.rows
							this.pageNum++
						} else {
							this.billList = this.billList.concat(res.rows)
							this.pageNum++
						}
					}
				})
			},
		}
	}
</script>

<style lang="scss">
	.page {
		background: #010000;
		min-height: 100vh;
		padding: 0 0 20rpx 0;
	}

	.date-group {
		background: #18171b;
		border-radius: 20rpx;
		padding: 0 0 10rpx 0;
		height: 87vh;
		overflow: scroll;
		box-sizing: border-box;
	}

	.date-title {
		color: #fff;
		font-size: 28rpx;
		font-weight: 500;
		padding: 24rpx 0 10rpx 24rpx;
	}

	.bill-item {
		display: flex;
		align-items: center;
		background: #232228;
		border-radius: 16rpx;
		margin: 0 16rpx 16rpx 16rpx;
		padding: 18rpx 20rpx;
	}

	.bill-icon {
		width: 64rpx;
		height: 64rpx;
		background: #f7e6e6;
		border-radius: 50%;
		display: flex;
		align-items: center;
		justify-content: center;
		margin-right: 20rpx;
	}

	.icon-img {
		width: 40rpx;
		height: 40rpx;
	}

	.bill-info {
		flex: 1;
		display: flex;
		flex-direction: column;
		justify-content: center;
	}

	.bill-type {
		color: #fff;
		font-size: 28rpx;
		font-weight: 500;
	}

	.bill-detail {
		color: #bdbdbd;
		font-size: 22rpx;
		margin-top: 4rpx;
	}

	.bill-time {
		margin-right: 8rpx;
	}

	.bill-id {
		margin-left: 8rpx;
	}

	.bill-amount {
		font-size: 32rpx;
		font-weight: 600;
	}

	.bill-amount.plus {
		color: #ff5e5e;
	}

	.bill-amount.minus {
		color: #bdbdbd;
	}
</style>