<script setup>
	/**
	 * 积分变动明细
	 */

	import {
		ref,
		reactive,
		computed,
	} from 'vue'
	import {
		onLoad,
		onReachBottom,
		onPullDownRefresh
	} from '@dcloudio/uni-app'
	// 顶部
	import apex from '/components/header/apex'
	import intergralApi from '@/api/intergral.js';
	// 工具库
	import util from '@/common/js/util.js'

	//积分变动记录
	const scrollLog = reactive({
		data: [],
		pageNum: 1,
		pageSize: 30,
		total: 0,
	})

	onLoad(() => {
		// 获取列表
		getList()
	})

	onPullDownRefresh(() => {
		// 刷新列表
		refreshList()
	})

	onReachBottom(() => {
		// 获取更多列表
		getMoreList()
	})

	// 刷新列表
	function refreshList() {
		scrollLog.homePageSize = 1
		getList()
	}

	// 获取更多列表
	function getMoreList() {
		if (scrollLog.total <= scrollLog.data.length) return
		scrollLog.pageNum++
		getList()
	}

	// 积分变动明细
	function getList() {
		intergralApi.scrollChange({
			query: {
				pageNum: scrollLog.pageNum,
				pageSize: scrollLog.pageSize,
			}
		}).then(rs => {
			if (rs.code == 200) {
				// 第一页
				if (scrollLog.pageNum == 1) scrollLog.data.length = 0
				// 合并
				scrollLog.data.push(...rs.rows)
				// 总数
				scrollLog.total = rs.total
				return
			}
			util.alert({
				content: rs.msg,
				showCancel: false,
			})
		}).finally(() => {
			// 停止下拉刷新
			uni.stopPullDownRefresh()
		})
	}

	/**
	 * 选择日期
	 // * @param {Object} ev 默认事件携带参数
	 */
	function handleDate(ev) {
		// 
	}
</script>

<template>
	<view class="app">
		<apex title="变动明细">
			<template #right v-if="0">
				<picker mode="date" @change="handleDate" fields="month">
					<uni-icons type="more-filled" size="40rpx" color="#333" />
				</picker>
			</template>
		</apex>

		<view class="list">
			<view class="li" v-for="(item,index) in scrollLog.data" :key="index">
				<view class="item rows ptb30 plr20 bfff">
					<view class="col oh f1">
						<view class="c333 f36">
							<!-- 间推 用户 为您当前一级卷轴(1)加速释放0.3 -->
							{{item.context}}
						</view>
						<view class="mt20 c666 f28">{{item.createTime}}</view>
					</view>
					<view class="change fs0 c333 f36" v-if="Number(item.scroll) != 0">
						<text v-if="Number(item.scroll) > 0">+</text>
						<text>{{item.scroll}}</text>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<style lang="scss">
	// 
</style>