index.js 19 KB

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