<template>
	<view class="page">
		<view class="content">
			<mescroll-body      ref="mescrollRef" @init="mescrollInit" :up="upOption" :down="downOption" @down="downCallback" @up="upCallback">
			<view class="logs-item" v-for="(item) in dataList">
				<view class="left">
					<text class="title"  >
						{{ utils.getDictLabelNames(typeOptions,item.logType) }}
					</text>
					<view class="time">{{item.createTime}}</view>
				</view>
				<view class="right">
					<text  :class="item.integral>0?'money green':'money red'">{{item.integral}}</text>
					<text class="remark">剩余积分:{{item.balance}}</text>
				</view>
			</view>
			</mescroll-body>
		</view>
	</view>
</template>

<script>
	import {getDictByKey} from '@/api/common.js'
	import {getUserIntegralLogsList} from '@/api/store.js'
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	export default {
		mixins: [MescrollMixin], // 使用mixin
		data() {
			return {
				typeOptions:[],
				mescroll:null,
				downOption: {
					auto:false//不要自动加载
				},
				upOption: {
					onScroll:false,
					use: true, // 是否启用上拉加载; 默认true
					page: {
						num: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
						size: 20 // 每页数据的数量,默认10
					},
					noMoreSize: 10, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
					textNoMore:"已经到底了",
					empty: {
						icon:'https://cos.his.cdwjyyh.com/fs/20240423/cf4a86b913a04341bb44e34bb4d37aa2.png',
						tip: '暂无数据'
					}
				},
				dataList: []
				 
			}
		},
		onLoad() {
			this.getDictByKey("sys_integral_log_type");
		},
		methods: {
			getDictByKey(key){
				var data={key:key}
				getDictByKey(data).then(
					res => {
						if(res.code==200){
							this.typeOptions=res.data;
						}
					},
					err => {
					}
				);
				
			},
			mescrollInit(mescroll) {
				this.mescroll = mescroll;
			},
			/*下拉刷新的回调 */
			downCallback(mescroll) {
				mescroll.resetUpScroll()
			},
			upCallback(page) {
				//联网加载数据
				var that = this;
				var data = {
					pageNum: page.num,
					pageSize: page.size
				};
				uni.showLoading({
					title:"加载中..."
				})
				getUserIntegralLogsList(data).then(res => {
					uni.hideLoading()
					if(res.code==200){
						//设置列表数据
						if (page.num == 1) {
							that.dataList = res.data.list; 
							
						} else {
							that.dataList = that.dataList.concat(res.data.list);
							 
						}
						that.mescroll.endBySize(res.data.list.length, res.data.total);
						
					}else{
						uni.showToast({
							icon:'none',
							title: "请求失败",
						});
						that.dataList = null;
						that.mescroll.endErr();
					}
				});
			},
			 
		}
	}
</script>

<style lang="scss" scoped>
	.page{
	}
	.content{
		.logs-item{
			width:calc(100% - 20rpx);
			background-color: #fff;
			padding: 20rpx 10rpx;
			display: flex;
			align-items: flex-start;
			justify-content: space-between;
			border-top: 1rpx solid #efefef;
			.left{
				display: flex;
				flex-direction: column;
				align-items: flex-start;
				justify-content: flex-start;
				.title{
					font-size: 26rpx;
					color: #111;
				}
				.time{
					margin-top: 20rpx;
					font-size: 24rpx;
					color: #a5a5a5;
				}
			}
			.right{
				display: flex;
				flex-direction: column;
				align-items: flex-end;
				justify-content: flex-end;
				.money{
					font-size: 28rpx;
					font-weight: bold;
					color: #111;
				}
				.green{
					color: green;
				}
				.red{
					color:#ff0000;
				}
				.remark{
					margin-top: 20rpx;
					font-size: 24rpx;
					color: #a5a5a5;
					.green{
						color: green;
					}
					.red{
						color: red;
					}
				}
			}
		}
		
	}
	 
</style>
