methods.js
5.82 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
import {
getSceneMarketMaterialMenu,
saveSceneMarketLead,
findSceneMarketLeadsById,
getSceneMarketConfig
} from '../request'
import dayjs from 'dayjs'
export default {
async getSceneMarketConfig(callBack) {
const {
sceneForm,
fixedForm
} = await getSceneMarketConfig()
this.setData({
sceneForm,
fixedForm
})
callBack()
},
changeCarBrand(e) {
const {
id,
name
} = e
this.setData({
['formData.storeBrandId']: id,
['formData.storeBrand']: name
})
},
async getSceneMarketMaterialMenu() {
try {
const {
code,
message,
data
} = await getSceneMarketMaterialMenu()
if (code == 0) {
let optionList = [
[],
[]
],
secondOption = []
for (let key in data) {
optionList[0].push(data[key])
secondOption.push(data[key].sceneMarketLevelTwoList)
}
optionList[1] = secondOption[0]
this.setData({
[`fixedForm[2].optionList`]: optionList,
secondOption
})
} else throw message
} catch (error) {
wx.$util.showToast(error)
}
},
bindMultiPickerColumnChange({
detail: e
}) {
let {
column,
value
} = e.detail, {
secondOption
} = this.data
if (column == 0) {
this.setData({
[`fixedForm[2].optionList[1]`]: secondOption[value]
})
}
},
bindMultiPickerChange({
detail: e
}) {
const {
value
} = e.detail, {
fixedForm
} = this.data,
[first, second] = value
let businessCodeName = `${fixedForm[2].optionList[0][first].directoryName}-${fixedForm[2].optionList[1][second].directoryName}`,
businessCode = fixedForm[2].optionList[1][second].code
this.setData({
['formData.businessCodeName']: businessCodeName,
['formData.businessCode']: businessCode,
nextBtn: true,
dynamicFormData: {},
dynamicForm: []
})
},
bindKeyInput({
detail: e
}) {
const {
key,
formName
} = e.currentTarget.dataset
this.setData({
[`${formName}.${key}`]: e.detail.value
})
},
bindPickerChange({
detail: e
}) {
const {
key,
option,
formName
} = e.currentTarget.dataset
this.setData({
[`${formName}.${key}`]: option[e.detail.value]
})
},
next() {
const {
formData,
sceneForm
} = this.data
if (formData.storeName && formData.storeBrandId && formData.businessCode) {
if (sceneForm[formData.businessCode]) this.setData({
dynamicForm: sceneForm[formData.businessCode],
nextBtn: false
})
else wx.$util.showToast('当前场景尚未配置对应表单')
}
},
submit() {
if(this.submitStatus) return
try {
wx.$util.showLoading('提交中...')
this.submitStatus = true
const {
formData,
dynamicForm,
dynamicFormData,
fixedForm
} = this.data
let requiredList = []
fixedForm.map(e => {
if (!formData[e.key]) throw e.placeholder
})
dynamicForm.map(e => {
e.form.map(i => {
if (i.required) requiredList.push({
placeholder: i.placeholder,
key: i.key
})
})
})
requiredList.map(e => {
if (!dynamicFormData[e.key]) throw e.placeholder
})
this.saveSceneMarketLead()
} catch (error) {
wx.hideLoading()
wx.$util.showToast(error)
this.submitStatus = false
}
},
async saveSceneMarketLead() {
try {
let {
formData,
dynamicForm,
dynamicFormData
} = this.data,
extendedAttributes = {}
dynamicForm.map(e => {
e.form.map(i => {
if (dynamicFormData[i.key]) extendedAttributes[i.key] = dynamicFormData[i.key]
})
})
const params = {
storeName: formData.storeName,
storeBrandId: formData.storeBrandId,
storeBrand: formData.storeBrand,
businessCode: formData.businessCode,
extendedAttributes: JSON.stringify(extendedAttributes)
}
const {
code,
message,
data
} = await saveSceneMarketLead(params)
if (code == 0) {
if (data) {
this.submitStatus = false
wx.hideLoading()
wx.showToast({
title: '数据保存成功',
mask: true
})
setTimeout(() => {
wx.$router.back(page => {
page.search()
})
}, 1e3)
} else throw message
} else throw message
} catch (error) {
this.submitStatus = false
wx.hideLoading()
console.log(error)
wx.$util.showToast(error)
}
},
async findSceneMarketLeadsById(id) {
try {
const {
code,
message,
data
} = await findSceneMarketLeadsById({
id
})
if (code == 0) {
let {
sceneForm,
fixedForm
} = this.data,
dynamicForm = sceneForm[data.businessCode],
dynamicFormData = JSON.parse(data.extendedAttributes)
data.time = dayjs(data.createdDate).format('YYYY年MM月DD日')
let lastIndex = fixedForm.length - 1,
lastItem = JSON.parse(JSON.stringify(fixedForm.at(-1)))
fixedForm.splice(lastIndex, 1)
fixedForm = [
...fixedForm,
{
label: '员工姓名',
key: 'createdBy',
},
{
label: '提报日期',
key: 'time',
},
lastItem
]
this.setData({
formData: data,
dynamicForm,
dynamicFormData,
readonly: true,
fixedForm
})
} else throw message
} catch (error) {
wx.$util.showToast(error)
}
},
}