shop.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import axios from '~plugins/axios'
  2. // 载入历史记录
  3. function StoreFocusList ({ commit }, params = {}) {
  4. commit('storeInfo/REQUEST_FOCUSLIST')
  5. return axios.get(`/trade/storeFocus/ifFocus?storeid=${params.id}`)
  6. .then(response => {
  7. commit('storeInfo/GET_FOCUSLIST_SUCCESS', response.data)
  8. }, err => {
  9. commit('storeInfo/GET_FOCUSLIST_FAILURE', err)
  10. })
  11. }
  12. export const actions = {
  13. // 根据UUID获取某店铺信息
  14. findStoreInfoFromUuid ({ commit }, params = {}) {
  15. commit('storeInfo/REQUEST_STORE_INFO')
  16. return axios.get('/api/store-service/stores', { params })
  17. .then(response => {
  18. commit('storeInfo/GET_STORE_INFO_SUCCESS', response.data)
  19. return Promise.all([
  20. StoreFocusList({ commit }, {id: response.data.id})
  21. ])
  22. }, err => {
  23. commit('storeInfo/GET_STORE_INFO_FAILURE', err)
  24. })
  25. },
  26. findCommodityOnBatchInfo ({ commit }, params = {}) {
  27. commit('storeInfo/REQUEST_COMMODITY')
  28. return axios.get(`/api/commodity/${params.batchCode || ''}/detail`)
  29. .then(response => {
  30. commit('storeInfo/GET_COMMODITY_SUCCESS', response.data)
  31. let commodity = response.data || {}
  32. commit('storeInfo/REQUEST_COMPONENT')
  33. return axios.get(`/api/commodity/component/${commodity.uuid}`)
  34. .then(response => {
  35. commit('storeInfo/GET_COMPONENT_SUCCESS', response.data)
  36. }, err => {
  37. commit('storeInfo/GET_COMPONENT_FAILURE', err)
  38. })
  39. }, err => {
  40. commit('storeInfo/GET_COMMODITY_FAILURE', err)
  41. })
  42. },
  43. findRecommendProducts ({ commit }, params = {}) {
  44. params.condition = 'store_uuid'
  45. commit('recommend/REQUEST_PRODUCTS')
  46. return axios.get('/api/store/recommend/products', { params })
  47. .then(response => {
  48. commit('recommend/GET_PRODUCTS_SUCCESS', response.data ? JSON.parse(JSON.stringify(response.data)) : [])
  49. }, err => {
  50. commit('recommend/GET_PRODUCTS_FAILURE', err)
  51. })
  52. },
  53. pageCommoditiesOfStore ({ commit }, uuid = '', pageParams = { page: 1, count: 6 }, code) {
  54. let params = { storeid: uuid, origin: 'store', code: code }
  55. params.page = pageParams.page
  56. params.count = pageParams.count
  57. commit('storeInfo/REQUEST_STORE_COMMODITY')
  58. return axios.get('/api/commodity/commodities', { params })
  59. .then(response => {
  60. commit('storeInfo/GET_STORE_COMMODITY_SUCCESS', response.data)
  61. }, err => {
  62. commit('storeInfo/GET_STORE_COMMODITY_FAILURE', err)
  63. })
  64. },
  65. // 获取保存浏览记录
  66. saveHistory ({ commit }, params = {}) {
  67. commit('storeInfo/REQUEST_SAVEHISOTRY')
  68. return axios.post(`/trade/history/goods/save?batchCode=${params.id}`, {})
  69. .then(response => {
  70. commit('storeInfo/GET_SAVEHISOTRY_SUCCESS', response.data)
  71. }, err => {
  72. commit('storeInfo/GET_SAVEHISOTRY_FAILURE', err)
  73. })
  74. },
  75. // 载入历史记录
  76. StoreFocusList ({ commit }, params = {}) {
  77. commit('storeInfo/REQUEST_FOCUSLIST')
  78. return axios.get(`/trade/storeFocus/ifFocus?storeid=${params.id}`)
  79. .then(response => {
  80. console.log(response.data)
  81. commit('storeInfo/GET_FOCUSLIST_SUCCESS', response.data)
  82. }, err => {
  83. commit('storeInfo/GET_FOCUSLIST_FAILURE', err)
  84. })
  85. },
  86. StoreFocus ({ commit }, storeName) {
  87. commit('storeInfo/REQUEST_FOCUS')
  88. return axios.post(`/trade/storeFocus/save`, storeName)
  89. .then(response => {
  90. commit('storeInfo/GET_FOCUS_SUCCESS', response.data)
  91. if (response.data === 'success') {
  92. commit('storeInfo/GET_FOCUSLIST_SUCCESS', 'true')
  93. }
  94. }, err => {
  95. commit('storeInfo/GET_FOCUS_FAILURE', err)
  96. })
  97. }
  98. }