createStaff.js
7.01 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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
// packagesList/mineDetail/pages/staffManage/createStaff/createStaff.js
import constantData from './constant/data'
import { behavior as computedBehavior } from "~/utils/lib/miniprogram-computed"
import mineApi from '~/api/mineApi/index'
import Util from '~/utils/util'
import { getUserInfo } from '~/utils/cache/userInfo'
Page({
behaviors: [computedBehavior],
/**
* 页面的初始数据
*/
data: {
addOrEdit: 'add',
serviceList: [],
formItems: constantData.formItems,
formData: {
selectedConnectionIds: [],
connectionValue: '全部',
visualType: 0, // 0:全部 1:选中部分可见客户
staffBusinessType: '0',
staffBusinessTypeStr: '驻店',
staffTypeSelectInfo: {
staffBusinessType: '0',
staffBusinessTypeStr: '驻店',
}
},
showServiceConfirm: false,
isConfirm: false,
staffPopupShow: false
},
watch: {
'formData.selectInfo.yqMerchantId': function (e) {
// 获取当前服务中心下的客户列表
// this.getConnectionList(e)
let { optionsInfo } = this.data
if (e == optionsInfo?.merchantNo) return
// 将可见客户置为全部
this.setData({
'formData.connectionValue': '全部',
'formData.selectedConnectionIds': []
})
}
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
// 获取服务中心/客户数据
this.getSelectList()
},
onRoute(options) {
// 选择可见客户回退
if (!options.info) return
let optionsInfo = options?.info || {}
let data = options?.info ? {
...options?.info,
selectInfo: {yqMerchantId: optionsInfo.merchantNo, yqMerchantName: optionsInfo.merchantName},
serviceValue: optionsInfo.merchantName,
visualType: optionsInfo.visualType || 0,
connectionValue: optionsInfo.visualType == 1 ? `已选${optionsInfo.visibleMerchantNo?.split(',')?.length}位客户`: '全部',
selectedConnectionIds: optionsInfo.visualType == 1 ? optionsInfo.visibleMerchantNo?.split(',').map((v) => {return v && Number(v)}) : [],
staffBusinessTypeStr: optionsInfo.staffBusinessType == 0 ? '驻店' : optionsInfo.staffBusinessType == 1 ? '技师' : '',
staffTypeSelectInfo: {staffBusinessType: optionsInfo?.staffBusinessType}
} : {}
if (options?.info) wx.setNavigationBarTitle({ title: '编辑员工' })
this.setData({
addOrEdit: options?.info ? 'edit' : 'add',
'formItems[0].disabled': options?.info ? true : false,
formData: data,
optionsInfo: Util.deepClone(optionsInfo)
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
// 获取服务中心下的客户列表
getConnectionList(e) {
mineApi.getConnectionListByServiceAPI({
serviceCenterMerchantId: e
}).then(res => {
// 全部客户
let { allConnectionIds, copyFormData } = this.data
allConnectionIds = res?.map(val => {return val.merchantId})
this.setData({
allConnectionIds
})
})
},
getSelectList() {
// 获取服务中心
mineApi.getServiceCenterListAPI({}).then(res => {
let data = res || []
this.setData({
serviceList: data
})
})
},
back() {
let { showServiceConfirm } = this.data
if (showServiceConfirm){
this.setData({
showServiceConfirm: false
})
} else wx.$router.back()
},
// 选择服务中心/客户
jump(e) {
let { formData } = this.data
let { type, disabled } = e.currentTarget.dataset
if (disabled) return
switch(type) {
// 选择服务中心
case 1:
this.hiddenSelectConfirm()
break
case 2:
if (!formData?.selectInfo?.yqMerchantId) return wx.$api.showToast('请先选择所属服务中心')
wx.$router.go('packageMine.selectConnectionPage', this.data.formData)
break
case 3:
this.handleStaffTypeChange()
break
}
},
handleStaffTypeChange() {
this.setData({
staffPopupShow: !this.data.staffPopupShow
})
},
staffTypeConfiem(e) {
let { formData } = this.data
let obj = {
...formData,
...e.detail,
selectInfo: formData.selectInfo,
staffTypeSelectInfo: e.detail
}
this.setData({
formData: obj
})
},
hiddenSelectConfirm(e) {
let { formData } = this.data
let selectInfo = {
...formData.selectInfo,
...e?.detail
}
this.setData({ showServiceConfirm: !this.data.showServiceConfirm })
if (!selectInfo) return
this.setData({
'formData.selectInfo': selectInfo,
'formData.serviceValue': selectInfo?.yqMerchantName
})
},
input(e) {
const { value } = e.detail,
{ name } = e.currentTarget.dataset
this.setData({
[`formData.${name}`]: value
})
},
// 提交
handleConfirm() {
let _this = this
let { addOrEdit, formData, allConnectionIds, isConfirm } = _this.data
if (isConfirm) {
return true
}
let validObj = wx.$util.checkRule(formData, constantData.formRule)
if (validObj) {
wx.$api.showToast(validObj.message)
return
}
let userInfo = getUserInfo()
let params = {
merchantNo: formData?.selectInfo?.yqMerchantId,
merchantName: userInfo?.merchantName,
type: formData.type,
staffUuid: formData?.staffUuid,
staffName: formData?.staffName,
staffPhone: formData?.staffPhone,
createdSource: 3, // 创建来源 固定3 生意助手
visualType: formData?.visualType,
visibleMerchantNoList: formData?.visualType == 0 ? undefined : formData?.selectedConnectionIds, // 全部 无需传可见客户数据
staffType: Number(formData?.staffBusinessType)
}
let message = addOrEdit == 'add' ? '是否确定创建员工?' : '是否确定修改员工信息?'
wx.showModal({
title: '提示',
content: message,
confirmText: '确定',
cancelText: '取消',
confirmColor: '#3666FE',
success(res) {
if (res.confirm) {
_this.setData({
isConfirm: true
})
// 创建/编辑接口
let requestEvent = addOrEdit == 'add' ? 'createStaffAPI' : 'updateStaffAPI'
mineApi[requestEvent](params).then(res => {
if (addOrEdit == 'add') {
wx.$router.redirectTo('packageMine.successPage?page=staff')
} else {
wx.$router.back()
}
}).catch(err => {
_this.setData({
isConfirm: false
})
})
}
}
})
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})