140 lines
2.7 KiB
JavaScript
140 lines
2.7 KiB
JavaScript
const {
|
||
api
|
||
} = require("../../utils/api")
|
||
|
||
// pages/store/index.js
|
||
Page({
|
||
|
||
/**
|
||
* 页面的初始数据
|
||
*/
|
||
data: {
|
||
points: 0,
|
||
list: [],
|
||
inviteCode: "",
|
||
visible: false,
|
||
current: null
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面加载
|
||
*/
|
||
onLoad(options) {
|
||
const inviteCode = wx.getStorageSync('inviteCode')
|
||
this.setData({
|
||
inviteCode: inviteCode
|
||
})
|
||
},
|
||
goInfo(e) {
|
||
const id = e.currentTarget.dataset.id
|
||
wx.navigateTo({
|
||
url: '../store/info?id=' + id,
|
||
})
|
||
},
|
||
|
||
goShare(e) {
|
||
const item = e.currentTarget.dataset.item
|
||
const show = !this.data.visible
|
||
this.setData({
|
||
visible: show,
|
||
current: item
|
||
})
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面初次渲染完成
|
||
*/
|
||
onReady() {
|
||
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面显示
|
||
*/
|
||
onShow() {
|
||
this.fetchList()
|
||
},
|
||
|
||
fetchList() {
|
||
api('/personal/personal', 'GET').then(res => {
|
||
if (res.code === 200) {
|
||
const tmps = res.data
|
||
this.setData({
|
||
points: tmps.pointsCount
|
||
})
|
||
wx.setStorageSync('points', tmps.pointsCount)
|
||
api('/claim/list', 'POST', {
|
||
current: 0,
|
||
pageSize: 10,
|
||
name: '',
|
||
keyword: ''
|
||
}, 'json').then(res => {
|
||
if (res.code === 200) {
|
||
const tmps = res.data.list.map(e => {
|
||
e.status = e.points < this.data.points ? 0 : 1
|
||
return e
|
||
}).sort((a, b) => {
|
||
// 1. 优先比较 status,0 在前,1 在后
|
||
if (a.status !== b.status) {
|
||
return a.status - b.status;
|
||
}
|
||
// 2. status 相同的情况下,比较 points,从小到大排序
|
||
return a.points - b.points;
|
||
})
|
||
this.setData({
|
||
list: tmps
|
||
})
|
||
}
|
||
})
|
||
}
|
||
})
|
||
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面隐藏
|
||
*/
|
||
onHide() {
|
||
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面卸载
|
||
*/
|
||
onUnload() {
|
||
|
||
},
|
||
|
||
/**
|
||
* 页面相关事件处理函数--监听用户下拉动作
|
||
*/
|
||
onPullDownRefresh() {
|
||
|
||
},
|
||
|
||
/**
|
||
* 页面上拉触底事件的处理函数
|
||
*/
|
||
onReachBottom() {
|
||
|
||
},
|
||
|
||
/**
|
||
* 用户点击右上角分享
|
||
*/
|
||
onShareAppMessage() {
|
||
return {
|
||
title: '发现一个宝藏养花神器',
|
||
imageUrl: "https://res.catter.cn/pub/2025/12/08/20251208112039694.png",
|
||
path: '/pages/index/index?inviteCode=' + this.data.inviteCode
|
||
};
|
||
},
|
||
|
||
onShareTimeline() {
|
||
return {
|
||
title: '发现一个宝藏养花神器',
|
||
imageUrl: "https://res.catter.cn/pub/2025/12/08/20251208112039694.png",
|
||
path: '/pages/index/index?inviteCode=' + this.data.inviteCode
|
||
};
|
||
}
|
||
}) |