index.js
6.87 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
// pages/customer/index.js
var mta=require('mta-wechat-analysis')
import App from '../../utils/api';
import util from '../../utils/util'
const {regeneratorRuntime} = global
Page({
/**
* 页面的初始数据
*/
data: {
loadHidden:false,
},
/**
* 生命周期函数--监听页面加载
*/
islove:'',//用户在哪端
enter_params:'',//商户入口参数
isInvitation:false,//客户经理
async onLoad(opt) {
console.log('onLoad', opt,mta);
//转化场景值到opt
this.selectComponent("#network").debug(opt, 'opt');
if (opt.scene) {//扫码进入
let query = decodeURIComponent(opt.scene);
query.split('&').forEach(q => {
let _q = q.split('=');
opt[_q[0]] = _q[1];
})
this.selectComponent("#network").debug(opt, 'scene');
}
mta.Page.init({
"appID":"500667280",
"eventID":"500667287",
"statPullDownFresh":true,
"statShareApp":true,
"statReachBottom":true,
"lauchOpts":opt, //渠道分析
});
opt.openid = await this.getOpenid();
if (!opt.openid) {
console.log('App.Orders.CheckOrder no openid');
this.selectComponent("#network").refresh();
return;
}
if(opt.islove){
util.cache('islove',opt.islove);
this.islove=opt.islove
}else{
this.islove=await util.cache('islove')
}
let usi=await App.Invitation.UserIdentity({openid:opt.openid});
if(usi.data.seller.flag){//商户
//获得商户数据
//this.enter_params=await this.SellerForOpenid(opt.openid);
this.enter_params=usi.data.data;
}
if(usi.data.invitation.flag){//已是客户经理
this.isInvitation=true;
}
//console.log('this.enter_params',this.enter_params)
let url = '/pages/reserve/index';
if (opt.id > 0 || opt.sms_code) {
if(opt.invite_name){
let invite_names=wx.getStorageSync('invite_names') ||{};
invite_names[opt.id]=opt.invite_name;
wx.setStorage({
key:'invite_names',
data:invite_names
});
}
let param={
openid: opt.openid,
}
if(opt.sms_code){
param.code=opt.sms_code;
}else{
param.rid=opt.id
}
App.Reserve.Detail(param).then(res => {
console.log(res.data.note_openid,this.enter_params.seller_openid)
if(this.enter_params){//商户
//if(res.data.sid==this.enter_params.seller_id && opt.hasSellerShare==1){//不是客户端分享,且是同一个店的
if(res.data.note_openid==this.enter_params.seller_openid && opt.hasSellerShare==1){//不是客户端分享,且是记录人
util.cache('enter_params',this.enter_params)
//url = '/pages/book/b_detail';
url = '/pages/book/b_invitation';
}
}
if(url!='/pages/book/b_invitation'){
//设置关系
App.Reserve.SetRelaOpenid({
rid:res.data.id,
openid:opt.openid,
fromid:opt.fromid?opt.fromid:''
})
if (!res.data.openid) {//无预订人
url = '/pages/customer/detail_owner';
if(opt.hasInvitation==1){
url = '/pages/customer/detail_owner_invitation';
}
} else {
url = '/pages/customer/detail_customer';
if(opt.hasInvitation==1){
url = '/pages/customer/detail_invitation';
}
if (res.data.openid == opt.openid) {
url = '/pages/customer/detail_owner';
if(opt.hasInvitation==1){
url = '/pages/customer/detail_owner_invitation';
}
}
}
}
url+='?id='+res.data.id+'&tplid='+(opt.tplid||1)
console.log('wx.redirectTo',url,res);
this.redirectTo({url: url});
}).catch(res=>{
this.redirectTo({url: url});
})
} else {
if(this.enter_params && this.islove!='customer' && this.islove!='invitation'){
//商户且未手动切换到顾客端或客户经理
wx.reLaunch({
url:util.http_build_query(this.enter_params,'/pages/book/b_index')
})
return;
}
if(this.isInvitation && this.islove!='customer' && this.islove!='book'){
//客户经理且未手动切换到顾客端或商户
wx.reLaunch({
url:'/pages/manager-invitation/review'
})
return;
}
console.log('url',url);
this.redirectTo({url: url});
}
},
redirectTo(red){
console.log('this.redirectTo',red);
if(red.url.indexOf('list')>0 || red.url.indexOf('reserve/index')>0){
wx.switchTab(red);
}else{
wx.redirectTo(red);
}
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
},
async getOpenid(){
let openid = getApp().openid;
return openid;
},
async SellerForOpenid(openid){
let enter_params='';
let res=await App.Reserve.SellerForOpenid({openid:openid});
if(res.data && res.data.seller_id){
enter_params=res.data;
}
if(enter_params) {
return enter_params;
}
// if(enter_params) {
// console.log('seller_enter_params', enter_params)
// wx.reLaunch({
// url:util.http_build_query(enter_params,'/pages/book/b_index')
// })
// return true
// }
return false
},
networkEvent(e){
console.log('networkEvent',e.detail);
if(!e.detail.hasWork){
this.setData({
loadHidden:true,
})
}
},
})