index.js 18 KB

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