index.js 19 KB

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