- 新增选手资料页面,支持查看选手信息及比赛记录 - 添加多个SVG图标替换原有emoji,提升视觉一致性 - 扩展CSS变量系统,增加信息、成功、警告、危险等状态颜色 - 优化多个页面的样式,统一使用CSS变量和现代设计语言 - 修复可选链操作符兼容性问题,改用传统条件判断 - 改进数据加载逻辑,使用Object.assign替代展开运算符 - 调整开发环境配置,使用本地服务器地址
131 lines
2.9 KiB
JavaScript
131 lines
2.9 KiB
JavaScript
const app = getApp()
|
|
const util = require('../../../utils/util')
|
|
|
|
Page({
|
|
data: {
|
|
orders: [],
|
|
status: '',
|
|
loading: false,
|
|
page: 1,
|
|
pageSize: 20,
|
|
hasMore: true,
|
|
showOrderModal: false,
|
|
currentOrder: null
|
|
},
|
|
|
|
onLoad() {
|
|
this.fetchOrders()
|
|
},
|
|
|
|
onPullDownRefresh() {
|
|
this.setData({ page: 1, hasMore: true })
|
|
this.fetchOrders().then(() => {
|
|
wx.stopPullDownRefresh()
|
|
})
|
|
},
|
|
|
|
onReachBottom() {
|
|
if (this.data.hasMore && !this.data.loading) {
|
|
this.loadMore()
|
|
}
|
|
},
|
|
|
|
async fetchOrders() {
|
|
this.setData({ loading: true })
|
|
|
|
try {
|
|
const params = {
|
|
page: this.data.page,
|
|
pageSize: this.data.pageSize
|
|
}
|
|
if (this.data.status !== '') {
|
|
params.status = this.data.status
|
|
}
|
|
|
|
const res = await app.request('/api/points/orders', params)
|
|
|
|
const orders = (res.data.list || []).map(order =>
|
|
Object.assign({}, order, {
|
|
createdAt: util.formatDate(order.createdAt)
|
|
})
|
|
)
|
|
|
|
this.setData({
|
|
orders: this.data.page === 1 ? orders : this.data.orders.concat(orders),
|
|
hasMore: orders.length >= this.data.pageSize
|
|
})
|
|
} catch (e) {
|
|
console.error('获取订单列表失败:', e)
|
|
} finally {
|
|
this.setData({ loading: false })
|
|
}
|
|
},
|
|
|
|
loadMore() {
|
|
this.setData({ page: this.data.page + 1 })
|
|
this.fetchOrders()
|
|
},
|
|
|
|
setStatus(e) {
|
|
const status = e.currentTarget.dataset.status
|
|
this.setData({ status, page: 1, hasMore: true })
|
|
this.fetchOrders()
|
|
},
|
|
|
|
async viewOrder(e) {
|
|
const order = e.currentTarget.dataset.order
|
|
|
|
wx.showLoading({ title: '加载中...' })
|
|
|
|
try {
|
|
const res = await app.request(`/api/points/orders/${order.id}`)
|
|
|
|
wx.hideLoading()
|
|
|
|
const orderData = Object.assign({}, res.data, {
|
|
createdAt: util.formatDate(res.data.createdAt),
|
|
qrcodeImage: ''
|
|
})
|
|
|
|
this.setData({
|
|
currentOrder: orderData,
|
|
showOrderModal: true
|
|
})
|
|
|
|
// 如果待核销,获取二维码图片
|
|
if (res.data.status === 0 && res.data.exchangeCode) {
|
|
this.generateQrcode(res.data.exchangeCode)
|
|
}
|
|
} catch (e) {
|
|
wx.hideLoading()
|
|
console.error('获取订单详情失败:', e)
|
|
wx.showToast({ title: '获取订单详情失败', icon: 'none' })
|
|
}
|
|
},
|
|
|
|
// 生成二维码
|
|
async generateQrcode(code) {
|
|
try {
|
|
const res = await app.request('/api/points/orders/qrcode', { code })
|
|
if (res.data && res.data.qrcode) {
|
|
this.setData({
|
|
'currentOrder.qrcodeImage': res.data.qrcode
|
|
})
|
|
}
|
|
} catch (e) {
|
|
console.error('生成二维码失败:', e)
|
|
}
|
|
},
|
|
|
|
closeOrderModal() {
|
|
this.setData({
|
|
showOrderModal: false,
|
|
currentOrder: null
|
|
})
|
|
},
|
|
|
|
goToMall() {
|
|
wx.switchTab({ url: '/pages/points/mall/index' })
|
|
}
|
|
})
|