index.js
8.68 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
import ActivityApi from "~/api/activityApi/index"
import MineApi from "~/api/mineApi/index"
const navStyle = 'background-color: transparent;'
import {
setUserInfo
} from '~/utils/cache/storageApi'
import { showEmoji } from '~/utils/emoji'
Page({
// behaviors: [kfMixin],
/**
* 页面的初始数据
*/
data: {
navStyle,
activePageNum: 1,
activeTotal: 0,
pageNum: 1,
total: 0,
pageSize: 10,
tab: [
{name: '活动中', account: 1},
{name: '活动诊断', account: 2}
],
tabIndex: 0,
activeList: [],
activityEndList: [],
allTaskCount: 0,
scrollTop: 0
},
// 申请活动
applyActivity() {
wx.$router.go('packageActivity.applyActivity')
},
click(e) {
let { index } = e.currentTarget.dataset
this.setData({
tabIndex: index
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
// 获取活动数据 1活动中 2活动诊断
this.getData()
},
getData() {
this.getActivityList(1)
this.getActivityList(2)
this.getStaffInfo()
},
getStaffInfo() {
const userStorage = wx.$storage.get('userInfo')
let para = {
id: userStorage.bussinessId
}
MineApi.getStaffDetailApi(para, {isShowLoading: true}).then(res => {
if(res.merchantFileResponse){
userStorage.sta_avatarUrl = res.merchantFileResponse.fileUrl
}
setUserInfo(userStorage)
})
},
// 计算文本宽度
getTextWidth(text, font, bold) {
var canvas = wx.createOffscreenCanvas({ type: '2d', width: 300, height: 300 })
var context = canvas.getContext('2d')
context.font = context.font = `${bold} ${font}px PingFangSC-Semibold`
var metrics = context.measureText(text)
return metrics.width
},
getActivityList(num, onPullDown) {
let {activePageNum, pageSize, pageNum, activeList, activityEndList, tabIndex} = this.data
ActivityApi.getActivityList({
type: num,
pageNum: num == 1 ? activePageNum : pageNum,
pageSize
}).then(res => {
let windowWidth = wx.getSystemInfoSync().windowWidth
let activityTitleViewWidth = windowWidth - (((windowWidth / 375) * (46 + 48 + 160 + 24))) / 2 // 活动title区域宽度
res.list && res.list.forEach((val, index) => {
val.isCollapse = true
val.startTime = val.startTime.split(' ')[0]
val.endTime = val.endTime.split(' ')[0]
val.tabIndex = num - 1
val.titleIsWarp = this.getTextWidth(val.activityName, '18', 600) > activityTitleViewWidth
if (num == 1 && activePageNum == 1 && index == 0) { // 活动中默认展开第一条 数据处理
val.isloading = true
ActivityApi.getActiveTaskList({activityId: val.id}, {isShowLoading: true}).then(res => {
res.forEach(a => {
a.platformMerchantMissionResponseList && a.platformMerchantMissionResponseList.forEach(k => {
k.detailInfo = {activityId: val.id, imgUrlList: []}
k.platformMerchantMissionMaterialResponseList && k.platformMerchantMissionMaterialResponseList.forEach(i => {
// materialType 素材类型1文案 2图片 3视频 4专属链接
if (i.materialType == 1) { // 文案
k.detailInfo.textContent = i.materialContent
k.detailInfo.filterTextContent = i.materialContent ? `<view style="word-break: break-all;">${showEmoji(i.materialContent)}</view>` : undefined
}
if (i.materialType == 2 || i.materialType == 3) { // 图片视频
k.detailInfo.imgUrlList.push({
url: i.materialContent,
type: i.materialType == 2 ? 'image' : 'video'
})
}
if (i.materialType == 4) { // 链接
k.detailInfo.linkUrl = val.activityUrl
}
})
})
})
val.isloading = false
val.missionList = res
val.newtaskCalenderList = this.calenderFilter(JSON.parse(JSON.stringify(val.missionList)) || [], 7)
let d = new Date()
let nowDate = (d.getMonth() + 1).toString().padStart(2, "0") + "月" + d.getDate().toString().padStart(2, "0") + "日"
let ind = 0
val.calenderActiveIndex = 0
val.newtaskCalenderList.forEach((v, index) => {
v.forEach(k => {
k.time = (new Date(k.activityTime).getMonth() + 1).toString().padStart(2, "0") + "月" + new Date(k.activityTime).getDate().toString().padStart(2, "0") + "日"
k.ind = ind
let completeStatusNum = 0
k.platformMerchantMissionResponseList.forEach(i => {
if (i.completeStatus == 2) completeStatusNum++
})
if (nowDate == k.time) {
val.calenderActiveIndex = index
this.setData({activeDateIndex: ind})
}
// status 1过去日期任务全部完成 2过去日期任务有未完成的 3当前日期或未来日期
if (completeStatusNum == v.length && d.getTime() > new Date(`${k.activityTime.replace(/-/g,'/')} 23:59:59`).getTime()) {
k.status = 1
} else if (d.getTime() > new Date(`${k.activityTime.replace(/-/g,'/')} 23:59:59`).getTime()) {
k.status = 2
} else {
k.status = 3
}
ind++
})
})
val.isCollapse = false
let itemVal = 'activeList['+index+']'
this.setData({
[itemVal]: val
})
}).catch(err => {
val.isloading = false
})
}
if (num == 2 && pageNum == 1 && index == 0) { // 活动诊断展开第一条
ActivityApi.getActivityEndInstallOrderList({activityId: val.id}, {isShowLoading: true}).then(res => {
val.isCollapse = false
res.orderList && res.orderList.forEach(it => {
it.time = it.createdDate ? new Date(it.createdDate).format('yyyy-MM-dd hh:mm') : ''
})
val.orderList = res.orderList
val.orderTotal = res.orderTotal
val.reInstallContactsName = res.reInstallContactsName
val.reInstallContactsPhone = res.reInstallContactsPhone
let itemVal = 'activityEndList['+index+']'
this.setData({
[itemVal]: val
})
}).catch(err => {
val.isloading = false
})
}
})
if (num == 1) {
this.setData({
activeList: onPullDown ? res.list : [...activeList, ...res.list],
activeTotal: res.total,
activeTrigger: false
})
} else {
this.setData({
activityEndList: onPullDown ? res.list : [...activityEndList, ...res.list],
total: res.total,
activeTrigger: false
})
}
})
},
// 任务日历数据处理
calenderFilter (arr, length) {
var _arr = []
while (arr.length) {
_arr.push(arr.splice(0, length))
}
return _arr
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
// 滚动中
scrollIng(e) {
let {type} = e.currentTarget.dataset
if (type == 1) {
this.setData({
activeTranslateValue: e.detail.scrollTop / 2.3 > 140 ? 130 : e.detail.scrollTop / 2.3
})
} else {
this.setData({
activityEndTranslateValue: e.detail.scrollTop / 2.3 > 140 ? 130 : e.detail.scrollTop / 2.3
})
}
},
// 下拉刷新
activityRefresh(e) {
let {type} = e.currentTarget.dataset
this.setData({
activePageNum: 1,
pageNum: 1
})
this.getActivityList(type, true)
},
// 上拉触底加载
scrollonReachBottom(e) {
let {type} = e.currentTarget.dataset
let { activePageNum, pageNum , activeTotal, total, pageSize } = this.data
// 判断当前页是否是末页
if (type == 1) {
if (Math.floor(activeTotal / pageSize) == activePageNum - 1) return
this.setData({
activePageNum: activePageNum + 1
})
this.getActivityList(type)
} else {
if (Math.floor(total / pageSize) == pageNum - 1) return
this.setData({
pageNum: pageNum + 1
})
this.getActivityList(type)
}
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
},
authFail(){
},
toShowAuth(){
this.setData({
showAuth:true
})
}
})