s_confirm.js
3.15 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
var util = require('../../utils/util.js')
import App from '../../utils/api.js'
//测试
var app=getApp();
Page({
data:{
loading:false,
},
onLoad:function(opt){
console.log(opt)
app.scence=1;
this.canClick=true;
let query=decodeURIComponent(opt.scene);
console.log(query)
query.split('&').forEach(q=>{
let _q=q.split('=');
opt[_q[0]]=_q[1];
})
this.setData({
reminder1:'成为店员后,顾客点餐时,',
reminder2:'您将会收到交易通知',
})
this.opt=opt;
if(util.cache('openid')){
this.setData({
openid:util.cache('openid'),
loading:true
})
}else{
this.getopenid();
}
},
getopenid(){
wx.login({
//获取code
success: (login_res)=>{
console.log('cc',login_res.code)
var data = {
code: login_res.code,
appid: 'wx418f1d7cdeda26c1',
}
//获取openid
App.Wechat.GetSellerOpenidByCode(data).then((json)=>{
var openid = JSON.parse(json.data[0]).openid;//返回openid
this.setData({
openid:openid,
loading:true
})
util.cache('openid',openid);
})
},
fail:(res)=>{
console.log('dddddd',res)
}
})
},
//重新调起授权后,想接口获取信息
login_start(iv,encryptedData){
console.log(iv,encryptedData)
var that=this;
wx.login({
//获取code
success: (login_res)=>{
console.log('cc',login_res.code)
var data = {
code: login_res.code,
appid: 'wx418f1d7cdeda26c1',
iv:iv,
encryptedData:encryptedData
}
App.Wechat.WxLogin(data).then((json)=>{
if(json.ret==200){
console.log(json);
if(json.data && json.data.openid){
this.setData({
openid:json.data.openid
})
util.cache('openid',json.data.openid);
this.adduser();
}
}
})
}
})
},
getuserinfo(e){
console.log(e);
if(e.detail && e.detail.errMsg=='getUserInfo:ok'){
this.opt.user_name=e.detail.userInfo.nickName;
var iv=e.detail.iv;
var encryptedData=e.detail.encryptedData;
this.login_start(iv,encryptedData)
}else{
wx.showModal({
title:'添加店员',
content:'需要授权之后才能成为店员',
confirmText:'我知道了',
showConcel:false,
confirmColor:'#199095',
success:()=>{
this.canClick=true;
}
})
}
},
adduser(){
let parmdata={
...this.opt,
openid:this.data.openid
}
App.Seller.BatchAddUser(parmdata).then((json)=>{
if(json.ret==200){
wx.showToast({
title:'添加成功',
duration:2000,
mask:true,
})
setTimeout(()=>{
wx.redirectTo({
url:'../me/s_index?sellerid='+this.opt.sellerid
})
},2000)
}else{
wx.showToast({
title:'账号已存在',
duration:2000,
mask:true,
})
setTimeout(()=>{
wx.redirectTo({
url:'../me/s_index?sellerid='+this.opt.sellerid
})
},2000)
}
})
}
})