index.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. import axios from '~plugins/axios'
  2. // 获取品牌详情产品分类信息
  3. function loadBrandCategories ({commit}, params = {}) {
  4. let id = params.id
  5. commit('brandCategories/REQUEST_CATEGORIES', params)
  6. return axios.get(`/api/product/brand/${id}/kinds`)
  7. .then(response => {
  8. commit('brandCategories/GET_CATEGORIES_SUCCESS', response.data)
  9. }, err => {
  10. commit('brandCategories/GET_CATEGORIES_FAILURE', err)
  11. })
  12. }
  13. // 获取品牌详情型号列表数据
  14. function loadBrandComponent ({commit}, params = {}) {
  15. commit('brandComponent/REQUEST_COMPONENT', params)
  16. return axios.get('/api/product/component/list', { params })
  17. .then(response => {
  18. commit('brandComponent/GET_COMPONENT_SUCCESS', response.data)
  19. }, err => {
  20. commit('brandComponent/GET_COMPONENT_FAILURE', err)
  21. })
  22. }
  23. export const actions = {
  24. // 全局服务初始化
  25. nuxtServerInit (store, { params, route, isDev, isServer, req }) {
  26. // 检查设备类型
  27. const userAgent = isServer ? req.headers['user-agent'] : navigator.userAgent
  28. const isMobile = /(iPhone|iPad|Opera Mini|Android.*Mobile|NetFront|PSP|BlackBerry|Windows Phone)/ig.test(userAgent)
  29. const cookie = isServer ? req.headers['cookie'] : null
  30. store.commit('option/SET_MOBILE_LAYOUT', isMobile)
  31. store.commit('option/SET_USER_AGENT', userAgent)
  32. store.commit('option/SET_COOKIES', cookie)
  33. // 设置跳转的URL
  34. if (!isDev) {
  35. store.commit('option/UPDATE_URL', 'http://www.usoftmall.com')
  36. }
  37. return Promise.all([
  38. // 全局数据
  39. store.dispatch('loadUserInfo'),
  40. store.dispatch('loadProductCounts', { _status: 'actived' }),
  41. store.dispatch('loadHotSearchDevice'),
  42. store.dispatch('loadHotSearchBrand'),
  43. store.dispatch('loadNewFloors')
  44. ])
  45. },
  46. // 获取用户信息
  47. loadUserInfo ({ commit }) {
  48. commit('option/REQUEST_USER_INFO')
  49. return axios.get('/user/authentication')
  50. .then(response => {
  51. if (response.data.userName) {
  52. let ens = response.data.enterprises
  53. if (ens && ens.length) {
  54. response.data.enterprise = ens.find(item => item.current) || {enName: '个人账户'}
  55. } else {
  56. response.data.enterprise = {enName: '个人账户'}
  57. }
  58. }
  59. commit('option/REQUEST_USER_INFO_SUCCESS', response.data)
  60. }, err => {
  61. commit('option/REQUEST_USER_INFO_FAILURE', err)
  62. })
  63. },
  64. // 用户退出
  65. logout ({ commit }) {
  66. return axios.get('/logout')
  67. .then(response => {
  68. commit('option/REQUEST_LOGOUT_SUCCESS', response.data)
  69. })
  70. },
  71. // 获取楼层配置
  72. loadFloors ({ commit }) {
  73. commit('floor/REQUEST_LIST')
  74. return axios.get('/api/floors/home')
  75. .then(response => {
  76. commit('floor/GET_LIST_SUCCESS', response.data)
  77. }, err => {
  78. commit('floor/GET_LIST_FAILURE', err)
  79. })
  80. },
  81. // 批量获取产品信息
  82. loadBatchCommodities ({ commit }, params = {}) {
  83. commit('floor/REQUEST_EXPANDLIST')
  84. return axios.post('/api/commodity/detail', params.batchCodeList)
  85. .then(response => {
  86. commit('floor/GET_EXPANDLIST_SUCCESS', response.data)
  87. }, err => {
  88. commit('floor/GET_EXPANDLIST_FAILURE', err)
  89. })
  90. },
  91. // 获取轮播配置
  92. loadBanners ({ commit }, params = {}) {
  93. commit('carousel/REQUEST_BANNER')
  94. return axios.get('/api/carousel/' + params.type + '%20' + (params.type === 'home' ? 'page' : 'zone') + '%20banner')
  95. .then(response => {
  96. commit('carousel/GET_BANNER_SUCCESS', response.data)
  97. }, err => {
  98. commit('carousel/GET_BANNER_FAILURE', err)
  99. })
  100. },
  101. // 获取新楼层配置
  102. loadNewFloors ({ commit }) {
  103. commit('floor/REQUEST_NEWLIST')
  104. return axios.get('/api/floors/home-v3')
  105. .then(response => {
  106. commit('floor/GET_NEWLIST_SUCCESS', response.data)
  107. }, err => {
  108. commit('floor/GET_NEWLIST_FAILURE', err)
  109. })
  110. },
  111. // 获取子器件类目
  112. loadProductKinds ({ commit }, params = {}) {
  113. let id = params.id
  114. commit('product/kind/REQUEST_KIND', params)
  115. return axios.get(`/api/product/kind/${id}/children`)
  116. .then(response => {
  117. commit('product/kind/GET_KIND_SUCCESS', { id, result: response.data })
  118. }, err => {
  119. commit('product/kind/GET_KIND_FAILURE', {id, err})
  120. })
  121. },
  122. // 获取全部子器件类目
  123. loadAllProductKinds ({ commit }, params = {}) {
  124. let id = params.id
  125. commit('product/kind/REQUEST_KIND', params)
  126. return axios.get(`/api/product/kind/${id}/children_all`)
  127. .then(response => {
  128. commit('product/kind/GET_KIND_SUCCESS', { id, result: response.data })
  129. }, err => {
  130. commit('product/kind/GET_KIND_FAILURE', {id, err})
  131. })
  132. },
  133. // 获取首页新闻
  134. loadNewsSnapshot ({ commit }, params = {}) {
  135. commit('news/REQUEST_SNAPSHOT')
  136. return axios.get('/api/news/created', {params})
  137. .then(response => {
  138. commit('news/GET_SNAPSHOT_SUCCESS', response.data)
  139. }, err => {
  140. commit('news/GET_SNAPSHOT_FAILURE', err)
  141. })
  142. },
  143. // 获取器件统计信息
  144. loadProductCounts ({ commit }, params = {}) {
  145. commit('product/common/REQUEST_COUNTS')
  146. return axios.get('/api/product/commoncount', {params})
  147. .then(response => {
  148. commit('product/common/GET_COUNTS_SUCCESS', response.data)
  149. }, err => {
  150. commit('product/common/GET_COUNTS_FAILURE', err)
  151. })
  152. },
  153. // 搜索关键字
  154. searchKeywords ({ commit }, params = {}) {
  155. commit('search/REQUEST_KEYWORDS')
  156. return axios.get('/search/similarKeywords', {params})
  157. .then(response => {
  158. commit('search/GET_KEYWORDS_SUCCESS', response.data)
  159. }, err => {
  160. commit('search/GET_KEYWORDS_FAILURE', err)
  161. })
  162. },
  163. resetSearchKeywords ({ commit }) {
  164. commit('search/RESET_KEYWORDS')
  165. },
  166. // 热卖推荐页面
  167. loadProductHot ({commit}, params = {}) {
  168. commit('original/REQUEST_HOT')
  169. return axios.get('/api/commodity/latest', {params})
  170. .then(response => {
  171. commit('original/GET_HOT_SUCCESS', response.data)
  172. }, err => {
  173. commit('original/GET_HOT_FAILURE', err)
  174. })
  175. },
  176. // 器件详情页面
  177. // 获得器件详情信息
  178. loadComponentDetail ({commit}, params = {}) {
  179. let id = params.id
  180. commit('componentDetail/REQUEST_DETAIL', params)
  181. return axios.get(`/api/product/component/${id}`)
  182. .then(response => {
  183. commit('componentDetail/GET_DETAIL_SUCCESS', response.data)
  184. if (response.data) {
  185. commit('componentMenu/REQUEST_MENU', params)
  186. return axios.get(`/api/product/kind/structing/${response.data.kindid}`)
  187. .then(response => {
  188. commit('componentMenu/GET_MENU_SUCCESS', response.data)
  189. }, err => {
  190. commit('componentMenu/GET_MENU_FAILURE', err)
  191. })
  192. }
  193. }, err => {
  194. commit('componentDetail/GET_DETAIL_FAILURE', err)
  195. })
  196. },
  197. // 获取器件详情页面包屑导航
  198. loadComponentMenu ({commit}, params = {}) {
  199. let pid = params.id
  200. commit('componentMenu/REQUEST_MENU', params)
  201. return axios.get(`/api/product/kind/structing/${pid}`)
  202. .then(response => {
  203. commit('componentMenu/GET_MENU_SUCCESS', response.data)
  204. }, err => {
  205. commit('componentMenu/GET_MENU_FAILURE', err)
  206. })
  207. },
  208. // 器件详情页选择商家
  209. loadComponentStore ({commit}, params = {}) {
  210. let id = params.uuid
  211. commit('componentStore/REQUEST_STORE', params)
  212. return axios.get(`/api/store-service/stores/uuid/${id}`)
  213. .then(response => {
  214. commit('componentStore/GET_STORE_SUCCESS', response.data)
  215. }, err => {
  216. commit('componentStore/GET_STORE_FAILURE', err)
  217. })
  218. },
  219. // 器件详情页商家列表
  220. loadComponentInformation ({commit}, params = {}) {
  221. // let params = {}
  222. // let filter = {uuid: uuid.uuid, ignoreUMall: false, ignoreStore: false}
  223. // // let sorting = {minPriceRMB: 'ASC'}
  224. // params.filter = filter
  225. // // params.sorting = sorting
  226. // params.page = pageParams.page
  227. // params.count = pageParams.count
  228. commit('componentInformation/REQUEST_INFORMATION')
  229. return axios.get('/api/commodity/goods/page', { params })
  230. .then(response => {
  231. commit('componentInformation/GET_INFORMATION_SUCCESS', response.data)
  232. }, err => {
  233. commit('componentInformation/GET_INFORMATION_FAILURE', err)
  234. })
  235. },
  236. // 获取库存寄售店铺storeid
  237. getUmallStoreId ({commit}) {
  238. commit('componentUmallStoreId/REQUEST_STOREID')
  239. return axios.get('/api/store-service/stores/UmallStore')
  240. .then(response => {
  241. commit('componentUmallStoreId/GET_STOREID_SUCCESS', response.data)
  242. }, err => {
  243. commit('componentUmallStoreId/GET_STOREID_FAILURE', err)
  244. })
  245. },
  246. // 品牌详情页面
  247. // 获得品牌详情信息
  248. loadBrandDetail ({commit, dispatch}, params = {}) {
  249. let id = params.id
  250. commit('brandDetail/REQUEST_DETAIL', params)
  251. return axios.get(`/api/product/brand/${id}`)
  252. .then(response => {
  253. let brand = response.data || {}
  254. commit('brandDetail/GET_DETAIL_SUCCESS', response.data)
  255. return Promise.all([
  256. loadBrandCategories({ commit }, {id: brand.id}),
  257. loadBrandComponent({ commit }, {count: 10, filter: { brandid: brand.id }, page: 1})
  258. ])
  259. }, err => {
  260. commit('brandDetail/GET_DETAIL_FAILURE', err)
  261. })
  262. },
  263. // 获取品牌详情产品分类信息
  264. loadBrandCategories ({commit}, params = {}) {
  265. let id = params.id
  266. commit('brandCategories/REQUEST_CATEGORIES', params)
  267. return axios.get(`/api/product/brand/${id}/kinds`)
  268. .then(response => {
  269. commit('brandCategories/GET_CATEGORIES_SUCCESS', response.data)
  270. }, err => {
  271. commit('brandCategories/GET_CATEGORIES_FAILURE', err)
  272. })
  273. },
  274. // 获取品牌详情型号列表数据
  275. loadBrandComponent ({commit}, params = {}) {
  276. commit('brandComponent/REQUEST_COMPONENT', params)
  277. return axios.get('/api/product/component/list', { params })
  278. .then(response => {
  279. commit('brandComponent/GET_COMPONENT_SUCCESS', response.data)
  280. }, err => {
  281. commit('brandComponent/GET_COMPONENT_FAILURE', err)
  282. })
  283. },
  284. // 获取品牌详情分页信息
  285. loadBrandPages ({commit}, params = {}) {
  286. commit('brandPages/REQUEST_PAGES', params)
  287. return axios.get('/api/product/PAGES/list', { params })
  288. .then(response => {
  289. commit('brandPages/GET__SUCCESS', response.data)
  290. }, err => {
  291. commit('brandPages/GET_COMPONENT_FAILURE', err)
  292. })
  293. },
  294. // 留言板
  295. // 提交了留言板信息
  296. uploadMessageBoardInformation ({commit}, params) {
  297. commit('messageBoard/REQUEST_INFORMATION')
  298. return axios.post('/api/operation/messageBoard', params)
  299. .then(response => {
  300. commit('messageBoard/GET_INFORMATION_SUCCESS', response.data)
  301. }, err => {
  302. commit('messageBoard/GET_INFORMATION_FAILURE', err)
  303. })
  304. },
  305. // 验证用户是否登录
  306. userIsLogin ({commit}) {
  307. commit('messageBoardIsLogin/REQUEST_LOGIN')
  308. return axios.get('/user/authentication')
  309. .then(response => {
  310. commit('messageBoardIsLogin/GET_LOGIN_SUCCESS', response.data)
  311. }, err => {
  312. commit('messageBoardIsLogin/GET_LOGIN_FAILURE', err)
  313. })
  314. },
  315. // 获取留言记录信息
  316. getMessageBoardInformation ({commit}, params) {
  317. let sorting = {createDate: 'DESC'}
  318. params.sorting = sorting
  319. commit('messageBoardInformation/REQUEST_INFORMATION', params)
  320. return axios.get('/operation/messageBoard/pageInfo/user', { params })
  321. .then(response => {
  322. commit('messageBoardInformation/GET_INFORMATION_SUCCESS', response.data)
  323. }, err => {
  324. commit('messageBoardInformation/GET_INFORMATION_FAILURE', err)
  325. })
  326. },
  327. // 获取帮助中心信息
  328. loadHelpSnapsho ({ commit }, params = {}) {
  329. commit('help/REQUEST_SNAPSHO')
  330. return axios.get('/api/help-service/helps', {params})
  331. .then(response => {
  332. commit('help/GET_SNAPSHO_SUCCESS', response.data)
  333. }, err => {
  334. commit('help/GET_SNAPSHO_FAILURE', err)
  335. })
  336. },
  337. // 获取帮助中心二级菜单
  338. loadHelpList ({ commit }, params = {}) {
  339. commit('help/REQUEST_HELPLIST')
  340. return axios.get('/api/help-service/issues', {params})
  341. .then(response => {
  342. commit('help/GET_HELPLIST_SUCCESS', response.data)
  343. }, err => {
  344. commit('help/GET_HELPLIST_FAILURE', err)
  345. })
  346. },
  347. // 获取帮助中心名称
  348. loadHelpTitle ({ commit }, params = {}) {
  349. let id = params.id
  350. commit('help/REQUEST_TITLE')
  351. return axios.get(`/api/help-service/${id}`, {params})
  352. .then(response => {
  353. commit('help/GET_TITLE_SUCCESS', response.data)
  354. }, err => {
  355. commit('help/GET_TITLE_FAILURE', err)
  356. })
  357. },
  358. // 获取详情
  359. loadHelpDetail ({ commit }, params = {}) {
  360. let id = params.id
  361. commit('help/REQUEST_DETAIL')
  362. return axios.get(`/api/help-service/issues/${id}`, {params})
  363. .then(response => {
  364. commit('help/GET_DETAIL_SUCCESS', response.data)
  365. let id = response.data.navId
  366. commit('help/REQUEST_TITLE')
  367. return axios.get(`/api/help-service/${id}`)
  368. .then(response => {
  369. commit('help/GET_TITLE_SUCCESS', response.data)
  370. }, err => {
  371. commit('help/GET_TITLE_FAILURE', err)
  372. })
  373. }, err => {
  374. commit('help/GET_DETAIL_FAILURE', err)
  375. })
  376. },
  377. // 获取最多搜索量的 器件
  378. loadHotSearchDevice ({commit}) {
  379. commit('hotSearchDevice/REQUEST_HOT')
  380. return axios.get('/api/product/component/mostSearchComponent')
  381. .then(response => {
  382. commit('hotSearchDevice/GET_HOT_SUCCESS', response.data)
  383. }, err => {
  384. commit('hotSearchDevice/GET_HOT_FAILURE', err)
  385. })
  386. },
  387. // 获取最多搜索量的 品牌
  388. loadHotSearchBrand ({commit}) {
  389. commit('hotSearchBrand/REQUEST_HOT')
  390. return axios.get('/api/product/brand/mostSearchBrands')
  391. .then(response => {
  392. commit('hotSearchBrand/GET_HOT_SUCCESS', response.data)
  393. }, err => {
  394. commit('hotSearchBrand/GET_HOT_FAILURE', err)
  395. })
  396. },
  397. // 获取最多搜索量的 品牌
  398. loadStoreStatus ({commit}, params = {}) {
  399. commit('option/REQUEST_STORE_STATUS')
  400. return axios.get('/store-service/stores', {params: params})
  401. .then(response => {
  402. commit('option/REQUEST_STORE_STATUS_SUCCESS', response.data)
  403. }, err => {
  404. commit('option/REQUEST_STORE_STATUS_FAILURE', err)
  405. })
  406. }
  407. }