cart.js
2.61 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
import urlAlias from '../url'
import request from '../request'
const { cartList, cartModi, cartDel, cartAdd } = urlAlias
const state = {
cartList: [],
}
const mutations = {
INIT: (state, cartList) => {
state.cartList = cartList
},
DEL: (state, index) => {
console.log('mutations====>', state.cartList)
state.cartList.splice(index, 1)
console.log('mutations====>index', index)
// state.cartList=delList
},
MODI: (state, args) => {
console.log('the num', state.cartList[args.index].num)
console.log('mutations====>isadd', args)
state.cartList[args.index].num = args.num
console.log('the num', state.cartList[args.index].num)
},
}
const actions = {
// 获取购物车列表
getCartList({ commit }, param) {
return new Promise((resolve) => request({
url: cartList,
data: param,
success: (res) => {
console.log('cart===>接口数据', res.data.data)
commit('INIT', res.data.data)
resolve(res.data.data)
},
}))
},
// 修改购物车数量
modiCart({ commit }, param) {
const arg = Object.assign({ num: param.num }, param.args)
delete param.args
request({
url: cartModi,
data: param,
success: (res) => {
console.log('modiCart-res=====>', res.data)
console.log('modi-parm', param)
commit('MODI', arg)
},
fail: (res) => {
console.log('fail status === > ', res)
},
complete: (res) => {
console.log('complete status === > ', res)
},
})
},
// 删除购物车商品
delCart({ commit }, param) {
const arg = param.arg
delete param.arg
request({
url: cartDel,
data: param,
success: (res) => {
console.log('del-parm', param)
console.log('del-myparms==>', arg)
commit('DEL', arg)
},
fail: (res) => {
console.log('fail status === > ', res)
},
complete: (res) => {
console.log('complete status === > ', res)
},
})
},
// 添加到购物车
addCart({ commit }, param) {
console.log('请求接口开始')
return new Promise((resolve) => request({
url: cartAdd,
data: param,
success: (res) => {
console.log('add-parm', param)
console.log('addcart===>res.data===>', res.data)
// commit('INIT', res.data.data)
resolve(res.data)
},
fail: (res) => {
console.log('添加购物车失败 === > ', res)
},
complete: (res) => {
console.log('添加购物车完成 === > ', res)
},
}))
},
}
export default {
namespaced: true,
state,
mutations,
actions,
}