provider.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. size: params.size
  78. }
  79. }).then(response => {
  80. commit('storeCms/GET_NEW_STORES_SUCCESS', response.data)
  81. }, err => {
  82. commit('storeCms/GET_NEW_STORES_FAILURE', err)
  83. })
  84. },
  85. // 获取原厂推荐信息
  86. loadRecommendOriginal ({ commit }, params = {}) {
  87. commit('storeCms/REQUEST_RECOMMEND_STORE')
  88. return axios.get('/api/store-service/stores/five', { params })
  89. .then(response => {
  90. commit('storeCms/GET_RECOMMEND_STORE_SUCCESS', response.data)
  91. }, err => {
  92. commit('storeCms/GET_RECOMMEND_STORE_FAILURE', err)
  93. })
  94. },
  95. // 获取优秀商家信息
  96. loadRecommendStores ({ commit }, params = {}) {
  97. commit('storeCms/REQUEST_RECOMMEND_STORE')
  98. return axios.get('/api/cms-service/storeIn', { params })
  99. .then(response => {
  100. commit('storeCms/GET_RECOMMEND_STORE_SUCCESS', response.data)
  101. }, err => {
  102. commit('storeCms/GET_RECOMMEND_STORE_FAILURE', err)
  103. })
  104. },
  105. loadHotComponents ({ commit }) {
  106. commit('storeCms/REQUEST_HOT_COMPONENTS')
  107. return axios.get('/cmsApi?method=queryContentPage&module=recommended&orderBy=order_number%20ASC')
  108. .then(response => {
  109. commit('storeCms/GET_HOT_COMPONENTS_SUCCESS', response.data)
  110. }, err => {
  111. commit('storeCms/GET_HOT_COMPONENTS_FAILURE', err)
  112. })
  113. },
  114. findStoreList ({ commit }, params = {}) {
  115. params.op = 'pageByType'
  116. commit('stores/REQUEST_STORE_LIST')
  117. return axios.get('/api/store-service/stores', { params })
  118. .then(response => {
  119. commit('stores/GET_STORE_LIST_SUCCESS', response.data)
  120. }, err => {
  121. commit('stores/GET_STORE_LIST_FAILURE', err)
  122. })
  123. },
  124. findSimilarStoreList ({ commit }, params = {}) {
  125. params.op = 'similar'
  126. commit('stores/REQUEST_STORE_LIST')
  127. return axios.get('/api/store-service/stores', { params })
  128. .then(response => {
  129. commit('stores/GET_STORE_LIST_SUCCESS', response.data)
  130. }, err => {
  131. commit('stores/GET_STORE_LIST_FAILURE', err)
  132. })
  133. },
  134. findStoreListInMobil ({ commit }, params = {}) {
  135. params.op = 'similar'
  136. commit('stores/REQUEST_STORE_LIST')
  137. return axios.get('/api/store-service/stores', { params })
  138. .then(response => {
  139. let listData = response.data
  140. let focusData = []
  141. for (let i = 0; i < listData.content.length; i++) {
  142. let str = findStoreFocusInMobil({id: listData.content[i].id})
  143. focusData.push(str)
  144. }
  145. // 合并请求,获取店铺关注信息
  146. return Promise.all(focusData)
  147. .then(result => {
  148. if (result) {
  149. for (let i = 0; i < result.length; i++) {
  150. listData.content[i].isFocus = result[i] ? result[i].data : 'false'
  151. }
  152. }
  153. commit('stores/GET_STORE_LIST_SUCCESS', listData)
  154. }, err => {
  155. console.log(err)
  156. for (let i = 0; i < listData.content.length; i++) {
  157. listData.content[i].isFocus = 'false'
  158. }
  159. commit('stores/GET_STORE_LIST_SUCCESS', listData)
  160. })
  161. }, err => {
  162. commit('stores/GET_STORE_LIST_FAILURE', err)
  163. })
  164. }
  165. }