package.js
5.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
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
import USERAPI from "~/api/usersApi/index";
Page({
/**
* 页面的初始数据
*/
data: {
packageInfo: {},
showAuthBtn: false,
shareStaff: {}
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
if (!options.id) {
return
}
this.login()
this.getPackageDetail(options.id)
// 推荐人
if (options.shareStaffUuid) {
this.data.shareStaff = {
shareStaffUuid: options.shareStaffUuid,
shareStaffName: options.shareStaffName
}
options.item_type = 4
options.action_type = 1
options.item_id = options.id
this.data.recommandOptions = options
// wx.$util.reportData(options, false, false, true)
}
if (options.activity_id) {
this.data.options = options
// wx.$util.reportData(options, true, false)
}
},
// 登录
login() {
USERAPI.login().then(res => {
if (res.data) {
wx.$authStatus = res.data.phone ? false : true
this.setNaviTitle(res.data.merchantName)
this.setData({
sessionId: res.data.sessionId,
showAuthBtn: res.data.phone ? false : true
})
if (res.data.isLogin) {
wx.p.cache.userInfo.setUserInfo(res.data)
wx.p.cache.storageApi.setSessionId(res.data.sessionId)
this.handlerCustomerId()
}
}
})
},
// 设置标题名称
setNaviTitle(title) {
wx.setNavigationBarTitle({
title
})
},
getPhoneNumber({ detail }) {
const { sessionId } = this.data
if (!sessionId) return
USERAPI.authUserPhone(detail, sessionId).then(({ data, code, message }) => {
wx.hideLoading()
if (code == '0') {
wx.p.authStatus = false
wx.p.cache.userInfo.setUserInfo(data)
wx.p.cache.storageApi.setSessionId(data.sessionId)
this.toCreatePackageNum()
this.handlerCustomerId()
} else wx.p.wxApi.showToast(message)
})
},
// 获取套餐详情
getPackageDetail(id) {
wx.p.api.couponsApi
.packageInfo({
id
})
.then(res => {
if (res.couponsDetailList.length) {
res.couponsDetailList.map(item => {
item.effectiveEndTime = new Date(item.effectiveEndTime).format('yyyy-MM-dd hh:mm:ss')
// item.shopTotalPrice = this.priceFormat(item.shopTotalPrice)
return item
})
}
this.setData({
packageInfo: res,
packageId: id
})
})
},
// 获取门店单号
toCreatePackageNum() {
wx.p.wxApi.showLoading()
wx.p.api.couponsApi.createOrderNum().then(res => {
wx.hideLoading()
if (res) {
// this.setData({
// orderCode:res
// })
this.createStoreOrder(res)
}
})
},
// 创建订单
createStoreOrder(orderCode) {
let { packageId, sessionId, packageInfo, shareStaff } = this.data
let para = {
packageId,
paySource: 3,
sessionId,
orderCode,
...shareStaff
}
let jumpParam = {
orderCode,
name: packageInfo.packageName,
price: packageInfo.packagePrice
}
wx.p.wxApi.showLoading()
let _this = this
wx.p.api.couponsApi.createOrder(para).then(res => {
wx.hideLoading()
if (res) {
const { timeStamp, nonceStr, packages, signType, paySign } = res
wx.requestPayment({
timeStamp: timeStamp,
nonceStr: nonceStr,
package: packages,
signType: signType,
paySign: paySign,
success() {
let temp = JSON.stringify(jumpParam)
wx.navigateTo({
url: '/packageEquity/pages/success/success?order=' + temp
})
},
fail(res) {
if (res.errMsg == 'requestPayment:fail cancel') {
wx.p.wxApi.showToast('取消支付')
}
}
})
}
})
},
// 客户id
handlerCustomerId() {
// let customerId = wx.p.storage.get('srcm_shopmall_customer_id')
// if (customerId) USERAPI.updataCustomerPhone()
},
// 价格格式化
// priceFormat(num, point = 2) {
// let numStr = num.toString().split('.')[0]
// if (numStr.length < 6) { // 判断数字有多长,如果小于6,,表示10万以内的数字,让其直接显示
// return numStr;
// } else if (numStr.length >= 6 && numStr.length <= 8) { // 如果数字大于6位,小于8位,让其数字后面加单位万
// point = 0
// let decimal = numStr.substring(numStr.length - 4, numStr.length - 4 + point)
// console.log(decimal);
// // 由千位,百位组成的一个数字
// return parseFloat(parseInt(num / 10000) + '.' + decimal) + '万'
// } else if (numStr.length > 8) { // 如果数字大于8位,让其数字后面加单位亿
// let decimal = numStr.substring(numStr.length - 8, numStr.length - 8 + point);
// console.log(decimal);
// return parseFloat(parseInt(num / 100000000) + '.' + decimal) + '亿'
// }
// },
onUnload: function () {
// wx.$util.customerbehavior(2)
}
})