index.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  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, req }) {
  26. // 检查设备类型
  27. const userAgent = process.server ? 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 = process.server ? 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. // console.log(req.headers.referer)
  34. if (route.query) {
  35. let messageType = route.query.messageType || ''
  36. store.commit('option/GET_MESSAGETYPE', messageType)
  37. }
  38. if (cookie) {
  39. if (cookie && cookie.length) {
  40. for (let i = 0; i < cookie.length; i++) {
  41. if (cookie[i].indexOf('JSESSIONID') > -1) {
  42. const sessionId = cookie[i]
  43. const first = sessionId.indexOf(';')
  44. const second = sessionId.lastIndexOf(';')
  45. const newSessionId = sessionId.replace(sessionId.substring(first, second), '')
  46. store.commit('option/SET_SESSION_ID', newSessionId)
  47. break
  48. }
  49. }
  50. }
  51. axios.defaults.headers['cookie'] = store.state.option.cookies + '; ' + store.state.option.sessionId
  52. axios.defaults.headers['User-Agent'] = store.state.option.userAgent
  53. } else {
  54. axios.defaults.headers['cookie'] = ''
  55. axios.defaults.headers['User-Agent'] = ''
  56. }
  57. // 设置跳转的URL
  58. if (!isDev) {
  59. store.commit('option/UPDATE_URL', 'http://www.usoftmall.com')
  60. }
  61. return Promise.all([
  62. // 全局数据
  63. store.dispatch('loadUserInfo'),
  64. store.dispatch('loadProductCounts', { _status: 'actived' }),
  65. store.dispatch('loadHotSearchDevice'),
  66. store.dispatch('loadHotSearchBrand'),
  67. store.dispatch('loadNewFloors')
  68. ])
  69. },
  70. // 获取用户信息
  71. loadUserInfo({ commit }) {
  72. commit('option/REQUEST_USER_INFO')
  73. return axios.get('/user/authentication')
  74. .then(response => {
  75. if (response.data.userName) {
  76. let ens = response.data.enterprises
  77. if (ens && ens.length) {
  78. response.data.enterprise = ens.find(item => item.current) || { enName: '个人账户' }
  79. } else {
  80. response.data.enterprise = { enName: '个人账户' }
  81. }
  82. }
  83. commit('option/REQUEST_USER_INFO_SUCCESS', response.data)
  84. }, err => {
  85. commit('option/REQUEST_USER_INFO_FAILURE', err)
  86. })
  87. },
  88. loadUserWithAdmin ({commit}, params = {}) {
  89. commit('option/REQUEST_ADMIN_INFO')
  90. return axios.get('/basic/user/getUserByUU', {params: params})
  91. .then(response => {
  92. commit('option/REQUEST_ADMIN_INFO_SUCCESS', response.data)
  93. }, err => {
  94. commit('option/REQUEST_ADMIN_INFO_FAILURE', err)
  95. })
  96. },
  97. // 用户退出
  98. logout({ commit }) {
  99. return axios.get('/logout')
  100. .then(response => {
  101. commit('option/REQUEST_LOGOUT_SUCCESS', response.data)
  102. })
  103. },
  104. // 获取楼层配置
  105. loadFloors({ commit }) {
  106. commit('floor/REQUEST_LIST')
  107. return axios.get('/api/floors/home')
  108. .then(response => {
  109. commit('floor/GET_LIST_SUCCESS', response.data)
  110. }, err => {
  111. commit('floor/GET_LIST_FAILURE', err)
  112. })
  113. },
  114. // 批量获取产品信息
  115. loadBatchCommodities({ commit }, params = {}) {
  116. commit('floor/REQUEST_EXPANDLIST')
  117. return axios.post('/api/commodity/detail', params.batchCodeList)
  118. .then(response => {
  119. commit('floor/GET_EXPANDLIST_SUCCESS', response.data)
  120. }, err => {
  121. commit('floor/GET_EXPANDLIST_FAILURE', err)
  122. })
  123. },
  124. // 获取轮播配置
  125. loadBanners({ commit }, params = {}) {
  126. commit('carousel/REQUEST_BANNER')
  127. return axios.get('/api/carousel/' + params.type + '%20' + (params.type === 'home' ? 'page' : 'zone') + '%20banner')
  128. .then(response => {
  129. commit('carousel/GET_BANNER_SUCCESS', response.data)
  130. }, err => {
  131. commit('carousel/GET_BANNER_FAILURE', err)
  132. })
  133. },
  134. // 获取新楼层配置
  135. loadNewFloors({ commit }) {
  136. commit('floor/REQUEST_NEWLIST')
  137. return axios.get('/api/floors/home-v3')
  138. .then(response => {
  139. commit('floor/GET_NEWLIST_SUCCESS', response.data)
  140. }, err => {
  141. commit('floor/GET_NEWLIST_FAILURE', err)
  142. })
  143. },
  144. // 获取子器件类目
  145. loadProductKinds({ commit }, params = {}) {
  146. let id = params.id
  147. commit('product/kind/REQUEST_KIND', params)
  148. return axios.get(`/api/product/kind/${id}/children`)
  149. .then(response => {
  150. commit('product/kind/GET_KIND_SUCCESS', { id, result: response.data })
  151. }, err => {
  152. commit('product/kind/GET_KIND_FAILURE', { id, err })
  153. })
  154. },
  155. // 获取全部子器件类目
  156. loadAllProductKinds({ commit }, params = {}) {
  157. let id = params.id
  158. commit('product/kind/REQUEST_KIND', params)
  159. return axios.get(`/api/product/kind/${id}/children_all`)
  160. .then(response => {
  161. commit('product/kind/GET_KIND_SUCCESS', { id, result: response.data })
  162. }, err => {
  163. commit('product/kind/GET_KIND_FAILURE', { id, err })
  164. })
  165. },
  166. // 获取首页新闻
  167. loadNewsSnapshot({ commit }, params = {}) {
  168. commit('news/REQUEST_SNAPSHOT')
  169. return axios.get('/api/news/created', { params })
  170. .then(response => {
  171. commit('news/GET_SNAPSHOT_SUCCESS', response.data)
  172. }, err => {
  173. commit('news/GET_SNAPSHOT_FAILURE', err)
  174. })
  175. },
  176. // 获取器件统计信息
  177. loadProductCounts({ commit }, params = {}) {
  178. commit('product/common/REQUEST_COUNTS')
  179. return axios.get('/api/product/commoncount', { params })
  180. .then(response => {
  181. commit('product/common/GET_COUNTS_SUCCESS', response.data)
  182. }, err => {
  183. commit('product/common/GET_COUNTS_FAILURE', err)
  184. })
  185. },
  186. // 搜索关键字
  187. searchKeywords({ commit }, params = {}) {
  188. commit('search/REQUEST_KEYWORDS')
  189. return axios.get('/search/similarKeywords', { params })
  190. .then(response => {
  191. commit('search/GET_KEYWORDS_SUCCESS', response.data)
  192. }, err => {
  193. commit('search/GET_KEYWORDS_FAILURE', err)
  194. })
  195. },
  196. resetSearchKeywords({ commit }) {
  197. commit('search/RESET_KEYWORDS')
  198. },
  199. // 热卖推荐页面
  200. loadProductHot({ commit }, params = {}) {
  201. commit('original/REQUEST_HOT')
  202. return axios.get('/api/commodity/latest', { params })
  203. .then(response => {
  204. commit('original/GET_HOT_SUCCESS', response.data)
  205. }, err => {
  206. commit('original/GET_HOT_FAILURE', err)
  207. })
  208. },
  209. // 器件详情页面
  210. // 获得器件详情信息
  211. loadComponentDetail({ commit }, params = {}) {
  212. let id = params.id
  213. commit('componentDetail/REQUEST_DETAIL', params)
  214. return axios.get(`/api/product/component/${id}`)
  215. .then(response => {
  216. commit('componentDetail/GET_DETAIL_SUCCESS', response.data)
  217. if (response.data) {
  218. commit('componentMenu/REQUEST_MENU', params)
  219. return axios.get(`/api/product/kind/structing/${response.data.kindid}`)
  220. .then(response => {
  221. commit('componentMenu/GET_MENU_SUCCESS', response.data)
  222. }, err => {
  223. commit('componentMenu/GET_MENU_FAILURE', err)
  224. })
  225. }
  226. }, err => {
  227. commit('componentDetail/GET_DETAIL_FAILURE', err)
  228. })
  229. },
  230. // 获取器件详情页面包屑导航
  231. loadComponentMenu({ commit }, params = {}) {
  232. let pid = params.id
  233. commit('componentMenu/REQUEST_MENU', params)
  234. return axios.get(`/api/product/kind/structing/${pid}`)
  235. .then(response => {
  236. commit('componentMenu/GET_MENU_SUCCESS', response.data)
  237. }, err => {
  238. commit('componentMenu/GET_MENU_FAILURE', err)
  239. })
  240. },
  241. // 器件详情页选择商家
  242. loadComponentStore({ commit }, params = {}) {
  243. let id = params.uuid
  244. commit('componentStore/REQUEST_STORE', params)
  245. return axios.get(`/api/store-service/stores/uuid/${id}`)
  246. .then(response => {
  247. commit('componentStore/GET_STORE_SUCCESS', response.data)
  248. }, err => {
  249. commit('componentStore/GET_STORE_FAILURE', err)
  250. })
  251. },
  252. // 器件详情页商家列表
  253. loadComponentInformation({ commit }, params = {}) {
  254. // let params = {}
  255. // let filter = {uuid: uuid.uuid, ignoreUMall: false, ignoreStore: false}
  256. // // let sorting = {minPriceRMB: 'ASC'}
  257. // params.filter = filter
  258. // // params.sorting = sorting
  259. // params.page = pageParams.page
  260. // params.count = pageParams.count
  261. commit('componentInformation/REQUEST_INFORMATION')
  262. return axios.get('/api/commodity/goods/page', { params })
  263. .then(response => {
  264. commit('componentInformation/GET_INFORMATION_SUCCESS', response.data)
  265. }, err => {
  266. commit('componentInformation/GET_INFORMATION_FAILURE', err)
  267. })
  268. },
  269. // 获取库存寄售店铺storeid
  270. getUmallStoreId({ commit }) {
  271. commit('componentUmallStoreId/REQUEST_STOREID')
  272. return axios.get('/api/store-service/stores/UmallStore')
  273. .then(response => {
  274. commit('componentUmallStoreId/GET_STOREID_SUCCESS', response.data)
  275. }, err => {
  276. commit('componentUmallStoreId/GET_STOREID_FAILURE', err)
  277. })
  278. },
  279. // 品牌详情页面
  280. // 获得品牌详情信息
  281. loadBrandDetail({ commit, dispatch }, params = {}) {
  282. let id = params.id
  283. commit('brandDetail/REQUEST_DETAIL', params)
  284. return axios.get(`/api/product/brand/${id}`)
  285. .then(response => {
  286. let brand = response.data || {}
  287. commit('brandDetail/GET_DETAIL_SUCCESS', response.data)
  288. return Promise.all([
  289. loadBrandCategories({ commit }, { id: brand.id }),
  290. loadBrandComponent({ commit }, { count: 10, filter: { brandid: brand.id }, page: 1 })
  291. ])
  292. }, err => {
  293. commit('brandDetail/GET_DETAIL_FAILURE', err)
  294. })
  295. },
  296. // 获取品牌详情产品分类信息
  297. loadBrandCategories({ commit }, params = {}) {
  298. let id = params.id
  299. commit('brandCategories/REQUEST_CATEGORIES', params)
  300. return axios.get(`/api/product/brand/${id}/kinds`)
  301. .then(response => {
  302. commit('brandCategories/GET_CATEGORIES_SUCCESS', response.data)
  303. }, err => {
  304. commit('brandCategories/GET_CATEGORIES_FAILURE', err)
  305. })
  306. },
  307. // 获取品牌详情型号列表数据
  308. loadBrandComponent({ commit }, params = {}) {
  309. commit('brandComponent/REQUEST_COMPONENT', params)
  310. return axios.get('/api/product/component/list', { params })
  311. .then(response => {
  312. commit('brandComponent/GET_COMPONENT_SUCCESS', response.data)
  313. }, err => {
  314. commit('brandComponent/GET_COMPONENT_FAILURE', err)
  315. })
  316. },
  317. // 获取品牌详情分页信息
  318. loadBrandPages({ commit }, params = {}) {
  319. commit('brandPages/REQUEST_PAGES', params)
  320. return axios.get('/api/product/PAGES/list', { params })
  321. .then(response => {
  322. commit('brandPages/GET__SUCCESS', response.data)
  323. }, err => {
  324. commit('brandPages/GET_COMPONENT_FAILURE', err)
  325. })
  326. },
  327. // 留言板
  328. // 提交了留言板信息
  329. uploadMessageBoardInformation({ commit }, params) {
  330. commit('messageBoard/REQUEST_INFORMATION')
  331. return axios.post('/api/operation/messageBoard', params)
  332. .then(response => {
  333. commit('messageBoard/GET_INFORMATION_SUCCESS', response.data)
  334. }, err => {
  335. commit('messageBoard/GET_INFORMATION_FAILURE', err)
  336. })
  337. },
  338. // 验证用户是否登录
  339. userIsLogin({ commit }) {
  340. commit('messageBoardIsLogin/REQUEST_LOGIN')
  341. return axios.get('/user/authentication')
  342. .then(response => {
  343. commit('messageBoardIsLogin/GET_LOGIN_SUCCESS', response.data)
  344. }, err => {
  345. commit('messageBoardIsLogin/GET_LOGIN_FAILURE', err)
  346. })
  347. },
  348. // 获取留言记录信息
  349. getMessageBoardInformation({ commit }, params) {
  350. let sorting = { createDate: 'DESC' }
  351. params.sorting = sorting
  352. commit('messageBoardInformation/REQUEST_INFORMATION', params)
  353. return axios.get('/operation/messageBoard/pageInfo/user', { params })
  354. .then(response => {
  355. commit('messageBoardInformation/GET_INFORMATION_SUCCESS', response.data)
  356. }, err => {
  357. commit('messageBoardInformation/GET_INFORMATION_FAILURE', err)
  358. })
  359. },
  360. // 获取帮助中心信息
  361. loadHelpSnapsho({ commit }, params = {}) {
  362. commit('help/REQUEST_SNAPSHO')
  363. return axios.get('/api/help-service/helps', { params })
  364. .then(response => {
  365. commit('help/GET_SNAPSHO_SUCCESS', response.data)
  366. }, err => {
  367. commit('help/GET_SNAPSHO_FAILURE', err)
  368. })
  369. },
  370. // 获取帮助中心二级菜单
  371. loadHelpList({ commit }, params = {}) {
  372. commit('help/REQUEST_HELPLIST')
  373. return axios.get('/api/help-service/issues', { params })
  374. .then(response => {
  375. commit('help/GET_HELPLIST_SUCCESS', response.data)
  376. }, err => {
  377. commit('help/GET_HELPLIST_FAILURE', err)
  378. })
  379. },
  380. // 获取帮助中心名称
  381. loadHelpTitle({ commit }, params = {}) {
  382. let id = params.id
  383. commit('help/REQUEST_TITLE')
  384. return axios.get(`/api/help-service/${id}`, { params })
  385. .then(response => {
  386. commit('help/GET_TITLE_SUCCESS', response.data)
  387. }, err => {
  388. commit('help/GET_TITLE_FAILURE', err)
  389. })
  390. },
  391. // 获取详情
  392. loadHelpDetail({ commit }, params = {}) {
  393. let id = params.id
  394. commit('help/REQUEST_DETAIL')
  395. return axios.get(`/api/help-service/issues/${id}`, { params })
  396. .then(response => {
  397. commit('help/GET_DETAIL_SUCCESS', response.data)
  398. let id = response.data.navId
  399. commit('help/REQUEST_TITLE')
  400. return axios.get(`/api/help-service/${id}`)
  401. .then(response => {
  402. commit('help/GET_TITLE_SUCCESS', response.data)
  403. }, err => {
  404. commit('help/GET_TITLE_FAILURE', err)
  405. })
  406. }, err => {
  407. commit('help/GET_DETAIL_FAILURE', err)
  408. })
  409. },
  410. // 获取最多搜索量的 器件
  411. loadHotSearchDevice({ commit }) {
  412. commit('hotSearchDevice/REQUEST_HOT')
  413. return axios.get('/api/product/component/mostSearchComponent')
  414. .then(response => {
  415. commit('hotSearchDevice/GET_HOT_SUCCESS', response.data)
  416. }, err => {
  417. commit('hotSearchDevice/GET_HOT_FAILURE', err)
  418. })
  419. },
  420. // 获取最多搜索量的 品牌
  421. loadHotSearchBrand({ commit }) {
  422. commit('hotSearchBrand/REQUEST_HOT')
  423. return axios.get('/api/product/brand/mostSearchBrands')
  424. .then(response => {
  425. commit('hotSearchBrand/GET_HOT_SUCCESS', response.data)
  426. }, err => {
  427. commit('hotSearchBrand/GET_HOT_FAILURE', err)
  428. })
  429. },
  430. // 获取用户开店信息
  431. loadStoreStatus({ commit }, params = {}) {
  432. commit('option/REQUEST_STORE_STATUS')
  433. return axios.get('/store-service/stores', { params: params })
  434. .then(response => {
  435. commit('option/REQUEST_STORE_STATUS_SUCCESS', response.data)
  436. }, err => {
  437. commit('option/REQUEST_STORE_STATUS_FAILURE', err)
  438. })
  439. },
  440. // 获取首页悬浮计数器交易金额
  441. loadAllCount ({commit}, params) {
  442. commit('count/REQUEST_ALLCOUNT')
  443. return axios.get('/api/product/commoncount', {params})
  444. .then(res => {
  445. commit('count/GET_ALLCOUNT_SUCCESS', res.data)
  446. }, (err) => {
  447. commit('count/GET_ALLCOUNT_FAILURE', err)
  448. })
  449. },
  450. // 获取首页悬浮计数器询价单
  451. loadInquirySheet ({commit}, params) {
  452. commit('count/REQUEST_INQUIRYSHEET')
  453. return axios.get('/inquiry/public/getPurcInquiryItemCountByMonth', {params})
  454. .then(res => {
  455. commit('count/GET_INQUIRYSHEET_SUCCESS', res.data)
  456. }, (err) => {
  457. commit('count/GET_INQUIRYSHEET_FAILURE', err)
  458. })
  459. },
  460. loadInquirySheetLast ({commit}, params) {
  461. commit('count/REQUEST_INQUIRYSHEETLAST')
  462. return axios.get('/inquiry/public/getPurcInquiryItemCountByMonth', {params})
  463. .then(res => {
  464. commit('count/GET_INQUIRYSHEETLAST_SUCCESS', res.data)
  465. }, (err) => {
  466. commit('count/GET_INQUIRYSHEETLAST_FAILURE', err)
  467. })
  468. },
  469. // 保存微信信息
  470. GerWechatInfo({ commit }, params = {}) {
  471. commit('option/REQUEST_WECHATINFO_STATUS')
  472. return axios.get('/wx/getWxUserInfo', { params: params })
  473. .then(response => {
  474. commit('option/REQUEST_WECHATINFO_STATUS_SUCCESS', response.data)
  475. localStorage.setItem('USOFTMALLWECHATINFO', JSON.stringify(response.data))
  476. }, err => {
  477. localStorage.removeItem('USOFTMALLWECHATINFO')
  478. commit('option/REQUEST_WECHATINFO_STATUS_FAILURE', err)
  479. })
  480. },
  481. // 获取品牌中心轮播图
  482. loadBrandCarousel ({ commit }) {
  483. commit('carousel/REQUEST_BRANDCAROUSEL')
  484. return axios.get('/cmsApi?method=queryContentPage&module=brandCenter_littleSlideshow')
  485. .then(response => {
  486. commit('carousel/GET_BRANDCAROUSEL_SUCCESS', response.data)
  487. }, err => {
  488. commit('carousel/GET_BRANDCAROUSEL_FAILURE', err)
  489. })
  490. },
  491. // 获取品牌中心首屏背景图
  492. loadBrandBanner ({ commit }) {
  493. commit('product/banner/REQUEST_BRANDBANNER')
  494. return axios.get('/cmsApi?method=queryContentPage&module=brandCenter_firstScreen')
  495. .then(response => {
  496. commit('product/banner/GET_BRANDBANNER_SUCCESS', response.data)
  497. }, err => {
  498. commit('product/banner/GET_BRANDBANNER_FAILURE', err)
  499. })
  500. }
  501. }