product.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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, req }) {
  15. // 检查设备类型
  16. const userAgent = process.server ? 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. loadPCBRecommends ({ commit }) {
  37. commit('brand/REQUEST_RECOMMENDS')
  38. return axios.get('/cmsApi?method=queryContentPage&module=brandCenter_brandReco')
  39. .then(response => {
  40. commit('brand/GET_RECOMMENDS_SUCCESS', response.data)
  41. }, err => {
  42. commit('brand/GET_RECOMMENDS_FAILURE', err)
  43. })
  44. },
  45. // 品牌列表配置
  46. loadBrands ({ commit }, params = {}) {
  47. let keyword = params.keyword
  48. commit('brand/REQUEST_BRANDS', params)
  49. return axios.get(`/api/product/brand/initial/${keyword}`)
  50. .then(response => {
  51. commit('brand/GET_BRANDS_SUCCESS', response.data)
  52. }, err => {
  53. commit('brand/GET_BRANDS_FAILURE', err)
  54. })
  55. },
  56. // 品牌列表分页查询(索引)
  57. loadBrandsPager ({ commit }, params = {}) {
  58. commit('brand/REQUEST_BRANDS_PAGER', params)
  59. return axios.get(`/api/product/brand/page/initial`, {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. loadBrandsPagerWithoutIndex ({ commit }, params = {}) {
  68. commit('brand/REQUEST_BRANDS_PAGER', params)
  69. return axios.get(`/api/product/brand/Brand/ByPage`, {params: params})
  70. .then(response => {
  71. commit('brand/GET_BRANDS_PAGER_SUCCESS', response.data)
  72. }, err => {
  73. commit('brand/GET_BRANDS_PAGER_FAILURE', err)
  74. })
  75. },
  76. // 获取全部子器件类目
  77. loadAllProductKinds ({ commit }, params = {}) {
  78. let id = params.id
  79. commit('kind/REQUEST_KIND', params)
  80. return axios.get(`/api/product/kind/${id}/children_all`)
  81. .then(response => {
  82. commit('kind/GET_KIND_SUCCESS', { id, result: response.data })
  83. }, err => {
  84. commit('kind/GET_KIND_FAILURE', {id, err})
  85. })
  86. },
  87. loadKindParentsWithBothers ({ commit }, params = {}) {
  88. let id = params.id
  89. commit('kind/REQUEST_KINDPARENTSWITHBOTHERS', params)
  90. return axios.get(`/api/product/kind/${id}/parentsWithBothers`)
  91. .then(response => {
  92. commit('kind/GET_KINDPARENTSWITHBOTHERS_SUCCESS', response.data)
  93. // if (response.data) {
  94. // if (!response.data[response.data.length - 1].leaf) {
  95. // // commit('kind/REQUEST_CHILDREN')
  96. // // return axios.get(`/api/product/kind/${id}/children`)
  97. // // .then(response => {
  98. // // commit('kind/GET_CHILDREN_SUCCESS', response.data)
  99. // // }, err => {
  100. // // commit('kind/GET_CHILDREN_FAILURE', err)
  101. // // })
  102. // } else {
  103. // // commit('kind/REQUEST_KINDPROPERTY')
  104. // // return axios.get(`/api/product/kind/${id}/properties/values`)
  105. // // .then(response => {
  106. // // commit('kind/GET_KINDPROPERTY_SUCCESS', response.data)
  107. // // }, err => {
  108. // // commit('kind/GET_KINDPROPERTY_FAILURE', err)
  109. // // })
  110. // }
  111. // }
  112. }, err => {
  113. commit('kind/GET_KINDPARENTSWITHBOTHERS_FAILURE', err)
  114. })
  115. },
  116. loadKindFirstChild ({ commit }, params = {}) {
  117. let id = params.id
  118. commit('kind/REQUEST_KINDFIRSTCHILD', params)
  119. return axios.get(`/api/product/kind/${id}/children`)
  120. .then(response => {
  121. commit('kind/GET_KINDFIRSTCHILD_SUCCESS', response.data)
  122. }, err => {
  123. commit('kind/GET_KINDFIRSTCHILD_FAILURE', err)
  124. })
  125. },
  126. loadKindBrands ({ commit }, params = {}) {
  127. let id = params.id
  128. commit('kind/REQUEST_KINDBRANDS')
  129. return axios.get(`/api/product/kind/${id}/brands`)
  130. .then(response => {
  131. commit('kind/GET_KINDBRANDS_SUCCESS', response.data)
  132. }, err => {
  133. commit('kind/GET_KINDBRANDS_FAILURE', err)
  134. })
  135. },
  136. pageComGoods ({ commit }, kindid = '', brandid = '', pageParams = { page: 1, count: 10 }) {
  137. let params = {}
  138. let filter = {kindid: kindid.kindid, brandid: kindid.brandid, properties: kindid.properties}
  139. params.filter = filter
  140. params.page = pageParams.page
  141. params.count = pageParams.count
  142. commit('component/REQUEST_CMPGOODS')
  143. return axios.get('/api/product/product/getCompGoodsByKindid', { params })
  144. .then(response => {
  145. commit('component/GET_CMPGOODS_SUCCESS', response.data)
  146. }, err => {
  147. commit('component/GET_CMPGOODS_FAILURE', err)
  148. })
  149. },
  150. // 保存单个收藏记录
  151. saveEntity ({ commit }, componentid) {
  152. commit('common/REQUEST_COLLECTSAVA')
  153. return axios.post(`/trade/collection/save`, componentid)
  154. .then(response => {
  155. commit('common/GET_COLLECTSAVA_SUCCESS', response.data)
  156. if (response.data === 'success') {
  157. commit('common/GET_COLLECTLIST_SUCCESS')
  158. return Promise.all([
  159. saveStores({ commit })
  160. ])
  161. }
  162. }, err => {
  163. commit('common/GET_COLLECTSAVA_FAILURE', err)
  164. })
  165. },
  166. // 保存一列收藏记录, 此方法仅限于在登陆界面使用
  167. saveStores ({ commit }, params = {}) {
  168. commit('common/REQUEST_COLLECTLIST')
  169. return axios.get(`/trade/collection/list`, { params })
  170. .then(response => {
  171. commit('common/GET_COLLECTLIST_SUCCESS', response.data)
  172. }, err => {
  173. commit('common/GET_COLLECTLIST_FAILURE', err)
  174. })
  175. },
  176. // 保存一列收藏记录, 此方法仅限于在登陆界面使用
  177. getCollectList ({ commit }, params = {}) {
  178. commit('common/REQUEST_COLLECT_LIST')
  179. return axios.get(`/trade/collection/list`, { params })
  180. .then(response => {
  181. commit('common/GET_COLLECT_LIST_SUCCESS', response.data)
  182. }, err => {
  183. commit('common/GET_COLLECT_LIST_FAILURE', err)
  184. })
  185. },
  186. // 供应商维护
  187. loadSupplierInformation ({ commit }, params = {}) {
  188. let uuid = params.uuid
  189. let param = {
  190. page: params.page,
  191. count: params.count
  192. }
  193. commit('supplierInformation/REQUEST_INFORMATION')
  194. return axios.get(`/api/produce/vendorlist/${uuid}`, {params: param})
  195. .then(response => {
  196. commit('supplierInformation/GET_INFORMATION_SUCCESS', response.data)
  197. }, err => {
  198. commit('supplierInformation/GET_INFORMATION_FAILURE', err)
  199. })
  200. },
  201. // 获取用户器件收藏数据
  202. loadCompCollectInfo({ commit }) {
  203. commit('component/REQUEST_COLLECT')
  204. return axios.get('/trade/collection/count', { params: {type: 'component'} })
  205. .then(response => {
  206. commit('component/REQUEST_COLLECT_SUCCESS', response.data)
  207. }, err => {
  208. commit('component/REQUEST_COLLECT_FAILURE', err)
  209. })
  210. },
  211. // 获取用户收藏类目数据
  212. getUserCollectCode({ commit }, params = {}) {
  213. commit('component/REQUEST_COLLECTCODE')
  214. return axios.get('/produce/kindConcern/list', { params: params })
  215. .then(response => {
  216. commit('component/REQUEST_COLLECTCODE_SUCCESS', response.data)
  217. }, err => {
  218. commit('component/REQUEST_COLLECTCODE_FAILURE', err)
  219. })
  220. }
  221. }