Blame view

src/store/modules/cart.js 2.54 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 = {
058f060df   范牧   冲突修改
7
    cartList: []
cc196c33c   喻鹏   购物车和用户推荐接口渲染
8
  }
7d2bdf29e   喻鹏   修改镜片选购逻辑 添加购物车和用户...
9
10
  const mutations = {
    INIT: (state, cartList) => {
058f060df   范牧   冲突修改
11
      state.cartList = cartList
7d2bdf29e   喻鹏   修改镜片选购逻辑 添加购物车和用户...
12
    },
058f060df   范牧   冲突修改
13
14
15
16
17
    DEL: (state, index) => {
      console.log('mutations====>', state.cartList)
      state.cartList.splice(index, 1)
      console.log('mutations====>index', index)
      // state.cartList=delList
cc196c33c   喻鹏   购物车和用户推荐接口渲染
18
    },
058f060df   范牧   冲突修改
19
20
21
    MODI: (state, args) => {
      console.log('the num', state.cartList[args.index].num)
      console.log('mutations====>isadd', args)
637a02b07   尹聃   添加购物车
22
      state.cartList[args.index].num = args.num
058f060df   范牧   冲突修改
23
24
      console.log('the num', state.cartList[args.index].num)
    }
7d2bdf29e   喻鹏   修改镜片选购逻辑 添加购物车和用户...
25

058f060df   范牧   冲突修改
26
  }
7d2bdf29e   喻鹏   修改镜片选购逻辑 添加购物车和用户...
27
28
  
  const actions = {
7d2bdf29e   喻鹏   修改镜片选购逻辑 添加购物车和用户...
29
30
31
    getCartList({ commit }, param) {
      request({
        url: cartList,
058f060df   范牧   冲突修改
32
        data: param,
7d2bdf29e   喻鹏   修改镜片选购逻辑 添加购物车和用户...
33
        success: (res) => {
058f060df   范牧   冲突修改
34
          console.log('cart===>接口数据', res.data.data)
7d2bdf29e   喻鹏   修改镜片选购逻辑 添加购物车和用户...
35
36
37
          commit('INIT', res.data.data)
        },
        fail: (res) => {
058f060df   范牧   冲突修改
38
          console.log('fail status === > ', res)
7d2bdf29e   喻鹏   修改镜片选购逻辑 添加购物车和用户...
39
40
        },
        complete: (res) => {
058f060df   范牧   冲突修改
41
42
43
44
45
46
          console.log('complete status === > ', res)
        }
      })
    },
  
    modiCart({ commit }, param) {
acc7ee230   喻鹏   购物车,用户推荐,新增验光逻辑修改
47
      const arg = Object.assign({ num: param.num }, param.args)
058f060df   范牧   冲突修改
48
49
50
51
52
      delete param.args
      request({
        url: cartModi,
        data: param,
        success: (res) => {
637a02b07   尹聃   添加购物车
53
          console.log('modiCart-res=====>', res.data)
058f060df   范牧   冲突修改
54
          console.log('modi-parm', param)
acc7ee230   喻鹏   购物车,用户推荐,新增验光逻辑修改
55
          commit('MODI', arg)
7d2bdf29e   喻鹏   修改镜片选购逻辑 添加购物车和用户...
56
        },
058f060df   范牧   冲突修改
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
        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)
058f060df   范牧   冲突修改
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
          commit('DEL', arg)
        },
        fail: (res) => {
          console.log('fail status === > ', res)
        },
        complete: (res) => {
          console.log('complete status === > ', res)
        }
      })
    },
  
    addCart({ commit }, param) {
      console.log('请求接口开始')
      request({
        url: cartAdd,
        data: param,
        success: (res) => {
          console.log('add-parm', param)
          console.log('addcart===>res.data===>', res.data)
          // commit('INIT', res.data.data)
        },
        fail: (res) => {
          console.log('fail status === > ', res)
        },
        complete: (res) => {
          console.log('complete status === > ', res)
        }
7d2bdf29e   喻鹏   修改镜片选购逻辑 添加购物车和用户...
102
103
      })
    }
058f060df   范牧   冲突修改
104

7d2bdf29e   喻鹏   修改镜片选购逻辑 添加购物车和用户...
105
106
107
108
109
110
  }
  
  export default {
    namespaced: true,
    state,
    mutations,
058f060df   范牧   冲突修改
111
112
    actions
  }