Blame view
src/store/modules/cart.js
2.05 KB
058f060df
|
1 2 |
import urlAlias from '../url' import request from '../request' |
7d2bdf29e
|
3 |
|
058f060df
|
4 |
const { cartList, cartModi, cartDel, cartAdd } = urlAlias |
7d2bdf29e
|
5 6 |
const state = { |
61d825263
|
7 8 9 |
cartList: [], checkedCartLst:[], buyItem:Object |
cc196c33c
|
10 |
} |
7d2bdf29e
|
11 12 |
const mutations = { INIT: (state, cartList) => { |
058f060df
|
13 |
state.cartList = cartList |
7d2bdf29e
|
14 |
}, |
058f060df
|
15 |
DEL: (state, index) => { |
058f060df
|
16 |
state.cartList.splice(index, 1) |
cc196c33c
|
17 |
}, |
058f060df
|
18 |
MODI: (state, args) => { |
637a02b07
|
19 |
state.cartList[args.index].num = args.num |
b38a27f3e
|
20 |
}, |
7d2bdf29e
|
21 |
|
058f060df
|
22 |
} |
7d2bdf29e
|
23 24 |
const actions = { |
b38a27f3e
|
25 |
// 获取购物车列表 |
0bda9efec
|
26 27 |
getCartList({ commit }, param) { return new Promise((resolve) => request({ |
7d2bdf29e
|
28 |
url: cartList, |
058f060df
|
29 |
data: param, |
7d2bdf29e
|
30 |
success: (res) => { |
1dbb125ac
|
31 32 33 34 35 |
let test = { isChecked: false, itemNum:1, price:0 } |
0bda9efec
|
36 37 |
commit('INIT', res.data.data) resolve(res.data.data) |
7d2bdf29e
|
38 |
}, |
0bda9efec
|
39 |
})) |
058f060df
|
40 |
}, |
b38a27f3e
|
41 |
// 修改购物车数量 |
058f060df
|
42 |
modiCart({ commit }, param) { |
acc7ee230
|
43 |
const arg = Object.assign({ num: param.num }, param.args) |
058f060df
|
44 |
delete param.args |
22e1420fa
|
45 |
return new Promise((resolve) => request({ |
058f060df
|
46 47 48 |
url: cartModi, data: param, success: (res) => { |
acc7ee230
|
49 |
commit('MODI', arg) |
7d2bdf29e
|
50 |
}, |
058f060df
|
51 |
fail: (res) => { |
058f060df
|
52 53 |
}, complete: (res) => { |
b38a27f3e
|
54 |
}, |
22e1420fa
|
55 |
})) |
058f060df
|
56 |
}, |
b38a27f3e
|
57 |
// 删除购物车商品 |
058f060df
|
58 59 60 61 62 63 64 |
delCart({ commit }, param) { const arg = param.arg delete param.arg request({ url: cartDel, data: param, success: (res) => { |
058f060df
|
65 66 67 |
commit('DEL', arg) }, fail: (res) => { |
058f060df
|
68 69 |
}, complete: (res) => { |
b38a27f3e
|
70 |
}, |
058f060df
|
71 72 |
}) }, |
b38a27f3e
|
73 |
// 添加到购物车 |
058f060df
|
74 75 |
addCart({ commit }, param) { console.log('请求接口开始') |
0bda9efec
|
76 |
return new Promise((resolve) => request({ |
058f060df
|
77 78 79 80 81 |
url: cartAdd, data: param, success: (res) => { console.log('add-parm', param) console.log('addcart===>res.data===>', res.data) |
0bda9efec
|
82 83 |
// commit('INIT', res.data.data) resolve(res.data) |
058f060df
|
84 85 |
}, fail: (res) => { |
0bda9efec
|
86 |
console.log('添加购物车失败 === > ', res) |
058f060df
|
87 88 |
}, complete: (res) => { |
0bda9efec
|
89 |
console.log('添加购物车完成 === > ', res) |
b38a27f3e
|
90 |
}, |
0bda9efec
|
91 |
})) |
b38a27f3e
|
92 |
}, |
7d2bdf29e
|
93 94 95 96 97 98 |
} export default { namespaced: true, state, mutations, |
b38a27f3e
|
99 |
actions, |
058f060df
|
100 |
} |