customerManagement.js
5.37 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
// pages/mineDetail/customerManagement/customerManagement.js
import mineApi from '~/api/mineApi/index'
// import USERAPI from '~/api/usersApi/index'
import { IMG_URL } from '~/utils/constantData'
const listObj = Object.freeze([
{
key: 'merchantId',
label: '商户号:',
editLabel: '商户号'
},
{
key: 'actualAccountName',
label: '商户账号:',
editLabel: '商户账号'
},
{
key: 'merchantName',
label: '门店名称:',
placeholder: '请输入您的客户门店简称',
editLabel: '门店名称',
maxLength: 20
},
{
key: 'contactName',
label: '联系人:',
placeholder: '请输入客户门店联系人',
editLabel: '联系人',
maxLength: 10
},
{
key: 'phone',
label: '手机号:',
placeholder: '请输入客户门店联系人手机号',
editLabel: '手机号',
maxLength: 11,
reg: '/[^d]/g,',
type: 'number'
},
{
key: 'mainBrand',
label: '主营品牌:',
// 请输入客户门店主营品牌,
placeholder: '多个品牌以分号区隔',
editLabel: '主营品牌',
maxLength: 20
},
{
key: 'newCarSales',
label: '新车销量:',
placeholder: '请输入客户门店新车月平均销售数',
editLabel: '新车销量',
maxLength: 5,
reg: '/[^d]/g',
type: 'number'
},
{
key: 'existUserNumber',
label: '存量用户数:',
placeholder: '请输入客户门店存量用户数',
editLabel: '存量用户数',
maxLength: 8,
reg: '/[^d]/g',
type: 'number'
}
])
Component({
options: {
addGlobalClass: true
},
/**
* 组件的属性列表
*/
properties: {},
/**
* 组件的初始数据
*/
data: {
pageNum: 1,
pageSize: 10,
pages: 1,
customerList: [{}],
listObj,
isSuper: false,
testData: [
{
a: 1
}
],
bgUrl: `${IMG_URL}/output/empty.png`
},
attached() {
// this.initTime()
let { userInfo } = wx.$storage.get()
this.setData({
isSuper: userInfo.isSuper
})
this.getMerchantCustomInfoList()
},
/**
* 组件的方法列表
*/
methods: {
restPageNum() {
// console.log('restPageNum')
this.setData({
pageNum: 1
})
this.getMerchantCustomInfoList('reset')
},
scrollonReachBottom() {
// console.log('scrollonReachBottom')
let { pages, pageNum } = this.data
// 判断当前页是否是末页
if (pages == pageNum) return wx.$api.showToast('列表已到底')
this.setData({
pageNum: pageNum + 1
})
this.getMerchantCustomInfoList()
},
// 分页查询客户列表
getMerchantCustomInfoList(type) {
wx.$api.showLoading('加载中...')
let { pageNum, pageSize, customerList } = this.data
let params = {
pageNum,
pageSize
}
mineApi
.merchantCustomInfo(params)
.then(result => {
console.log(result)
let { pages, list, total } = result
console.log(list)
list = list.map(item => {
item.merchantName = item.merchantName || item.actualMerchantName
item.phone = item.phone || item.actualPhone
// || item.actualContactName
item.contactName = item.contactName || item.actualContactName
return item
})
console.log(list)
this.setData({
customerList: pageNum == 1 ? list : [...customerList, ...list],
triggered: false,
pages
})
})
.catch(err => {})
.finally(() => {
if (type == 'reset') {
wx.$api.showToast({
title: '刷新成功',
icon: 'success'
})
} else {
wx.$api.hideLoading()
}
})
},
submit(data) {
let obj = ['merchantId', 'merchantName', 'contactName', 'phone', 'mainBrand', 'newCarSales', 'existUserNumber']
let objList = {}
obj.forEach(item => {
if (data[item]) {
objList[item] = data[item]
}
})
mineApi
.saveMerchantCustomInfo(objList)
.then(result => {
wx.$api.showToast('更新成功')
// console.log(result)
// this.setData({
// pageNum: 1
// })
// this.getMerchantCustomInfoList()
})
.catch(err => {})
},
changeStatus(e) {
console.log(e)
let { customerList, isSuper } = this.data
let { index, item } = e.currentTarget.dataset
// let
let status = customerList[index].isEdit
// console.log(isEdit)
// customerList[index]['isEdit'] = !customerList[index]['isEdit']
if (item.isEdit) {
// 提交客户信息更新
!isSuper && this.submit(customerList[index])
}
console.log(index)
// let indexEdit = console.log(!status)
this.setData({
[`customerList[${index}].isEdit`]: !status
})
},
input(e) {
let { index, name } = e.currentTarget.dataset
// console.log(index)
// console.log(name)
let { customerList, listObj } = this.data
let { value } = e.detail
// listObj
customerList[index][name] = value
this.setData({
customerList
})
// let { name } = e.currentTarget.dataset
// this.setData({
// [`orderObj.${name}`]: value
// })
}
}
})