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) if (args.isadd) { state.cartList[args.index].num = args.num } else { state.cartList[args.index].num = args.num } console.log('the num', state.cartList[args.index].num) } } const actions = { getCartList({ commit }, param) { request({ url: cartList, data: param, success: (res) => { console.log('cart===>接口数据', res.data.data) // const resData = { // ...res, // data, // } commit('INIT', res.data.data) }, fail: (res) => { console.log('fail status === > ', res) }, complete: (res) => { console.log('complete status === > ', res) } }) }, modiCart({ commit }, param) { const args = Object.assign({ num: param.num }, param.args) delete param.args request({ url: cartModi, data: param, success: (res) => { console.log('modi-parm', param) commit('MODI', args) }, 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) // console.log('deacart====>cartList',this.$store.state.cart.cartList) 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) } }) } } export default { namespaced: true, state, mutations, actions }