index.js
2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// pages/tab/select/index.js
// import { strategyList } from "./constant/constant";
Page({
/**
* 页面的初始数据
*/
data: {
strategyList: [],
categoryList: [],
currentCateIndex: 0,
toCate: 'to-0'
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
this.getCategoryList()
this.shareTitle = "攻略专区"
},
// navbarReady(e) {
// let {
// height
// } = e.detail
// this.setData({
// user_box_style: `padding-top:${height + 15}px`
// })
// },
// 获取分类列表
getCategoryList() {
wx.p.api.strategyApi.getStrategyCategory({}).then(res => {
if (res && res.list && res.list.length) {
let setdataobj = { categoryList: res.list }
if (this.fresh) {
// 防止下拉刷新时,分类已被置顶乱序
const currentIndx = res.list.findIndex(item => item.id == this.currentCategoryId)
setdataobj.currentCateIndex = currentIndx
setdataobj.toCate = `to-${currentIndx}`
} else {
this.currentCategoryId = res.list[0].id
}
this.setData(setdataobj, () => {
this.getStrategyList();
})
}
})
},
selectCate(e) {
const { index, item } = e.currentTarget.dataset
this.currentCategoryId = item.id
this.getStrategyList();
this.setData({
currentCateIndex: index,
toCate: `to-${index}`
})
},
getStrategyList() {
wx.p.api.strategyApi.getStrategyList({
pageNum: 1,
pageSize: 99999,
categoryId: this.currentCategoryId
}).then(res => {
this.setData({
strategyList: res.list,
})
if (this.fresh) {
wx.stopPullDownRefresh()
}
});
},
selectStrategy(e) {
const { id } = e.currentTarget.dataset.item
wx.p.router.go('/packageStrategy/pages/strategyDetail/index', {
id,
notIntercept: true
})
},
onShareAppMessage() { },
onShow() {
const FIRST = wx.p.storage.get('first_enter_miniprograme')
this.setData({
showStore: !FIRST
})
},
onPullDownRefresh() {
this.fresh = true
this.getCategoryList()
},
});