order.js
1.51 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
import urlAlias from '../url'
import request from '../request'
const { orderBuild, buyNow, pay } = urlAlias
const state = { list: [], param: {} }
const mutations = {
LIST: (state, list) => {
state.list = list
},
SAVE: (state, param) => {
state.param = param
},
}
const actions = {
// 立即购买->创建订单
buyNow({ commit }, param) {
return new Promise((resolve) => request({
url: buyNow,
data: param,
success: (res) => {
resolve(res)
},
fail: () => {
uni.showModal({
content: '创建订单失败',
showCancel: false,
})
},
}))
},
// 购物车->创建订单
build({ commit }, param) {
return new Promise((resolve, reject) => request({
url: orderBuild,
data: param,
success: (res) => {
resolve(res.data)
},
fail: () => {
uni.showModal({
content: '订单生成失败',
showCancel: false,
})
},
}))
},
// 支付
pay({ commit }, param) {
return new Promise((resolve, reject) => request({
url: pay,
data: param,
success: (res) => {
resolve(res.data)
},
fail: () => {
uni.showModal({
content: '订单生成失败',
showCancel: false,
})
},
}))
},
// 储存创建订单参数
saveParams({ commit }, param) {
console.log('save', param)
commit('SAVE', param)
},
}
export default {
namespaced: true,
state,
mutations,
actions,
}