index.js
3.33 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import ActivityApi from '~/api/activityApi/index'
import {handlerMiss} from '~/packageStoreAssistant/common/common'
Component({
/**
* 组件的属性列表
*/
properties: {
isHaveSubcribe:Boolean,
ids:Array,
entranceType:{
type:Number,
observer:function(val){
if(val>-1&&this.control){
this.initLocal(val)
}
}
},
fresh:{
type:Boolean,
observer: function (val) {
if(val){
this.setData({
pageNum: 1
}, () => {
this.initLocal(this.data.entranceType)
})
}
}
}
},
/**
* 组件的初始数据
*/
data: {
listData: [],
activeTrigger: false,
activePageNum: 1,
activeTotal: 0,
pageNum: 1,
total: 0,
pageSize: 10,
noResult:false
},
/**
* 组件的方法列表
*/
methods: {
// 初始化
initLocal(val){
this.setData({
listData: [],
activeTrigger: false,
activePageNum: 1,
activeTotal: 0,
pageNum: 1,
total: 0,
pageSize: 10,
noResult:false
},()=>{
this.getActivity(val)
})
},
// 获取数据
getActivity(type){
wx.$api.showLoading()
let { pageSize, pageNum,listData,ids } = this.data
let paraList = [],apiName = 'getActivityList',para = {pageNum,pageSize}
if(type==1){
ids.forEach(el=>{
if((el.serviceType==1&&type==1) || (el.serviceType==2&&type==2)){
if(el.activityId){
paraList.push(el.activityId)
}
}
})
para.ids = paraList
apiName = 'getSubscribeListByIdsApi'
if(!paraList.length)return this.setData({noResult:true})
}else if([2,5,6,3].includes(type)){
para.subscribe = type
apiName = 'getActivityPageBySubscribe'
}
ActivityApi[apiName](para).then(res=>{
wx.hideLoading()
if(res&&res.list){
handlerMiss(res,{serviceType:type,pageNum,listName:'listData',orginList:listData},(result)=>{
if(result&&result.total&&type==0){
this.triggerEvent('total',{type:0,total:result.total || 0})
}
this.setData(result)
})
}
}).catch(err =>{
wx.hideLoading()
})
},
toFresh(e) {
if (e.detail) {
this.setData({
listData: e.detail
})
}
},
// 下拉刷新
activityRefresh(e) {
this.setData({
pageNum: 1,
listData:[]
},()=>{
this.getActivity(this.data.entranceType)
// 刷新获取订阅配置
if(!this.data.isHaveSubcribe){
wx.$eventbus.emit("RESFRESH_SUBCRIBE",{type:this.data.entranceType,fresh:true})
}
})
},
// 上拉触底加载
scrollonReachBottom(e) {
let { pageNum, total, pageSize } = this.data
// 判断当前页是否是末页
// if (Math.floor(total / pageSize) == pageNum - 1) return
if(pageNum*pageSize>=total)return
this.setData({
pageNum: pageNum + 1
},()=>{
this.getActivity(this.data.entranceType)
})
},
// 滚动中
scrollIng(e) {},
},
lifetimes: {
attached() {
if(this.control)return
this.control = true
this.initLocal(this.data.entranceType)
}
},
})