index.js 18 KB

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