apply.js
4.67 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
// pages/apply/apply.js
const navStyle = 'background-color: transparent;'
import { IMG_URL } from '~/utils/constantData.js'
import applyApi from '~/api/applyApi/index'
import { addCoProductApi } from '~/api/applyProd.js'
// `${IMG_URL}index/car2.png`,
//本地图片路径
let IMG_URLLocal = '../../images/'
import utils from '~/utils/util.js'
import { behavior as computedBehavior } from '~/utils/lib/miniprogram-computed'
Page({
/**
* 页面的初始数据
*/
behaviors: [computedBehavior],
data: {
// navStyle,
IMG_URL,
tabActive: 1,
tabList: [{
title: '申请业务',
name: 1
}, {
title: '申请产品',
name: 2
}],
isLoading: false
},
// computed: {
// hasProdAct(data) {
// return data.selectProdArr.
// }
// },
// navbar高度设置
navbarReady(e) {
let { height, statusBarHeight } = e.detail
this.setData({
tabBarStyle: height / 2 + statusBarHeight
// headerHeight: height / 2 + statusBarHeight + 88*2
})
},
onTabChange(e) {
const { name } = e.detail
this.setData({
tabActive: name
})
},
// 申请业务
applyBusiness() {
if (this.data.isLoading) {
return
}
const subCompData = this.selectComponent('#apply-business').data
let { name } = subCompData.carObj
// console.log('name: ', name)
if (!name) {
wx.pro.showToast({
title: '请输入开店名称',
icon: 'error'
})
return
}
this.submitBusinessForm(subCompData)
},
submitBusinessForm(subCompData) {
let { carObj, selectProdArr } = subCompData
let { clueId } = this.data
let selectProdArrStr = ''
selectProdArr.forEach((item, index) => { selectProdArrStr += `${item.productName}${selectProdArr.length - 1 == index ? '' : ';'}` })
let { userInfo } = wx.$storage.get()
let MerchantInfo = userInfo.subLoginUser
let params = {
serviceMerchantId: MerchantInfo.merchantId,
serviceMerchantName: MerchantInfo.merchantName,
serviceMerchantPhone: MerchantInfo.phone,
merchantContact: carObj.contact,
phone: carObj.phone,
applyMerchantName: carObj.name,
carType: carObj.model,
baseCustomer: carObj.selNum,
clueId,
intentProducts: selectProdArrStr
}
this.setData({
isLoading: true
})
// return wx.$api.showToast('申请成功')
applyApi
.merchantApply(params)
.then(result => {
// console.log(result)
if (result) {
wx.$api.showToast('申请成功')
setTimeout(() => {
wx.$router.back(page => {
page && page.getClueInit && page.getClueInit()
})
}, 1000)
}
})
.catch(err => {
this.setData({
isLoading: false
})
})
},
// 申请产品
applyProduct() {
if (this.data.isLoading) {
return
}
const subCompData = this.selectComponent('#apply-product').data
let { prodName, selectStoreItem } = subCompData
if (!prodName) {
wx.pro.showToast({
title: '请输入产品名称',
icon: 'error'
})
return
}
if (utils.isEmptyObj(selectStoreItem)) {
wx.pro.showToast({
title: '请选择合作门店',
icon: 'error'
})
return
}
this.submitProductForm(subCompData)
},
async submitProductForm(subCompData) {
let { prodName, selectStoreItem } = subCompData
let userInfo = wx.$storage.get('userInfo')
let params = {
...selectStoreItem,
serviceMerchantId: userInfo.merchantId,
serviceMerchantName: userInfo.merchantName,
coProduct: prodName
}
this.setData({
isLoading: true
})
let { code } = await addCoProductApi(params)
if (code == 0) {
wx.$api.showToast('申请成功')
setTimeout(() => {
wx.$router.back()
}, 1000)
} else {
this.setData({
isLoading: false
})
}
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) { },
onRoute(params) {
// 线索id
this.setData({
clueId: params
})
// console.log('params: ', params)
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() { },
/**
* 生命周期函数--监听页面显示
*/
onShow() { },
/**
* 生命周期函数--监听页面隐藏
*/
onHide() { },
/**
* 生命周期函数--监听页面卸载
*/
onUnload() { },
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() { },
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() { },
/**
* 用户点击右上角分享
*/
onShareAppMessage() { }
})