applyActivity.js
3.16 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
import ActivityApi from "~/api/activityApi/index"
import UsersApi from "~/api/usersApi/index"
import {
reportData
} from '~/api/api.js'
Page({
data: {
currentIndex: 0,
currentSceneCode: '',
currentSceneName: '',
product: [],
USERINFO: {}
},
onLoad() {
UsersApi.getWXUserInfo()
const {
USERINFO
} = this.getCommonData()
// 已开通场景
ActivityApi.getOpenSceneList({merchantId: USERINFO.merchantId}).then(res => {
let arr = []
res && res.forEach(val => {
if (val.status == 1 && val.sceneCode != 'SC005') arr.push(val)
})
if (arr[0] && arr[0].sceneCode) this.getProducts(arr[0].sceneCode)
this.setData({
list: arr,
currentSceneCode: (arr[0] && arr[0].sceneCode) || 'SC001',
currentSceneName: (arr[0] && arr[0].name)
})
})
},
getProducts(code) {
let arr = []
const {
USERINFO
} = this.getCommonData()
this.setData({
product: arr
})
ActivityApi.getNotOpenProductsList({merchantId: USERINFO.merchantId, sceneCode: code}).then(res => { // 默认选中第一个业务场景 获取可用产品/活动
res.forEach(item => {
item.isSelect = false
if (item.sceneCode == this.data.currentSceneCode) arr.push(item)
})
this.setData({
product: arr
})
})
},
select(e) {
const { index, item } = e.currentTarget.dataset
this.setData({
currentIndex: index,
currentSceneCode: item.sceneCode,
currentSceneName: item.name
})
this.getProducts(item.sceneCode)
},
selectProduct(e) {
const { item, index } = e.currentTarget.dataset
let name = `product[${index}].isSelect`
this.setData({
[name]: !item.isSelect
})
},
// 申请开通
applyOpened() {
// 获取已选的产品code
let { product, currentSceneCode, currentSceneName } = this.data
let [arr1, arr2] = [[], []]
product.forEach(val => {
if (val.isSelect) {
arr1.push(val.productCode)
arr2.push(val.productName)
}
})
if (!arr1.length) return wx.showToast({
title: '请选择产品/活动',
icon: "none"
})
const {
USERINFO,
WXUSERINFO
} = this.getCommonData()
wx.showToast({
title: '提交中',
icon: 'loading'
})
reportData({
openId: WXUSERINFO.openId || '',
unionId: USERINFO.uuid || '',
nickName: USERINFO.name || '',
avatar: USERINFO.sta_avatarUrl || USERINFO.weChatAvatarUrl || '',
phone: USERINFO.phone || USERINFO.weChatPhone || '',
merchantId: USERINFO.merchantId || '',
shopName: USERINFO.merchantName || '',
sceneCode: currentSceneCode || '',
sceneName: currentSceneName || '',
productCode: arr1.join(','),
productDesc: arr2.join(','),
shopId: USERINFO.merchantId || ''
}, 2).then(res => {
wx.hideToast()
wx.$router.redirectTo('packageActivity.applySuccess')
})
},
getCommonData() {
const USERINFO = wx.$storage.get('userInfo')
const WXUSERINFO = wx.$storage.get('wx_user_info')
this.setData({
USERINFO
})
return {
USERINFO,
WXUSERINFO
}
}
})