product.js 7.2 KB

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