activeBox.js
9.26 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
// pages/tab/index/components/activeBox/activeBox.js
import {imgUrlMixin} from '~/mixins/index'
import ActivityApi from "~/api/activityApi/index"
import { showEmoji } from '~/utils/emoji'
import {
domain
} from '~/utils/request/http'
Component({
/**
* 组件的属性列表
*/
options: {
addGlobalClass: true
},
behaviors: [imgUrlMixin],
properties: {
activeList: {
type: Array,
observer(newVal) {
}
},
nothing: {
type: Boolean
},
activeDateIndex: {
type: Number
}
},
/**
* 组件的初始数据
*/
data: {
activityOverviewList: ['shareData', 'browseData', 'visitorData', 'orderData'],
backStyle: [
'background-image: linear-gradient(180deg, #FFFFFF 72%, #FFEDEF 100%);margin: 0 16rpx 16rpx 0;',
'background-image: linear-gradient(179deg, #FFFFFF 76%, #FFF8E6 100%);',
'background-image: linear-gradient(180deg, #FFFFFF 72%, #EBF1FF 100%);margin: 0 16rpx 0 0;',
'background-image: linear-gradient(180deg, #FFFFFF 72%, #EBFEFF 100%);'
],
activeList: []
},
/**
* 组件的方法列表
*/
methods: {
// 图片加载完成
imageLoaded(event) {
if (event.detail.width) {
this.setData({imageLoaded: true})
}
},
// 展开收起
collapseClick(e) {
let { key, flag } = e.currentTarget.dataset
let { activeList } = this.data
this.setData({
activeDateIndex: 0
})
activeList.forEach((val, idx) => {
if (key == idx) {
if (flag && !val.missionList) {
val.isloading = true
ActivityApi.getActiveTaskList({activityId: val.id}).then(res => {
val.isloading = false
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.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(val => {
if (val.completeStatus == 2) completeStatusNum++
})
if (d.getTime() > new Date(`${k.activityTime.replace(/-/g,'/')} 23:59:59`).getTime()) k.status = 2
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['+idx+']'
this.setData({
[itemVal]: val
})
}).catch(err => {
val.isloading = false
let itemVal = 'activeList['+idx+']'
this.setData({
[itemVal]: val
})
})
} else if (flag && val.missionList) { // 已请求数据 展开默认选中当天
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 (d.getTime() > new Date(`${k.activityTime.replace(/-/g,'/')} 23:59:59`).getTime()) k.status = 2
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
} else {
val.isCollapse = !flag
}
} else {
val.isCollapse = true
}
})
this.setData({
activeList
})
},
// 任务日历数据处理
calenderFilter (arr, length) {
var _arr = []
while (arr.length) {
_arr.push(arr.splice(0, length))
}
return _arr
},
toUnicode (chineseStr = '') {
let unicodeStr = ''
for (let i = 0, iLength = chineseStr.length; i < iLength; i++) {
unicodeStr += '@' + chineseStr.charCodeAt(i).toString(16)
}
return unicodeStr
},
filterJumpUrl(item) {
const userStorage = wx.$storage.get('userInfo')
return `${domain}/scrm-wx-merchant-activity/#/?id=${item.id}&merchantId=${userStorage.merchantId}&shareStaffUuid=${userStorage.uuid}&shareStaffName=${this.toUnicode(userStorage.name)}&isExclusive=1&exclusiveUuid=${userStorage.uuid}&shareStaffType=2&sharedTime=${Date.now()}`
},
// 分享活动(复制链接)
copyActivityUrl(e) {
let { item } = e.currentTarget.dataset
let thisPage = wx.$router.getPageInstance()
wx.$api.showLoading()
ActivityApi.getActivityPosters({id: item.id}).then(res => {
// var code= QR.createQrCodeImg(res.activityUrl);
// /*code是指图片base64格式数据*/
// //声明文件系统
// const fs = wx.getFileSystemManager();
// //随机定义路径名称
// var times = new Date().getTime();
// var codeimg = wx.env.USER_DATA_PATH + '/' + times + '.png';
// //将base64图片写入
// fs.writeFile({
// filePath: codeimg,
// data: code.slice(22),
// encoding: 'base64',
// success: () => {
// thisPage.setData({
// sharePopupData: {
// imagePath: codeimg,
// activityName: res.activityName,
// address: res.activityAddressDetailName,
// posterImg: res.posterImg,
// showSharePopup: true
// },
// })
// }
// });
thisPage.setData({
sharePopupData: {
posterImg: res,
activityName: item.activityName,
showSharePopup: true
},
})
})
},
// 活动详情
goToDetail(e) {
let { item } = e.currentTarget.dataset
let h5Url = this.filterJumpUrl(item)
console.log(h5Url)
wx.$router.jumpH5(h5Url)
},
// 活动战报
jump(e) {
let { item } = e.currentTarget.dataset
wx.$router.go('packageActivity.warReport', item)
}
}
})