provider.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. export const actions = {
  11. // 获取销售排行榜信息
  12. loadSalesStore ({ commit }, params = {isOriginal: false}) {
  13. commit('storeCms/REQUEST_SALES')
  14. return axios.get('/api/store-service/stores', {
  15. params: {
  16. filter: 'topBySales',
  17. isOriginal: params.isOriginal
  18. }
  19. }).then(response => {
  20. let stores = response.data || []
  21. let orderCounts = []
  22. for (let i = 0; i < stores.length; i++) {
  23. orderCounts.push(countStoreOrderCount(stores[i]))
  24. }
  25. // 合并请求,获取店铺的交易量数据
  26. return Promise.all(orderCounts)
  27. .then(result => {
  28. if (result) {
  29. for (let i = 0; i < result.length; i++) {
  30. stores[i].orderCount = result[i].data ? result[i].data.orderCount : 0
  31. }
  32. }
  33. commit('storeCms/GET_SALES_SUCCESS', stores)
  34. }, err => {
  35. commit('storeCms/GET_SALES_FAILURE', err)
  36. })
  37. }, err => {
  38. commit('storeCms/GET_SALES_FAILURE', err)
  39. })
  40. },
  41. // 获取新开店铺信息
  42. loadNewStores ({ commit }, params = { types: 'ORIGINAL_FACTORY' }) {
  43. commit('storeCms/REQUEST_NEW_STORES')
  44. return axios.get('/api/store-service/stores', {
  45. params: {
  46. filter: 'newStore',
  47. types: params.types
  48. }
  49. }).then(response => {
  50. commit('storeCms/GET_NEW_STORES_SUCCESS', response.data)
  51. commit('storeCms/REQUEST_STORE_COUNT')
  52. return axios.get('/api/store-service/stores/type/count', {
  53. params: {
  54. types: params.types
  55. }
  56. }).then(response => {
  57. commit('storeCms/GET_STORE_COUNT_SUCCESS', response.data && response.data.success ? response.data.data : 0)
  58. }, err => {
  59. commit('storeCms/GET_STORE_COUNT_FAILURE', err)
  60. })
  61. }, err => {
  62. commit('storeCms/GET_NEW_STORES_FAILURE', err)
  63. })
  64. },
  65. // 获取原厂推荐信息
  66. loadRecommendOriginal ({ commit }) {
  67. let params = { type: 'ORIGINAL_FACTORY' }
  68. commit('storeCms/REQUEST_RECOMMEND_STORE')
  69. return axios.get('/api/store-cms/contents/store/5', {
  70. params: params
  71. }).then(response => {
  72. commit('storeCms/GET_RECOMMEND_STORE_SUCCESS', response.data)
  73. }, err => {
  74. commit('storeCms/GET_RECOMMEND_STORE_FAILURE', err)
  75. })
  76. }
  77. // 获取优秀商家信息
  78. // loadRecommendStores ({ commit }) {
  79. // commit('storeCms/REQUEST_RECOMMEND_STORE')
  80. // return axios.get('/api/cms-service/storeIn/5')
  81. // .then(response => {
  82. // commit('storeCms/GET_RECOMMEND_STORE_SUCCESS', response.data)
  83. // }, err => {
  84. // commit('storeCms/GET_RECOMMEND_STORE_FAILURE', err)
  85. // })
  86. // },
  87. // loadHotComponents ({ commit }) {
  88. // commit('storeCms/REQUEST_HOT_COMPONENTS')
  89. // return axios.get('/api/cms-service/storeCms/inventory')
  90. // .then(response => {
  91. // commit('storeCms/GET_HOT_COMPONENTS_SUCCESS', response.data)
  92. // }, err => {
  93. // commit('storeCms/GET_HOT_COMPONENTS_FAILURE', err)
  94. // })
  95. // },
  96. // findStoreList ({ commit }, params = {}) {
  97. // params.op = 'pageByType'
  98. // commit('stores/REQUEST_STORE_LIST')
  99. // return axios.get('/api/store-service/stores', { params })
  100. // .then(response => {
  101. // commit('stores/GET_STORE_LIST_SUCCESS', response.data)
  102. // }, err => {
  103. // commit('stores/GET_STORE_LIST_FAILURE', err)
  104. // })
  105. // }
  106. }