forked from EastWorld/wechat-app-mall
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
202 lines (201 loc) · 5.94 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
//app.js
App({
onLaunch: function () {
var that = this;
// 获取商城名称
wx.request({
url: 'https://api.it120.cc/'+ that.globalData.subDomain +'/config/get-value',
data: {
key: 'mallName'
},
success: function(res) {
if (res.data.code == 0) {
wx.setStorageSync('mallName', res.data.data.value);
}
}
})
wx.request({
url: 'https://api.it120.cc/' + that.globalData.subDomain + '/score/send/rule',
data: {
code: 'goodReputation'
},
success: function (res) {
if (res.data.code == 0) {
that.globalData.order_reputation_score = res.data.data[0].score;
}
}
})
wx.request({
url: 'https://api.it120.cc/' + that.globalData.subDomain + '/config/get-value',
data: {
key: 'recharge_amount_min'
},
success: function (res) {
if (res.data.code == 0) {
that.globalData.recharge_amount_min = res.data.data.value;
}
}
})
// 获取砍价设置
wx.request({
url: 'https://api.it120.cc/' + that.globalData.subDomain + '/shop/goods/kanjia/list',
data: {},
success: function (res) {
if (res.data.code == 0) {
that.globalData.kanjiaList = res.data.data.result;
}
}
})
this.login();
},
login : function () {
var that = this;
var token = that.globalData.token;
if (token) {
wx.request({
url: 'https://api.it120.cc/' + that.globalData.subDomain + '/user/check-token',
data: {
token: token
},
success: function (res) {
if (res.data.code != 0) {
that.globalData.token = null;
that.login();
}
}
})
return;
}
wx.login({
success: function (res) {
wx.request({
url: 'https://api.it120.cc/'+ that.globalData.subDomain +'/user/wxapp/login',
data: {
code: res.code
},
success: function(res) {
if (res.data.code == 10000) {
// 去注册
that.registerUser();
return;
}
if (res.data.code != 0) {
// 登录错误
wx.hideLoading();
wx.showModal({
title: '提示',
content: '无法登录,请重试',
showCancel:false
})
return;
}
//console.log(res.data.data)
that.globalData.token = res.data.data.token;
that.globalData.uid = res.data.data.uid;
}
})
}
})
},
registerUser: function () {
var that = this;
wx.login({
success: function (res) {
var code = res.code; // 微信登录接口返回的 code 参数,下面注册接口需要用到
wx.getUserInfo({
success: function (res) {
var iv = res.iv;
var encryptedData = res.encryptedData;
// 下面开始调用注册接口
wx.request({
url: 'https://api.it120.cc/' + that.globalData.subDomain +'/user/wxapp/register/complex',
data: {code:code,encryptedData:encryptedData,iv:iv}, // 设置请求的 参数
success: (res) =>{
wx.hideLoading();
that.login();
}
})
}
})
}
})
},
sendTempleMsg: function (orderId, trigger, template_id, form_id, page, postJsonString){
var that = this;
wx.request({
url: 'https://api.it120.cc/' + that.globalData.subDomain + '/template-msg/put',
method:'POST',
header: {
'content-type': 'application/x-www-form-urlencoded'
},
data: {
token: that.globalData.token,
type:0,
module:'order',
business_id: orderId,
trigger: trigger,
template_id: template_id,
form_id: form_id,
url:page,
postJsonString: postJsonString
},
success: (res) => {
//console.log('*********************');
//console.log(res.data);
//console.log('*********************');
}
})
},
sendTempleMsgImmediately: function (template_id, form_id, page, postJsonString) {
var that = this;
wx.request({
url: 'https://api.it120.cc/' + that.globalData.subDomain + '/template-msg/put',
method: 'POST',
header: {
'content-type': 'application/x-www-form-urlencoded'
},
data: {
token: that.globalData.token,
type: 0,
module: 'immediately',
template_id: template_id,
form_id: form_id,
url: page,
postJsonString: postJsonString
},
success: (res) => {
console.log(res.data);
}
})
},
getUserInfo: function (cb) {
var that = this
if (this.globalData.userInfo) {
typeof cb == "function" && cb(this.globalData.userInfo)
} else {
//调用登陆接口
wx.login({
success: function () {
wx.getUserInfo({
success: function (res) {
that.globalData.userInfo = res.userInfo
typeof cb == "function" && cb(that.globalData.userInfo)
}
})
}
})
}
},
globalData:{
userInfo:null,
subDomain: "tz", // 如果你的域名是: https://api.it120.cc/abcd 那么这里只要填写 abcd
version: "2.0",
shareProfile: '百款精品商品,总有一款适合您' // 首页转发的时候话术
}
/*
根据自己需要修改下单时候的模板消息内容设置,可增加关闭订单、收货时候模板消息提醒;
1、/pages/to-pay-order/index.js 中已添加关闭订单、商家发货后提醒消费者;
2、/pages/order-details/index.js 中已添加用户确认收货后提供用户参与评价;评价后提醒消费者好评奖励积分已到账;
3、请自行修改上面几处的模板消息ID,参数为您自己的变量设置即可。
*/
})