provider.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. import axios from '~plugins/axios'
  2. /**
  3. * 获取某店铺的交易量
  4. *
  5. * @param store 店铺信息
  6. */
  7. function countStoreOrderCount (store) {
  8. return axios.get('/api/provider/order/storeid/' + store.uuid + '/count')
  9. }
  10. function findStoreFocusInMobil (store) {
  11. return axios.get('/trade/storeFocus/ifFocus?storeid=' + store.id)
  12. }
  13. export const actions = {
  14. // 获取销售排行榜信息
  15. loadSalesStore ({ commit }, params = {isOriginal: false}) {
  16. commit('storeCms/REQUEST_SALES')
  17. return axios.get('/api/store-service/stores', {
  18. params: {
  19. filter: 'topBySales',
  20. isOriginal: params.isOriginal
  21. }
  22. }).then(response => {
  23. let stores = response.data || []
  24. let orderCounts = []
  25. for (let i = 0; i < stores.length; i++) {
  26. orderCounts.push(countStoreOrderCount(stores[i]))
  27. }
  28. // 合并请求,获取店铺的交易量数据
  29. return Promise.all(orderCounts)
  30. .then(result => {
  31. if (result) {
  32. for (let i = 0; i < result.length; i++) {
  33. stores[i].orderCount = result[i].data ? result[i].data.orderCount : 0
  34. }
  35. }
  36. commit('storeCms/GET_SALES_SUCCESS', stores)
  37. }, err => {
  38. commit('storeCms/GET_SALES_FAILURE', err)
  39. })
  40. }, err => {
  41. commit('storeCms/GET_SALES_FAILURE', err)
  42. })
  43. },
  44. // 获取原厂入驻数量信息
  45. loadFactoriesCount ({commit}, params = {types: 'ORIGINAL_FACTORY'}) {
  46. commit('stores/REQUEST_ORIGINALCOUNT')
  47. return axios.get('/api/store-service/stores/type/count', {
  48. params: {
  49. types: params.types
  50. }
  51. }).then(response => {
  52. commit('stores/GET_ORIGINALCOUNT_SUCCESS', response.data && response.data.success ? response.data.data : 0)
  53. }, err => {
  54. commit('stores/GET_ORIGINALCOUNT_FAILURE', err)
  55. })
  56. },
  57. // 获取代理经销入驻数量信息
  58. loadAgencyCount ({commit}, params = {types: 'AGENCY-DISTRIBUTION'}) {
  59. commit('stores/REQUEST_STORE_COUNT')
  60. return axios.get('/api/store-service/stores/type/count', {
  61. params: {
  62. types: params.types
  63. }
  64. }).then(response => {
  65. commit('stores/GET_STORE_COUNT_SUCCESS', response.data && response.data.success ? response.data.data : 0)
  66. }, err => {
  67. commit('stores/GET_STORE_COUNT_FAILURE', err)
  68. })
  69. },
  70. // 获取新开店铺信息
  71. loadNewStores ({ commit }, params = { types: 'ORIGINAL_FACTORY' }) {
  72. commit('storeCms/REQUEST_NEW_STORES')
  73. return axios.get('/api/store-service/stores', {
  74. params: {
  75. filter: 'newStore',
  76. types: params.types
  77. }
  78. }).then(response => {
  79. commit('storeCms/GET_NEW_STORES_SUCCESS', response.data)
  80. }, err => {
  81. commit('storeCms/GET_NEW_STORES_FAILURE', err)
  82. })
  83. },
  84. // 获取原厂推荐信息
  85. loadRecommendOriginal ({ commit }, params = {}) {
  86. commit('storeCms/REQUEST_RECOMMEND_STORE')
  87. return axios.get('/api/store-service/stores/five', { params })
  88. .then(response => {
  89. commit('storeCms/GET_RECOMMEND_STORE_SUCCESS', response.data)
  90. }, err => {
  91. commit('storeCms/GET_RECOMMEND_STORE_FAILURE', err)
  92. })
  93. },
  94. // 获取优秀商家信息
  95. loadRecommendStores ({ commit }, params = {}) {
  96. commit('storeCms/REQUEST_RECOMMEND_STORE')
  97. return axios.get('/api/cms-service/storeIn', { params })
  98. .then(response => {
  99. commit('storeCms/GET_RECOMMEND_STORE_SUCCESS', response.data)
  100. }, err => {
  101. commit('storeCms/GET_RECOMMEND_STORE_FAILURE', err)
  102. })
  103. },
  104. loadHotComponents ({ commit }) {
  105. commit('storeCms/REQUEST_HOT_COMPONENTS')
  106. return axios.get('/api/cms-service/storeCms/inventory')
  107. .then(response => {
  108. commit('storeCms/GET_HOT_COMPONENTS_SUCCESS', response.data)
  109. }, err => {
  110. commit('storeCms/GET_HOT_COMPONENTS_FAILURE', err)
  111. })
  112. },
  113. findStoreList ({ commit }, params = {}) {
  114. params.op = 'pageByType'
  115. commit('stores/REQUEST_STORE_LIST')
  116. return axios.get('/api/store-service/stores', { params })
  117. .then(response => {
  118. commit('stores/GET_STORE_LIST_SUCCESS', response.data)
  119. }, err => {
  120. commit('stores/GET_STORE_LIST_FAILURE', err)
  121. })
  122. },
  123. findSimilarStoreList ({ commit }, params = {}) {
  124. params.op = 'similar'
  125. commit('stores/REQUEST_STORE_LIST')
  126. return axios.get('/api/store-service/stores', { params })
  127. .then(response => {
  128. commit('stores/GET_STORE_LIST_SUCCESS', response.data)
  129. }, err => {
  130. commit('stores/GET_STORE_LIST_FAILURE', err)
  131. })
  132. },
  133. findStoreListInMobil ({ commit }, params = {}) {
  134. params.op = 'similar'
  135. commit('stores/REQUEST_STORE_LIST')
  136. return axios.get('/api/store-service/stores', { params })
  137. .then(response => {
  138. let listData = response.data
  139. let focusData = []
  140. for (let i = 0; i < listData.content.length; i++) {
  141. let str = findStoreFocusInMobil({id: listData.content[i].id})
  142. focusData.push(str)
  143. }
  144. // 合并请求,获取店铺关注信息
  145. return Promise.all(focusData)
  146. .then(result => {
  147. if (result) {
  148. for (let i = 0; i < result.length; i++) {
  149. listData.content[i].isFocus = result[i] ? result[i].data : 'false'
  150. }
  151. }
  152. commit('stores/GET_STORE_LIST_SUCCESS', listData)
  153. }, err => {
  154. console.log(err)
  155. for (let i = 0; i < listData.content.length; i++) {
  156. listData.content[i].isFocus = 'false'
  157. }
  158. commit('stores/GET_STORE_LIST_SUCCESS', listData)
  159. })
  160. }, err => {
  161. commit('stores/GET_STORE_LIST_FAILURE', err)
  162. })
  163. }
  164. }