统一排行榜对齐星雀UI,页面资源后台配置实时刷新
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
344
miniprogram/pages/dashoudingdan/dashoudingdan.js
Normal file
344
miniprogram/pages/dashoudingdan/dashoudingdan.js
Normal file
@@ -0,0 +1,344 @@
|
||||
const app = getApp()
|
||||
import request from '../../utils/request.js'
|
||||
|
||||
Page({
|
||||
onShow() {
|
||||
// 原有代码...
|
||||
|
||||
// 🆕 注册通知组件
|
||||
this.registerNotificationComponent();
|
||||
},
|
||||
|
||||
// 🆕 新增:注册通知组件
|
||||
registerNotificationComponent() {
|
||||
const app = getApp();
|
||||
const notificationComp = this.selectComponent('#global-notification');
|
||||
|
||||
if (notificationComp && notificationComp.showNotification) {
|
||||
//console.log('🏪 商城页面注册通知组件');
|
||||
app.globalData.globalNotification = {
|
||||
show: (data) => notificationComp.showNotification(data),
|
||||
hide: () => notificationComp.hideNotification()
|
||||
};
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
|
||||
|
||||
data: {
|
||||
// 打手订单状态tab配置(去掉已下单,其他保留)
|
||||
dsDingdanZhuangtaiTabs: [
|
||||
{ name: '进行中', key: 'jinxingzhong', zhuangtaiList: [2] },
|
||||
{ name: '退款中', key: 'tuikuanzhong', zhuangtaiList: [4] },
|
||||
{ name: '已退款', key: 'yituikuan', zhuangtaiList: [5] },
|
||||
{ name: '退款失败', key: 'tuikuanshibai', zhuangtaiList: [6] },
|
||||
{ name: '已完成', key: 'yiwancheng', zhuangtaiList: [3] },
|
||||
{ name: '结算中', key: 'jiesuanzhong', zhuangtaiList: [8] }
|
||||
],
|
||||
|
||||
// 当前选中的tab索引(默认0=进行中)
|
||||
xuanzhongTabIndex: 0,
|
||||
// 当前选中的tab的key
|
||||
currentTabKey: 'jinxingzhong',
|
||||
|
||||
// 防抖标志:是否允许切换tab
|
||||
allowSwitchTab: true,
|
||||
// 防抖时间(毫秒)
|
||||
switchDebounceTime: 2000,
|
||||
|
||||
// 每个tab对应的订单数据
|
||||
dsDingdanShuju: {
|
||||
jinxingzhong: { list: [], page: 1, hasMore: true, isLoading: false },
|
||||
tuikuanzhong: { list: [], page: 1, hasMore: true, isLoading: false },
|
||||
yituikuan: { list: [], page: 1, hasMore: true, isLoading: false },
|
||||
tuikuanshibai: { list: [], page: 1, hasMore: true, isLoading: false },
|
||||
yiwancheng: { list: [], page: 1, hasMore: true, isLoading: false },
|
||||
jiesuanzhong: { list: [], page: 1, hasMore: true, isLoading: false }
|
||||
},
|
||||
|
||||
// 打手订单图片URL(从缓存或全局变量获取后拼接)
|
||||
dsDingdanTupianUrl: '',
|
||||
|
||||
// 页面加载状态
|
||||
isLoading: true,
|
||||
|
||||
// 是否显示加载更多
|
||||
xianshiJiazaigengduo: false
|
||||
},
|
||||
|
||||
onLoad(options) {
|
||||
// 设置页面标题
|
||||
wx.setNavigationBarTitle({
|
||||
title: '我的接单'
|
||||
})
|
||||
|
||||
// 初始化:获取图片URL并拼接
|
||||
this.getAndSetTupianUrl()
|
||||
|
||||
// 加载初始数据(默认进行中)
|
||||
this.setData({
|
||||
isLoading: false
|
||||
})
|
||||
|
||||
this.jiazaiDsDingdanShuju(0, false)
|
||||
},
|
||||
|
||||
// 获取并设置图片URL
|
||||
getAndSetTupianUrl() {
|
||||
const app = getApp()
|
||||
|
||||
// 1. 先从缓存获取touxiang
|
||||
const cacheTouxiang = wx.getStorageSync('touxiang') || ''
|
||||
|
||||
// 2. 如果缓存没有,从全局变量获取morentouxiang
|
||||
let tupianPath = cacheTouxiang || app.globalData.morentouxiang || ''
|
||||
|
||||
// 3. 拼接完整的图片URL
|
||||
const ossImageUrl = app.globalData.ossImageUrl || ''
|
||||
let fullTupianUrl = ''
|
||||
|
||||
if (tupianPath && ossImageUrl) {
|
||||
// 确保路径不以斜杠开头(防止双斜杠)
|
||||
if (tupianPath.startsWith('/')) {
|
||||
tupianPath = tupianPath.substring(1)
|
||||
}
|
||||
fullTupianUrl = ossImageUrl + tupianPath
|
||||
}
|
||||
|
||||
this.setData({
|
||||
dsDingdanTupianUrl: fullTupianUrl
|
||||
})
|
||||
},
|
||||
|
||||
// 切换订单tab(增加防抖)
|
||||
switchDsDingdanTab(e) {
|
||||
const tabIndex = e.currentTarget.dataset.index
|
||||
|
||||
// 如果当前正在加载,不允许切换
|
||||
const currentTabKey = this.data.currentTabKey
|
||||
const currentTabData = this.data.dsDingdanShuju[currentTabKey]
|
||||
if (currentTabData.isLoading) {
|
||||
console.log('当前正在加载,禁止切换')
|
||||
return
|
||||
}
|
||||
|
||||
// 防抖:检查是否允许切换
|
||||
if (!this.data.allowSwitchTab) {
|
||||
|
||||
wx.showToast({
|
||||
title: '切换太频繁,请稍后',
|
||||
icon: 'none',
|
||||
duration: 1000
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 如果点击的是当前选中的tab,不处理
|
||||
if (tabIndex === this.data.xuanzhongTabIndex) {
|
||||
return
|
||||
}
|
||||
|
||||
const tabKey = this.data.dsDingdanZhuangtaiTabs[tabIndex].key
|
||||
|
||||
// 设置防抖标志,2秒内不允许再次切换
|
||||
this.setData({
|
||||
allowSwitchTab: false
|
||||
})
|
||||
|
||||
// 设置定时器,2秒后恢复允许切换
|
||||
setTimeout(() => {
|
||||
this.setData({
|
||||
allowSwitchTab: true
|
||||
})
|
||||
}, this.data.switchDebounceTime)
|
||||
|
||||
// 更新选中的tab
|
||||
this.setData({
|
||||
xuanzhongTabIndex: tabIndex,
|
||||
currentTabKey: tabKey
|
||||
})
|
||||
|
||||
// 加载对应tab的数据
|
||||
this.jiazaiDsDingdanShuju(tabIndex, false)
|
||||
},
|
||||
|
||||
// 加载打手订单数据
|
||||
async jiazaiDsDingdanShuju(tabIndex, isLoadMore = false) {
|
||||
const tab = this.data.dsDingdanZhuangtaiTabs[tabIndex]
|
||||
const tabKey = tab.key
|
||||
|
||||
const tabData = this.data.dsDingdanShuju[tabKey]
|
||||
|
||||
const page = isLoadMore ? tabData.page + 1 : 1
|
||||
|
||||
// 检查是否正在加载
|
||||
if (tabData.isLoading) {
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// 如果不是加载更多,清空已有数据
|
||||
if (!isLoadMore) {
|
||||
this.setData({
|
||||
[`dsDingdanShuju.${tabKey}.list`]: [],
|
||||
[`dsDingdanShuju.${tabKey}.page`]: 1
|
||||
})
|
||||
}
|
||||
|
||||
// 设置加载状态
|
||||
this.setData({
|
||||
[`dsDingdanShuju.${tabKey}.isLoading`]: true
|
||||
})
|
||||
|
||||
// 显示加载提示(非加载更多时显示)
|
||||
if (!isLoadMore) {
|
||||
wx.showLoading({
|
||||
title: '加载订单...',
|
||||
mask: true
|
||||
})
|
||||
}
|
||||
|
||||
try {
|
||||
// 准备请求数据
|
||||
const requestData = {
|
||||
zhuangtai_list: tab.zhuangtaiList,
|
||||
page: page,
|
||||
page_size: 10
|
||||
}
|
||||
|
||||
|
||||
|
||||
const res = await request({
|
||||
url: '/dingdan/dshqdingdan',
|
||||
method: 'POST',
|
||||
data: requestData,
|
||||
header: {
|
||||
'content-type': 'application/json'
|
||||
}
|
||||
})
|
||||
|
||||
// 隐藏加载提示
|
||||
if (!isLoadMore) {
|
||||
wx.hideLoading()
|
||||
}
|
||||
|
||||
// 处理返回数据
|
||||
if (res && res.data.code === 0) {
|
||||
const newDingdanList = res.data.data.list || []
|
||||
const hasMore = res.data.data.has_more || false
|
||||
|
||||
|
||||
|
||||
// 为每个订单添加状态中文描述和统一的图片URL
|
||||
const processedList = newDingdanList.map(item => {
|
||||
const zhuangtaiZh = this.getZhuangtaiZhongwen(item.zhuangtai)
|
||||
|
||||
return {
|
||||
...item,
|
||||
tupian: this.data.dsDingdanTupianUrl, // 使用统一的图片URL
|
||||
zhuangtaiZh: zhuangtaiZh
|
||||
}
|
||||
})
|
||||
|
||||
const currentList = this.data.dsDingdanShuju[tabKey].list
|
||||
const updatedList = isLoadMore
|
||||
? [...currentList, ...processedList]
|
||||
: processedList
|
||||
|
||||
// 更新数据
|
||||
this.setData({
|
||||
[`dsDingdanShuju.${tabKey}.list`]: updatedList,
|
||||
[`dsDingdanShuju.${tabKey}.page`]: page,
|
||||
[`dsDingdanShuju.${tabKey}.hasMore`]: hasMore,
|
||||
[`dsDingdanShuju.${tabKey}.isLoading`]: false,
|
||||
xianshiJiazaigengduo: hasMore
|
||||
})
|
||||
|
||||
} else {
|
||||
// 请求失败处理
|
||||
const errorMsg = res ? (res.data.msg || '加载失败') : '请求失败'
|
||||
|
||||
if (!isLoadMore) {
|
||||
wx.showToast({
|
||||
title: errorMsg,
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
})
|
||||
}
|
||||
|
||||
this.setData({
|
||||
[`dsDingdanShuju.${tabKey}.isLoading`]: false
|
||||
})
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
|
||||
|
||||
if (!isLoadMore) {
|
||||
wx.hideLoading()
|
||||
wx.showToast({
|
||||
title: '网络请求失败,请重试',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
})
|
||||
}
|
||||
|
||||
this.setData({
|
||||
[`dsDingdanShuju.${tabKey}.isLoading`]: false
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
// 获取状态中文描述
|
||||
getZhuangtaiZhongwen(zhuangtai) {
|
||||
const zhuangtaiMap = {
|
||||
1: '已下单', // 打手看不到这个状态
|
||||
2: '进行中',
|
||||
3: '已完成',
|
||||
4: '退款中',
|
||||
5: '已退款',
|
||||
6: '退款失败',
|
||||
7: '指定中', // 打手看不到这个状态
|
||||
8: '结算中'
|
||||
}
|
||||
|
||||
return zhuangtaiMap[zhuangtai] || '未知状态'
|
||||
},
|
||||
|
||||
// 上拉加载更多
|
||||
onReachBottom() {
|
||||
const tabKey = this.data.currentTabKey
|
||||
const tabData = this.data.dsDingdanShuju[tabKey]
|
||||
|
||||
// 检查是否还有更多数据并且当前没有正在加载
|
||||
if (tabData.hasMore && !tabData.isLoading) {
|
||||
const tabIndex = this.data.xuanzhongTabIndex
|
||||
this.jiazaiDsDingdanShuju(tabIndex, true)
|
||||
}
|
||||
},
|
||||
|
||||
// 跳转到订单详情页面
|
||||
goToDsDingdanXiangqing(e) {
|
||||
const dingdanItem = e.currentTarget.dataset.item
|
||||
if (!dingdanItem) return
|
||||
|
||||
// 编码订单数据
|
||||
const dingdanDataStr = encodeURIComponent(JSON.stringify(dingdanItem))
|
||||
|
||||
// 跳转到打手订单详情页
|
||||
wx.navigateTo({
|
||||
url: `/pages/dsddxq/dsddxq?dingdanData=${dingdanDataStr}`
|
||||
})
|
||||
},
|
||||
|
||||
// 图片加载失败处理
|
||||
onImageError(e) {
|
||||
// 如果统一图片加载失败,使用默认图片
|
||||
const defaultImage = app.globalData.lunbozhanwei || '/images/default.jpg'
|
||||
|
||||
this.setData({
|
||||
dsDingdanTupianUrl: defaultImage
|
||||
})
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user