product.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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('/cmsApi?method=queryContentPage&module=brandCenter_brandReco&orderBy=contExp_sort')
  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. loadBrandsPager ({ commit }, params = {}) {
  48. commit('brand/REQUEST_BRANDS_PAGER', params)
  49. return axios.get(`/api/product/brand/page/initial`, {params: params})
  50. .then(response => {
  51. commit('brand/GET_BRANDS_PAGER_SUCCESS', response.data)
  52. }, err => {
  53. commit('brand/GET_BRANDS_PAGER_FAILURE', err)
  54. })
  55. },
  56. // 品牌列表分页查询(搜索)
  57. loadBrandsPagerWithoutIndex ({ commit }, params = {}) {
  58. commit('brand/REQUEST_BRANDS_PAGER', params)
  59. return axios.get(`/api/product/brand/Brand/ByPage`, {params: params})
  60. .then(response => {
  61. commit('brand/GET_BRANDS_PAGER_SUCCESS', response.data)
  62. }, err => {
  63. commit('brand/GET_BRANDS_PAGER_FAILURE', err)
  64. })
  65. },
  66. // 获取全部子器件类目
  67. loadAllProductKinds ({ commit }, params = {}) {
  68. let id = params.id
  69. commit('kind/REQUEST_KIND', params)
  70. return axios.get(`/api/product/kind/${id}/children_all`)
  71. .then(response => {
  72. commit('kind/GET_KIND_SUCCESS', { id, result: response.data })
  73. }, err => {
  74. commit('kind/GET_KIND_FAILURE', {id, err})
  75. })
  76. },
  77. loadKindParentsWithBothers ({ commit }, params = {}) {
  78. let id = params.id
  79. commit('kind/REQUEST_KINDPARENTSWITHBOTHERS', params)
  80. return axios.get(`/api/product/kind/${id}/parentsWithBothers`)
  81. .then(response => {
  82. commit('kind/GET_KINDPARENTSWITHBOTHERS_SUCCESS', response.data)
  83. // if (response.data) {
  84. // if (!response.data[response.data.length - 1].leaf) {
  85. // // commit('kind/REQUEST_CHILDREN')
  86. // // return axios.get(`/api/product/kind/${id}/children`)
  87. // // .then(response => {
  88. // // commit('kind/GET_CHILDREN_SUCCESS', response.data)
  89. // // }, err => {
  90. // // commit('kind/GET_CHILDREN_FAILURE', err)
  91. // // })
  92. // } else {
  93. // // commit('kind/REQUEST_KINDPROPERTY')
  94. // // return axios.get(`/api/product/kind/${id}/properties/values`)
  95. // // .then(response => {
  96. // // commit('kind/GET_KINDPROPERTY_SUCCESS', response.data)
  97. // // }, err => {
  98. // // commit('kind/GET_KINDPROPERTY_FAILURE', err)
  99. // // })
  100. // }
  101. // }
  102. }, err => {
  103. commit('kind/GET_KINDPARENTSWITHBOTHERS_FAILURE', err)
  104. })
  105. },
  106. loadKindBrands ({ commit }, params = {}) {
  107. let id = params.id
  108. commit('kind/REQUEST_KINDBRANDS')
  109. return axios.get(`/api/product/kind/${id}/brands`)
  110. .then(response => {
  111. commit('kind/GET_KINDBRANDS_SUCCESS', response.data)
  112. }, err => {
  113. commit('kind/GET_KINDBRANDS_FAILURE', err)
  114. })
  115. },
  116. pageComGoods ({ commit }, kindid = '', brandid = '', pageParams = { page: 1, count: 10 }) {
  117. let params = {}
  118. let filter = {kindid: kindid.kindid, brandid: kindid.brandid, properties: kindid.properties}
  119. params.filter = filter
  120. params.page = pageParams.page
  121. params.count = pageParams.count
  122. commit('component/REQUEST_CMPGOODS')
  123. return axios.get('/api/product/product/getCompGoodsByKindid', { params })
  124. .then(response => {
  125. commit('component/GET_CMPGOODS_SUCCESS', response.data)
  126. }, err => {
  127. commit('component/GET_CMPGOODS_FAILURE', err)
  128. })
  129. },
  130. // 保存单个收藏记录
  131. saveEntity ({ commit }, componentid) {
  132. commit('common/REQUEST_COLLECTSAVA')
  133. return axios.post(`/trade/collection/save`, componentid)
  134. .then(response => {
  135. commit('common/GET_COLLECTSAVA_SUCCESS', response.data)
  136. if (response.data === 'success') {
  137. commit('common/GET_COLLECTLIST_SUCCESS')
  138. return Promise.all([
  139. saveStores({ commit })
  140. ])
  141. }
  142. }, err => {
  143. commit('common/GET_COLLECTSAVA_FAILURE', err)
  144. })
  145. },
  146. // 保存一列收藏记录, 此方法仅限于在登陆界面使用
  147. saveStores ({ commit }, params = {}) {
  148. commit('common/REQUEST_COLLECTLIST')
  149. return axios.get(`/trade/collection/list`, { params })
  150. .then(response => {
  151. commit('common/GET_COLLECTLIST_SUCCESS', response.data)
  152. }, err => {
  153. commit('common/GET_COLLECTLIST_FAILURE', err)
  154. })
  155. },
  156. // 保存一列收藏记录, 此方法仅限于在登陆界面使用
  157. getCollectList ({ commit }, params = {}) {
  158. commit('common/REQUEST_COLLECT_LIST')
  159. return axios.get(`/trade/collection/list`, { params })
  160. .then(response => {
  161. commit('common/GET_COLLECT_LIST_SUCCESS', response.data)
  162. }, err => {
  163. commit('common/GET_COLLECT_LIST_FAILURE', err)
  164. })
  165. },
  166. // 供应商维护
  167. loadSupplierInformation ({ commit }, params = {}) {
  168. let uuid = params.uuid
  169. let param = {
  170. page: params.page,
  171. count: params.count
  172. }
  173. commit('supplierInformation/REQUEST_INFORMATION')
  174. return axios.get(`/api/produce/vendorlist/${uuid}`, {params: param})
  175. .then(response => {
  176. commit('supplierInformation/GET_INFORMATION_SUCCESS', response.data)
  177. }, err => {
  178. commit('supplierInformation/GET_INFORMATION_FAILURE', err)
  179. })
  180. },
  181. // 获取用户器件收藏数据
  182. loadCompCollectInfo({ commit }) {
  183. commit('component/REQUEST_COLLECT')
  184. return axios.get('/trade/collection/count', { params: {type: 'component'} })
  185. .then(response => {
  186. commit('component/REQUEST_COLLECT_SUCCESS', response.data)
  187. }, err => {
  188. commit('component/REQUEST_COLLECT_FAILURE', err)
  189. })
  190. }
  191. }