-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
318 lines (298 loc) · 9.5 KB
/
app.js
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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
//app.js
App({
onLaunch: function() {
// 登录
wx.login({
success: function(res) {
var that = this;
if (res.code)
wx.setStorageSync('code', res.code); //准备发送code到后台换取 openId, sessionKey, unionId
else
console.log('wx.login.....code获取失败' + res.errMsg);
//尝试读取缓存中的user_id
var user_id = wx.getStorageSync('user_id');
if (user_id)
console.log("wx.login...缓存中的user_id =", user_id);
else {
console.log("wx.login...缓存中的user_id获取失败");
//wx.setStorageSync('user_id', '00000');
}
}
})
// 获取用户信息
wx.getSetting({
success: res => {
// 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
if (res.authSetting['scope.userInfo'])
wx.getUserInfo({
success: res => {
//
// 可以将 res 发送给后台解码出 unionId
//
this.globalData.userInfo = res.userInfo;
// 由于 getUserInfo 是网络请求,可能会在Page.onLoad之后才返回,所以此处加入 callback 以防止这种情况
if (this.userInfoReadyCallback)
this.userInfoReadyCallback(res)
}
});
}
})
},
globalData: {
wantRegisterCompany: true,
userInfo: null,
industry: null, //行业类型数据,从服务器拉取
//* 转发*********************************************
shareApp: function(res) {
if (res.from === 'button') { //如果来自页面内转发按钮
console.log(res.target)
}
var path = '/pages/index/index?company_id=' + wx.getStorageSync('company_id') + '&user_id=' + wx.getStorageSync('user_id') + '&company_type=' + wx.getStorageSync('company_type'); //+ '&role_type=' + wx.getStorageSync('role_type');
console.log("onShareAppMessage, path =", path);
return {
title: '生产管理小程序',
path: path,
}
},
////////////////////////////////////////////////////////////////
// moreInfo menu
// 路由菜单
////////////////////////////////////////////////////////////////
param: {},
// 设置moreInfo菜单的内容--------------------------
setMenu: function(that, contents, str_type, associate_code) {
// 遍历contents数组中的[str_type]属性,将它们添加到数组types中
var len = contents.length;
if (len == 0)
return;
var types = [contents[0][str_type]];
for (var i = 1; i < len; i++) {
var n = types.length,
type = contents[i][str_type],
b = false;
for (var j = 0; j < n; j++) {
if (type === types[j]) {
b = true;
break;
}
}
if (!b)
types.push(type);
}
// that.setData({
// types: types
// });
// console.log("types=",types);
// 根据不同的types,查询若干个路由菜单列表,以type为key将这些列表放入menuObject
len = types.length;
for (var i = 0; i < len; i++) {
var args = ['menuObject.' + types[i], that];
var param = {
their_scene_code: "01",
their_scene_type: wx.getStorageSync('role_type'), //暂时写死
their_scene_name: this.convertCode("01"),
their_associate_code: associate_code,
their_associate_type: types[i],
their_associate_name: this.convertCode(associate_code),
};
// console.log(param);
require('utils/data.js').getParamsByEntity(param, this.setMenuObject, args);
}
},
// ---------------------------------------
setMenuObject: function(res, args) {
var data = res.data,
l = data.length;
console.log("setMenu...res.data = ", data, "args=", args);
if (l > 0) {
args[1].setData({
[args[0]]: data
})
}
},
//* 显示更多内容(显示路由菜单)*******************************************
showMoreInfo: function(that, index, content_type, goByIdFunc) {
var self = this,
menuList = that.data.menuObject[content_type],
itemList = [];
if (menuList.length <= 1) {
goByIdFunc(index);
return;
}
for (var i = 0; i < menuList.length; i++)
itemList.push(menuList[i].other_associate_name);
wx.showActionSheet({
itemList: itemList,
success(res) {
var value = menuList[res.tapIndex].other_associate_code,
name = menuList[res.tapIndex].other_associate_name,
o_type = menuList[res.tapIndex].other_associate_type,
url = self.getUrlByCode(value) + '?hasTabBar=false'; //hasTabBar参数的意义:从朋友这边跳转到页面时,屏蔽tabBar
if (name == "代理商" || (value == "01" && o_type == "301")) {
url = self.getUrlByCode(o_type) + '?hasTabBar=false';
// if(!that.data.hasTabBar)
// wx.setStorageSync('level', parseInt(wx.getStorageSync('level')+1));
}
if (name == "详情" || (o_type == "000" && value == "999")) //todo:999应为对应场景的code
goByIdFunc(index);
else {
//设置:查询数据所用的参数their_associate_xxx...
var their_info = wx.getStorageSync('their_info');
self.param = {
their_associate_code: their_info.code || "01",
their_associate_type: their_info.type || wx.getStorageSync('role_type'),
their_associate_number: their_info.number || wx.getStorageSync('user_id'),
their_associate_name: self.convertCode(their_info.code),
other_associate_code: value,
other_associate_type: o_type,
other_associate_number: "00000",
other_associate_name: name,
};
// wx.removeStorageSync('their_info');
wx.navigateTo({
url: url
});
}
}
})
},
//------------------------------------------
setTheirInfo: function(code, type, number) {
var their_info = {
code: code,
type: type,
number: number
};
wx.setStorageSync('their_info', their_info);
},
////////////////////////////////////////////////////////////
// tabBar
////////////////////////////////////////////////////////////
tabBar: {
"color": "#9E9E9E",
"selectedColor": "#f00",
"backgroundColor": "#fff",
"borderStyle": "#ccc",
"list": [],
"position": "bottom"
},
getTabBarListItem: function(data) {
var entity_code = data.entity_code; //商群01、工单02、订单03、评价单04、业务单据05、记账凭证06、内容07、钱包08、店铺09、商品10
var listItem = {
pagePath: "",
text: data.entity_name,
iconPath: "",
selectedIconPath: "",
selectedColor: "#1aad19",
active: false,
//number: parseInt(data.serial_number),
};
listItem.pagePath = this.getUrlByCode(entity_code);
listItem.iconPath = "/imgs/" + entity_code + ".png";
listItem.selectedIconPath = "/imgs/" + entity_code + "_fill.png";
return listItem;
},
convertCode: function(code) {
var str = "";
switch (code) {
case "01":
str = "用户";
break;
case "02":
str = "工单";
break;
case "03":
str = "订单";
break;
case "05":
str = "业务单据";
break;
case "06":
str = "记账凭证";
break;
case "07":
str = "内容";
break;
case "08":
str = "账户"; //钱包
break;
case "09":
str = "店铺";
break;
case "10":
str = "商品";
break;
case "11":
str = "CLASS";
break;
case "11":
str = "消息";
break;
case "13":
str = "社保";
break;
case "90":
str = "报表";
break;
case "98":
str = "系统";
break;
case "301":
str = "代理商"
break;
}
return str;
},
getUrlByCode: function(code) {
var str = "";
switch (code) {
case "01":
str = "/pages/friends/manage";
break;
case "02":
str = "/pages/operate/operate";
break;
case "03":
str = "/pages/inquiry/inquiry";
break;
case "05":
str = "业务单据";
break;
case "06":
str = "记账凭证";
break;
case "07":
str = "/pages/market/content/list";
break;
case "08":
str = "/pages/market/wallet/wallet";
break;
case "09":
str = "/pages/market/shop/list";
break;
case "10":
str = "商品";
break;
case "11":
str = "CLASS";
break;
case "12":
str = "/pages/message/list";
break;
case "13":
str = "/pages/message/safe/main";
break;
case "90":
str = "报表";
break;
case "98":
str = "系统";
break;
case "301":
str = "/pages/friends/roleSale/manage"
break;
}
return str;
},
}
})