shop.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. // 根据UUID获取某店铺信息
  13. function findStoreInfoFromUuid ({ commit }, params = {}) {
  14. commit('storeInfo/REQUEST_STORE_INFO')
  15. return axios.get('/api/store-service/stores', { params })
  16. .then(response => {
  17. commit('storeInfo/GET_STORE_INFO_SUCCESS', response.data)
  18. return Promise.all([
  19. StoreFocusList({ commit }, {id: response.data.id})
  20. ])
  21. }, err => {
  22. commit('storeInfo/GET_STORE_INFO_FAILURE', err)
  23. })
  24. }
  25. export const actions = {
  26. // 根据UUID获取某店铺信息
  27. findStoreInfoFromUuid ({ commit }, params = {}) {
  28. commit('storeInfo/REQUEST_STORE_INFO')
  29. return axios.get('/api/store-service/stores', { params })
  30. .then(response => {
  31. commit('storeInfo/GET_STORE_INFO_SUCCESS', response.data)
  32. return Promise.all([
  33. StoreFocusList({ commit }, {id: response.data.id})
  34. ])
  35. }, err => {
  36. commit('storeInfo/GET_STORE_INFO_FAILURE', err)
  37. })
  38. },
  39. findCommodityOnBatchInfo ({ commit }, params = {}) {
  40. commit('storeInfo/REQUEST_COMMODITY')
  41. return axios.get(`/api/commodity/${params.batchCode || ''}/detail`)
  42. .then(response => {
  43. commit('storeInfo/GET_COMMODITY_SUCCESS', response.data)
  44. let commodity = response.data || {}
  45. commit('storeInfo/REQUEST_COMPONENT')
  46. return axios.get(`/api/commodity/component/${commodity.uuid}`)
  47. .then(response => {
  48. commit('storeInfo/GET_COMPONENT_SUCCESS', response.data)
  49. return Promise.all([
  50. findStoreInfoFromUuid({ commit }, {uuid: commodity.storeid})
  51. ])
  52. }, err => {
  53. commit('storeInfo/GET_COMPONENT_FAILURE', err)
  54. })
  55. }, err => {
  56. commit('storeInfo/GET_COMMODITY_FAILURE', err)
  57. })
  58. },
  59. findRecommendProducts ({ commit }, params = {}) {
  60. params.condition = 'store_uuid'
  61. commit('recommend/REQUEST_PRODUCTS')
  62. return axios.get('/api/store/recommend/products', { params })
  63. .then(response => {
  64. commit('recommend/GET_PRODUCTS_SUCCESS', response.data ? JSON.parse(JSON.stringify(response.data)) : [])
  65. }, err => {
  66. commit('recommend/GET_PRODUCTS_FAILURE', err)
  67. })
  68. },
  69. pageCommoditiesOfStore ({ commit }, uuid = '', pageParams = { page: 1, count: 10 }, code) {
  70. let params = { storeid: uuid, origin: 'store', code: code }
  71. params.page = pageParams.page
  72. params.count = pageParams.count
  73. commit('storeInfo/REQUEST_STORE_COMMODITY')
  74. return axios.get('/api/commodity/commodities', { params })
  75. .then(response => {
  76. commit('storeInfo/GET_STORE_COMMODITY_SUCCESS', response.data)
  77. }, err => {
  78. commit('storeInfo/GET_STORE_COMMODITY_FAILURE', err)
  79. })
  80. },
  81. mobilePageCommoditiesOfStore ({ commit }, params = {}) {
  82. commit('storeInfo/REQUEST_STORE_COMMODITY')
  83. return axios.get('/api/commodity/commodities', { params })
  84. .then(response => {
  85. commit('storeInfo/GET_STORE_COMMODITY_SUCCESS', response.data)
  86. }, err => {
  87. commit('storeInfo/GET_STORE_COMMODITY_FAILURE', err)
  88. })
  89. },
  90. // 获取保存浏览记录
  91. saveHistory ({ commit }, params = {}) {
  92. commit('storeInfo/REQUEST_SAVEHISOTRY')
  93. return axios.post(`/trade/history/goods/save?batchCode=${params.id}`, {})
  94. .then(response => {
  95. commit('storeInfo/GET_SAVEHISOTRY_SUCCESS', response.data)
  96. }, err => {
  97. commit('storeInfo/GET_SAVEHISOTRY_FAILURE', err)
  98. })
  99. },
  100. // 载入历史记录
  101. StoreFocusList ({ commit }, params = {}) {
  102. commit('storeInfo/REQUEST_FOCUSLIST')
  103. return axios.get(`/trade/storeFocus/ifFocus?storeid=${params.id}`)
  104. .then(response => {
  105. commit('storeInfo/GET_FOCUSLIST_SUCCESS', response.data)
  106. }, err => {
  107. commit('storeInfo/GET_FOCUSLIST_FAILURE', err)
  108. })
  109. },
  110. StoreFocus ({ commit }, storeName) {
  111. commit('storeInfo/REQUEST_FOCUS')
  112. return axios.post(`/trade/storeFocus/save`, storeName)
  113. .then(response => {
  114. commit('storeInfo/GET_FOCUS_SUCCESS', response.data)
  115. if (response.data === 'success') {
  116. commit('storeInfo/GET_FOCUSLIST_SUCCESS', 'true')
  117. }
  118. }, err => {
  119. commit('storeInfo/GET_FOCUS_FAILURE', err)
  120. })
  121. },
  122. // 根据UUID获取收藏店铺信息
  123. StoreFocusPage ({commit}, params = {}) {
  124. commit('storeInfo/REQUEST_FOCUSPAGE')
  125. return axios.get(`/trade/storeFocus/page`, {params})
  126. .then(response => {
  127. commit('storeInfo/GET_FOCUSPAGE_SUCCESS', response.data)
  128. }, err => {
  129. commit('storeInfo/GET_FOCUSPAGE_FAILURE', err)
  130. })
  131. },
  132. // 获取某店铺信息
  133. findStoreInfoFromEnUU ({ commit }, params = {}) {
  134. commit('storeInfo/REQUEST_STORE_INFO')
  135. return axios.get('/api/store-service/stores', { params })
  136. .then(response => {
  137. commit('storeInfo/GET_STORE_INFO_SUCCESS', response.data)
  138. }, err => {
  139. commit('storeInfo/GET_STORE_INFO_FAILURE', err)
  140. })
  141. },
  142. // 获取用户店铺关注数量
  143. loadStoreCollectInfo({ commit }) {
  144. commit('storeInfo/REQUEST_COLLECT')
  145. return axios.get('/trade/storeFocus/count')
  146. .then(response => {
  147. commit('storeInfo/REQUEST_COLLECT_SUCCESS', response.data)
  148. }, err => {
  149. commit('storeInfo/REQUEST_COLLECT_FAILURE', err)
  150. })
  151. }
  152. }