mine.js
3.02 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
const navStyle = "background-color: transparent;";
import MineApi from '~/api/mineApi/index'
import USERAPI from '~/api/usersApi/index'
import {
setUserInfo
} from '~/utils/cache/storageApi'
const DEPARTMENTLIST = ['销售部', '售后部', '客服部', '续保部',]
Page({
/**
* 页面的初始数据
*/
data: {
navStyle,
showModal: false,
},
navbarReady(e) {
let {
height
} = e.detail;
this.setData({
user_box_style: `padding-top:${height + 10}px`,
count_box_style: `padding-top:${height}px`,
});
},
onPageScroll: function (e) {
this.setData({
navStyle: e.scrollTop >= 38 ? "" : navStyle,
});
},
toAddEvent() {
wx.$eventbus.on('SETTING', (res) => {
this.getStaffInfo()
})
},
toShowBindModal(e) {
this.setData({
showModal: e.detail
})
},
toCloseModal() {
this.setData({
showModal: false
})
},
async toBindWechat(e) {
console.log(e);
if (e.detail.errMsg === "getPhoneNumber:ok") {
wx.$api.showLoading()
const { encryptedData, iv, code } = e.detail
USERAPI.wxCodeLogin().then(res => {
let { user } = this.data
let para = {
code,
encryptedData,
iv,
platformEntrance: 'STORE_ASSISTANT',
userType: user.userType,
staffPhone: user.phone,
merchantId: user.merchantId,
loginToken: res.data,
id:user.bussinessId
}
MineApi.wechatBindApi(para).then(res => {
this.getStaffInfo()
})
})
}
},
getStaffInfo() {
const userStorage = wx.$storage.get('userInfo')
let para = {
id: userStorage.bussinessId
}
MineApi.getStaffDetailApi(para).then(res => {
wx.hideLoading();
const temp = this.handleUserInfo(res)
this.setData({
user: temp
})
})
},
handleUserInfo(data) {
const userStorage = wx.$storage.get('userInfo')
const storage = {
merchantId: userStorage.merchantId,
userType: userStorage.userType,
merchantName: userStorage.merchantName,
phone: userStorage.phone,
}
const { id, staffPhone, phone, department, weChatNickName, weChatAvatarUrl,weChatPhone, weChatOpenId, staffName,merchantFileResponse } = data
let avatar = ''
if(merchantFileResponse){
avatar = merchantFileResponse.fileUrl
}
const USERINFO = {
headImgUrl: avatar || weChatAvatarUrl,
nickName: staffName,
seriseName: DEPARTMENTLIST[department - 1],
brandName: weChatNickName || weChatPhone || staffPhone,
bindStatus: weChatOpenId ? 1 : 0,
bussinessId: id,
...storage
}
// 更新缓存userinfo里面员工的姓名和员工部门
userStorage.name = staffName
userStorage.department = department
setUserInfo(userStorage)
return USERINFO
},
onLoad: function (options) {
this.getStaffInfo()
this.toAddEvent()
},
onPullDownRefresh: function () {
this.getStaffInfo()
wx.$eventbus.emit('REFRESH_WITHDRALWAL')
},
})