1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- import { couponListApi } from '../../api/other';
- Page({
- data: {
- couponList: [],
- page: 1,
- pageSize: 10,
- loadingMore: false,
- noMore: false,
- refreshing: false
- },
- onLoad() {
- this.loadData(true);
- },
- async loadData(isRefresh = false) {
- if (this.data.loadingMore) return;
- let page = isRefresh ? 1 : this.data.page;
- this.setData({ loadingMore: true });
- try {
- const res = await couponListApi({ page, pageSize: this.data.pageSize });
- const statusImgMap = {
- 0: '/static/image/whx.png', // 未核销
- 1: '/static/image/yhx.png' // 已核销
- };
- const newList = res.data.list || [];
- let allList = isRefresh ? newList : [...this.data.couponList, ...newList];
- allList = allList.map(item => ({
- ...item,
- statusImg: statusImgMap[item.verify_status] || '/static/image/whx.png',
- }));
- this.setData({
- couponList: allList,
- loadingMore: false,
- page: page + 1,
- noMore: allList.length >= res.data.total,
- refreshing: false
- });
- } catch (err) {
- console.error(err);
- wx.showToast({ title: '加载失败', icon: 'none' });
- this.setData({
- loadingMore: false,
- refreshing: false
- });
- }
- },
- // 上拉触底
- onReachBottom() {
- if (this.data.noMore) return;
- this.loadData();
- },
- // 下拉刷新
- onPullDownRefresh() {
- if (this.data.refreshing) return;
- this.setData({ refreshing: true, noMore: false, page: 1 });
- this.loadData(true);
- },
- goPage(e) {
- const coupon = e.currentTarget.dataset.item;
- wx.navigateTo({
- url: `/pages/couponDetail/couponDetail?id=${coupon.id}&status=${coupon.verify_status}`
- });
- }
- });
|