orderConfirm.js
3.74 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
/**
* orderConfirm.js
*@author dennis
*@createtime 2018/10/26
*@description 订单支付确认界面
*/
import orderService from '../orderService'
import {getImgUrl} from '../../../utils';
import router from '../../../router/index.js'
import { prePay } from '../../order/wxpay.js'
Page({
data: {
payLabel: '待支付:',
payButton: '去支付',
protocolLabel: '我已阅读并同意',
protocolText: '买家协议',
agreeProtocol: false,
checkImage: '../../../assets/images/select@2x.png',
unCheckImage: '../../../assets/images/unselect@2x.png',
},
onLoad: function (option) {
console.log(option)
this.setData({
skup: option && option.skup ? option.skup : '',
product_id: option && option.product_id ? option.product_id : '',
hasAddress: false
})
this.fetchData()
this.fetchAddress()
},
fetchData() {
let api = new orderService();
wx.showLoading({
title: '',
});
let params = {
skup: this.data.skup,
}
api.createPaymentInfo(params, () => wx.hideLoading())
.then(data => {
if (data) {
if (data.good && data.good.goodImg) {
data.good.goodImg = getImgUrl(data.good.goodImg,270,270)
}
this.setData(data)
}
})
.catch(error => {
console.log(error)
})
},
fetchAddress() {
let api = new orderService().yohoApi()
wx.showLoading({
title: '',
})
let params = {
}
api.buyerGetAddress(params, () => wx.hideLoading())
.then(data => {
if (Array.isArray(data)){
for (let item of data) {
let index = data.indexOf(item)
if (item.is_default === 'Y') {
this.setData({
address: item,
hasAddress: true,
})
break
}
if (index == data.length - 1){
this.setData({
address: item,
hasAddress: true,
})
}
}
}
})
.catch(error => {
console.log(error)
})
},
submit() {
if (!this.data.agreeProtocol) return
if (!this.data.hasAddress) {
wx.showToast({
title:'请选择地址'
})
return
}
let addressId = this.data.hasAddress && this.data.address && this.data.address.address_id
let skup = this.data.skup
let channelNo = ''
let api = new orderService()
wx.showLoading({
title: '',
})
api.buyerSubmit(skup,channelNo,addressId, () => wx.hideLoading())
.then(data => {
if (data && data.orderCode) {
//todo:待处理微信数据分析上报,订单生成
// wx.reportAnalytics(eventName, data)
let orderCode = data.orderCode;
let productId = data.productId ? data.productId : '';
prePay(productId, orderCode, 0);
}
})
.catch(error => {
wx.showToast({
title: error.message,
icon: 'none'
})
})
},
chooseAddress: function(){
let addressId = this.data.address ? this.data.address.address_id : ''
let params = {
currentMode: 'modeSelect',
address_id: addressId
}
router.go('addressManager', params);
},
selectComplete: function(data) {
if (data) {
this.setData({
address: data,
hasAddress: true
})
}
},
checkProtocol: function () {
this.setData({
agreeProtocol: !this.data.agreeProtocol
})
},
goProtocol: function () {
let url = `http://m.yohobuy.com/activity/student/detail/renzhen?openby:yohobuy={\"action\":\"go.h5\",\"params\":{\"url\":\"https://activity.yoho.cn/feature/3189.html?title=买家协议\"}}`;
router.goUrl(url);
},
})