ts_aimz/pages/mine/mineAccount/mineCoupons/mineCoupons.js
2025-04-09 11:31:24 +08:00

147 lines
4.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import ProApi from '../../../../net/api/projectApi'
const app = getApp()
const deviceInfo = wx.getDeviceInfo()
const screenInfo = wx.getWindowInfo();
const statusBarHeight = screenInfo.statusBarHeight; // 状态栏高度
const navBarHeight = deviceInfo.platform == 'IOS' ? 48 : 50; // 导航栏高度iOS 为 44pxAndroid 为 48px
const windowHeight = screenInfo.windowHeight - navBarHeight - statusBarHeight; //可用内容高度
Page({
/**
* 页面的初始数据
*/
data: {
currentStatus: 1,
height: windowHeight,
couponsList: [], //订单列表
pageData: {
page: 1,
rows: 10,
isEffective: '',
isUsed: '',
}, //检索参数
loadingState: 'loading', //加载状态
listRefreshTrig: false, //list刷新状态
isLoadMore: false, //加载更多的状态
hasMore: true, //是否有更多数据
keywords: '', //搜索关键字
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
wx.setNavigationBarTitle({
title: '我的优惠卷',
})
wx.setNavigationBarColor({
frontColor: '#000000', // 必写项,字体颜色仅支持#ffffff和#000000
backgroundColor: '#F0F0F0', // 传递的颜色值,仅支持十六进制颜色
animation: { // 可选项
duration: 500,
timingFunc: 'easeIn'
}
})
//加载数据
this.doRefreshList()
},
//tab切换
doChangeStatus(e) {
const value = e.currentTarget.dataset.value
this.setData({
currentStatus: value
})
this.doRefreshList()
},
//获取我的优惠卷
doGetMyCoupons(isRefresh) {
const _self = this
_self.setData({
couponsList: isRefresh ? [] : _self.data.couponsList,
loadingState: isRefresh ? 'loading' : ''
})
ProApi.doGetCouponseList(_self.data.pageData)
.then(res => {
var status = 'success'
status = res.rows && res.rows.length > 0 ? 'success' : 'empty'
_self.setData({
loadingState: isRefresh ? status : '',
couponsList: _self.data.couponsList.concat(res.rows),
listRefreshTrig: false,
isLoadMore: false
})
_self.setData({
hasMore: _self.data.couponsList.length < res.total
})
}, err => {
_self.setData({
loadingState: 'error',
listRefreshTrig: false,
isLoadMore: false,
hasMore: true
})
})
},
//下拉刷新
doRefreshList() {
const _self = this
var isEffective = ''
var isUsed = ''
if (_self.data.currentStatus == 1) {
isEffective = 1
isUsed = 0
} else if (_self.data.currentStatus == 2) {
isEffective = ''
isUsed = 1
} else {
isEffective = 0
isUsed = 0
}
_self.setData({
listRefreshTrig: true,
loadingState: 'loading',
hasMore: true,
'pageData.page': 1,
'pageData.isEffective': isEffective,
'pageData.isUsed': isUsed,
isLoadMore: false
})
_self.doGetMyCoupons(true)
},
//加载更多
doLoadMore() {
//判断是否正在加载中 与是否存在更多数据
const _self = this
if (_self.data.isLoadMore || !_self.data.hasMore) {
return
}
var isEffective = ''
var isUsed = ''
if (_self.data.currentStatus == 1) {
isEffective = 1
isUsed = 0
} else if (_self.data.currentStatus == 2) {
isEffective = ''
isUsed = 1
} else {
isEffective = 0
isUsed = 0
}
_self.setData({
isLoadMore: true,
'pageData.page': ++_self.data.pageData.page,
'pageData.isEffective': isEffective,
'pageData.isUsed': isUsed,
})
_self.doGetMyCoupons(false)
},
//显示使用规则
showRule() {
const id = '89c4ca41-a44e-4ae2-bad3-6fa6536dd453'
wx.navigateTo({
url: '/pages/treaty/rule/rule?id=' + id,
})
}
})