user.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import axios from '~/plugins/axios'
  2. export const actions = {
  3. // 获取浏览记录
  4. loadHistory ({ commit }, params = {}) {
  5. commit('history/REQUEST_HISTORY')
  6. return axios.get('/trade/history/goods/list', {params})
  7. .then(response => {
  8. commit('history/GET_HISTORY_SUCCESS', response.data)
  9. }, err => {
  10. commit('history/GET_HISTORY_FAILURE', err)
  11. })
  12. },
  13. // 删除一条历史记录
  14. deleteHistory ({ commit }, params = {}) {
  15. commit('history/REQUEST_DELETE')
  16. return axios.post(`/trade/history/goods/setDelete?id=${params.id}`, {})
  17. .then(response => {
  18. commit('history/GET_DELETE_SUCCESS', response.data)
  19. }, err => {
  20. commit('history/GET_DELETE_FAILURE', err)
  21. })
  22. },
  23. // 获取购物车数量
  24. CarCount ({ commit }, params = {}) {
  25. commit('history/REQUEST_CARTCOUNT')
  26. return axios.get(`/trade/cart/count`, {params})
  27. .then(response => {
  28. commit('history/GET_CARTCOUNT_SUCCESS', response.data)
  29. }, err => {
  30. commit('history/GET_CARTCOUNT_FAILURE', err)
  31. })
  32. },
  33. // 获取购买信息
  34. getBuyInfo ({ commit }, params) {
  35. commit('buy/REQUEST_BUY')
  36. return axios.post(`/trade/order/buyNow`, params)
  37. .then(response => {
  38. commit('buy/GET_BUY_SUCCESS', response.data)
  39. }, err => {
  40. commit('buy/GET_BUY_FAILURE', err)
  41. })
  42. },
  43. // 加入购物车
  44. addCar ({ commit }, params) {
  45. commit('car/REQUEST_CAR')
  46. return axios.post(`/trade/cart/add`, params)
  47. .then(response => {
  48. commit('car/GET_CAR_SUCCESS', response.data)
  49. }, err => {
  50. commit('car/GET_CAR_FAILURE', err)
  51. })
  52. }
  53. }