index.js 18 KB

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