index.js 19 KB

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