product.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. import axios from '~/plugins/axios'
  2. // 保存一列收藏记录, 此方法仅限于在登陆界面使用
  3. function saveStores ({ commit }, params = {}) {
  4. commit('common/REQUEST_COLLECTLIST')
  5. return axios.get(`trade/collection/list`, { params })
  6. .then(response => {
  7. commit('common/GET_COLLECTLIST_SUCCESS', response.data)
  8. }, err => {
  9. commit('common/GET_COLLECTLIST_FAILURE', err)
  10. })
  11. }
  12. export const actions = {
  13. // 全局服务初始化
  14. nuxtServerInit (store, { params, route, isServer, req }) {
  15. // 检查设备类型
  16. const userAgent = isServer ? req.headers['user-agent'] : navigator.userAgent
  17. const isMobile = /(iPhone|iPod|Opera Mini|Android.*Mobile|NetFront|PSP|BlackBerry|Windows Phone)/ig.test(userAgent)
  18. store.commit('option/SET_MOBILE_LAYOUT', isMobile)
  19. store.commit('option/SET_USER_AGENT', userAgent)
  20. return Promise.all([
  21. // 全局数据
  22. // store.dispatch('loadUserInfo')
  23. ])
  24. },
  25. // 品牌列表推荐品牌配置
  26. loadRecommends ({ commit }) {
  27. commit('brand/REQUEST_RECOMMENDS')
  28. return axios.get(`/api/product/brand/hot/5`)
  29. .then(response => {
  30. commit('brand/GET_RECOMMENDS_SUCCESS', response.data)
  31. }, err => {
  32. commit('brand/GET_RECOMMENDS_FAILURE', err)
  33. })
  34. },
  35. // 品牌列表配置
  36. loadBrands ({ commit }, params = {}) {
  37. let keyword = params.keyword
  38. commit('brand/REQUEST_BRANDS', params)
  39. return axios.get(`/api/product/brand/initial/${keyword}`)
  40. .then(response => {
  41. commit('brand/GET_BRANDS_SUCCESS', response.data)
  42. }, err => {
  43. commit('brand/GET_BRANDS_FAILURE', err)
  44. })
  45. },
  46. // 获取全部子器件类目
  47. loadAllProductKinds ({ commit }, params = {}) {
  48. let id = params.id
  49. commit('kind/REQUEST_KIND', params)
  50. return axios.get(`/api/product/kind/${id}/children_all`)
  51. .then(response => {
  52. commit('kind/GET_KIND_SUCCESS', { id, result: response.data })
  53. }, err => {
  54. commit('kind/GET_KIND_FAILURE', {id, err})
  55. })
  56. },
  57. loadKindParentsWithBothers ({ commit }, params = {}) {
  58. let id = params.id
  59. commit('kind/REQUEST_KINDPARENTSWITHBOTHERS', params)
  60. return axios.get(`/api/product/kind/${id}/parentsWithBothers`)
  61. .then(response => {
  62. commit('kind/GET_KINDPARENTSWITHBOTHERS_SUCCESS', response.data)
  63. if (response.data) {
  64. if (!response.data[response.data.length - 1].leaf) {
  65. commit('kind/REQUEST_CHILDREN')
  66. return axios.get(`/api/product/kind/${id}/children`)
  67. .then(response => {
  68. commit('kind/GET_CHILDREN_SUCCESS', response.data)
  69. }, err => {
  70. commit('kind/GET_CHILDREN_FAILURE', err)
  71. })
  72. } else {
  73. commit('kind/REQUEST_KINDPROPERTY')
  74. return axios.get(`/api/product/kind/${id}/properties/values`)
  75. .then(response => {
  76. commit('kind/GET_KINDPROPERTY_SUCCESS', response.data)
  77. }, err => {
  78. commit('kind/GET_KINDPROPERTY_FAILURE', err)
  79. })
  80. }
  81. }
  82. }, err => {
  83. commit('kind/GET_KINDPARENTSWITHBOTHERS_FAILURE', err)
  84. })
  85. },
  86. loadKindBrands ({ commit }, params = {}) {
  87. let id = params.id
  88. commit('kind/REQUEST_KINDBRANDS')
  89. return axios.get(`/api/product/kind/${id}/brands`)
  90. .then(response => {
  91. commit('kind/GET_KINDBRANDS_SUCCESS', response.data)
  92. }, err => {
  93. commit('kind/GET_KINDBRANDS_FAILURE', err)
  94. })
  95. },
  96. pageComGoods ({ commit }, kindid = '', brandid = '', pageParams = { page: 1, count: 10 }) {
  97. let params = {}
  98. let filter = {kindid: kindid.kindid, brandid: kindid.brandid, properties: kindid.properties}
  99. params.filter = filter
  100. params.page = pageParams.page
  101. params.count = pageParams.count
  102. commit('component/REQUEST_CMPGOODS')
  103. return axios.get('/api/product/product/getCompGoodsByKindid', { params })
  104. .then(response => {
  105. commit('component/GET_CMPGOODS_SUCCESS', response.data)
  106. }, err => {
  107. commit('component/GET_CMPGOODS_FAILURE', err)
  108. })
  109. },
  110. // 保存单个收藏记录
  111. saveEntity ({ commit }, componentid) {
  112. commit('common/REQUEST_COLLECTSAVA')
  113. return axios.post(`/trade/collection/save`, componentid)
  114. .then(response => {
  115. commit('common/GET_COLLECTSAVA_SUCCESS', response.data)
  116. if (response.data === 'success') {
  117. commit('common/GET_COLLECTLIST_SUCCESS')
  118. return Promise.all([
  119. saveStores({ commit })
  120. ])
  121. }
  122. }, err => {
  123. commit('common/GET_COLLECTSAVA_FAILURE', err)
  124. })
  125. },
  126. // 保存一列收藏记录, 此方法仅限于在登陆界面使用
  127. saveStores ({ commit }, params = {}) {
  128. commit('common/REQUEST_COLLECTLIST')
  129. return axios.get(`trade/collection/list`, { params })
  130. .then(response => {
  131. commit('common/GET_COLLECTLIST_SUCCESS', response.data)
  132. }, err => {
  133. commit('common/GET_COLLECTLIST_FAILURE', err)
  134. })
  135. }
  136. }