2025-03-31 18:23:29 +08:00
|
|
|
|
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 为 44px,Android 为 48px)
|
|
|
|
|
const windowHeight = screenInfo.windowHeight - navBarHeight - statusBarHeight; //可用内容高度
|
|
|
|
|
Page({
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 页面的初始数据
|
|
|
|
|
*/
|
|
|
|
|
data: {
|
|
|
|
|
currentStatus: 1,
|
2025-04-07 18:00:30 +08:00
|
|
|
|
height: windowHeight,
|
|
|
|
|
couponsList: [], //订单列表
|
|
|
|
|
pageData: {
|
|
|
|
|
page: 1,
|
|
|
|
|
rows: 10,
|
|
|
|
|
isEffective: '',
|
|
|
|
|
isUsed: '',
|
|
|
|
|
}, //检索参数
|
|
|
|
|
loadingState: 'loading', //加载状态
|
|
|
|
|
listRefreshTrig: false, //list刷新状态
|
|
|
|
|
isLoadMore: false, //加载更多的状态
|
|
|
|
|
hasMore: true, //是否有更多数据
|
|
|
|
|
keywords: '', //搜索关键字
|
2025-03-31 18:23:29 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 生命周期函数--监听页面加载
|
|
|
|
|
*/
|
|
|
|
|
onLoad(options) {
|
2025-04-07 18:00:30 +08:00
|
|
|
|
wx.setNavigationBarTitle({
|
|
|
|
|
title: '我的优惠卷',
|
|
|
|
|
})
|
|
|
|
|
wx.setNavigationBarColor({
|
|
|
|
|
frontColor: '#000000', // 必写项,字体颜色仅支持#ffffff和#000000
|
|
|
|
|
backgroundColor: '#F0F0F0', // 传递的颜色值,仅支持十六进制颜色
|
|
|
|
|
animation: { // 可选项
|
|
|
|
|
duration: 500,
|
|
|
|
|
timingFunc: 'easeIn'
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
//加载数据
|
2025-03-31 18:23:29 +08:00
|
|
|
|
this.doRefreshList()
|
2025-04-07 18:00:30 +08:00
|
|
|
|
|
2025-03-31 18:23:29 +08:00
|
|
|
|
},
|
|
|
|
|
//tab切换
|
|
|
|
|
doChangeStatus(e) {
|
|
|
|
|
const value = e.currentTarget.dataset.value
|
|
|
|
|
this.setData({
|
|
|
|
|
currentStatus: value
|
|
|
|
|
})
|
|
|
|
|
this.doRefreshList()
|
|
|
|
|
},
|
|
|
|
|
//获取我的优惠卷
|
2025-04-07 18:00:30 +08:00
|
|
|
|
doGetMyCoupons(isRefresh) {
|
2025-03-31 18:23:29 +08:00
|
|
|
|
const _self = this
|
2025-04-07 18:00:30 +08:00
|
|
|
|
_self.setData({
|
|
|
|
|
couponsList: isRefresh ? [] : _self.data.couponsList,
|
|
|
|
|
loadingState: isRefresh ? 'loading' : ''
|
|
|
|
|
})
|
|
|
|
|
ProApi.doGetCouponseList(_self.data.pageData)
|
2025-03-31 18:23:29 +08:00
|
|
|
|
.then(res => {
|
2025-04-07 18:00:30 +08:00
|
|
|
|
var status = 'success'
|
|
|
|
|
status = res.rows && res.rows.length > 0 ? 'success' : 'empty'
|
2025-03-31 18:23:29 +08:00
|
|
|
|
_self.setData({
|
2025-04-07 18:00:30 +08:00
|
|
|
|
loadingState: isRefresh ? status : '',
|
2025-03-31 18:23:29 +08:00
|
|
|
|
couponsList: _self.data.couponsList.concat(res.rows),
|
|
|
|
|
listRefreshTrig: false,
|
|
|
|
|
isLoadMore: false
|
|
|
|
|
})
|
2025-04-07 18:00:30 +08:00
|
|
|
|
_self.setData({
|
|
|
|
|
hasMore: _self.data.couponsList.length < res.total
|
|
|
|
|
})
|
2025-03-31 18:23:29 +08:00
|
|
|
|
}, err => {
|
|
|
|
|
_self.setData({
|
2025-04-07 18:00:30 +08:00
|
|
|
|
loadingState: 'error',
|
2025-03-31 18:23:29 +08:00
|
|
|
|
listRefreshTrig: false,
|
2025-04-07 18:00:30 +08:00
|
|
|
|
isLoadMore: false,
|
|
|
|
|
hasMore: true
|
2025-03-31 18:23:29 +08:00
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
//下拉刷新
|
|
|
|
|
doRefreshList() {
|
|
|
|
|
const _self = this
|
2025-04-07 18:00:30 +08:00
|
|
|
|
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
|
|
|
|
|
}
|
2025-03-31 18:23:29 +08:00
|
|
|
|
_self.setData({
|
|
|
|
|
listRefreshTrig: true,
|
2025-04-07 18:00:30 +08:00
|
|
|
|
loadingState: 'loading',
|
|
|
|
|
hasMore: true,
|
|
|
|
|
'pageData.page': 1,
|
|
|
|
|
'pageData.isEffective': isEffective,
|
|
|
|
|
'pageData.isUsed': isUsed,
|
|
|
|
|
isLoadMore: false
|
2025-03-31 18:23:29 +08:00
|
|
|
|
})
|
2025-04-07 18:00:30 +08:00
|
|
|
|
_self.doGetMyCoupons(true)
|
2025-03-31 18:23:29 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
//加载更多
|
|
|
|
|
doLoadMore() {
|
2025-04-07 18:00:30 +08:00
|
|
|
|
//判断是否正在加载中 与是否存在更多数据
|
|
|
|
|
const _self = this
|
|
|
|
|
if (_self.data.isLoadMore || !_self.data.hasMore) {
|
2025-03-31 18:23:29 +08:00
|
|
|
|
return
|
|
|
|
|
}
|
2025-04-07 18:00:30 +08:00
|
|
|
|
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
|
|
|
|
|
}
|
2025-03-31 18:23:29 +08:00
|
|
|
|
_self.setData({
|
2025-04-07 18:00:30 +08:00
|
|
|
|
isLoadMore: true,
|
|
|
|
|
'pageData.page': ++_self.data.pageData.page,
|
|
|
|
|
'pageData.isEffective': isEffective,
|
|
|
|
|
'pageData.isUsed': isUsed,
|
2025-03-31 18:23:29 +08:00
|
|
|
|
})
|
2025-04-07 18:00:30 +08:00
|
|
|
|
_self.doGetMyCoupons(false)
|
|
|
|
|
},
|
|
|
|
|
//显示使用规则
|
|
|
|
|
showRule() {
|
|
|
|
|
ProApi.doGetRuleDate()
|
|
|
|
|
.then(res => {
|
|
|
|
|
console.log(res)
|
|
|
|
|
}, err => {
|
|
|
|
|
console.log(err)
|
|
|
|
|
})
|
2025-03-31 18:23:29 +08:00
|
|
|
|
}
|
|
|
|
|
})
|