index.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  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, isServer, req }) {
  26. // 检查设备类型
  27. const userAgent = isServer ? req.headers['user-agent'] : navigator.userAgent
  28. const isMobile = /(iPhone|iPod|Opera Mini|Android.*Mobile|NetFront|PSP|BlackBerry|Windows Phone)/ig.test(userAgent)
  29. const cookie = isServer ? 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. // 设置跳转的URL
  34. if (!isDev) {
  35. store.commit('option/UPDATE_URL', 'http://www.usoftmall.com')
  36. }
  37. return Promise.all([
  38. // 全局数据
  39. store.dispatch('loadUserInfo'),
  40. store.dispatch('loadProductCounts', { _status: 'actived' })
  41. ])
  42. },
  43. // 获取用户信息
  44. loadUserInfo ({ commit }) {
  45. commit('option/REQUEST_USER_INFO')
  46. return axios.get('/user/authentication')
  47. .then(response => {
  48. commit('option/REQUEST_USER_INFO_SUCCESS', response.data)
  49. }, err => {
  50. commit('option/REQUEST_USER_INFO_FAILURE', err)
  51. })
  52. },
  53. // 用户退出
  54. logout ({ commit }) {
  55. return axios.get('/logout')
  56. .then(response => {
  57. commit('option/REQUEST_LOGOUT_SUCCESS', response.data)
  58. })
  59. },
  60. // 获取楼层配置
  61. loadFloors ({ commit }) {
  62. commit('floor/REQUEST_LIST')
  63. return axios.get('/api/floors/home')
  64. .then(response => {
  65. commit('floor/GET_LIST_SUCCESS', response.data)
  66. }, err => {
  67. commit('floor/GET_LIST_FAILURE', err)
  68. })
  69. },
  70. // 获取轮播配置
  71. loadBanners ({ commit }, params = {}) {
  72. commit('carousel/REQUEST_BANNER')
  73. return axios.get('/api/carousel/' + params.type + '%20' + (params.type === 'home' ? 'page' : 'zone') + '%20banner')
  74. .then(response => {
  75. commit('carousel/GET_BANNER_SUCCESS', response.data)
  76. }, err => {
  77. commit('carousel/GET_BANNER_FAILURE', err)
  78. })
  79. },
  80. // 获取子器件类目
  81. loadProductKinds ({ commit }, params = {}) {
  82. let id = params.id
  83. commit('product/kind/REQUEST_KIND', params)
  84. return axios.get(`/api/product/kind/${id}/children`)
  85. .then(response => {
  86. commit('product/kind/GET_KIND_SUCCESS', { id, result: response.data })
  87. }, err => {
  88. commit('product/kind/GET_KIND_FAILURE', {id, err})
  89. })
  90. },
  91. // 获取全部子器件类目
  92. loadAllProductKinds ({ commit }, params = {}) {
  93. let id = params.id
  94. commit('product/kind/REQUEST_KIND', params)
  95. return axios.get(`/api/product/kind/${id}/children_all`)
  96. .then(response => {
  97. commit('product/kind/GET_KIND_SUCCESS', { id, result: response.data })
  98. }, err => {
  99. commit('product/kind/GET_KIND_FAILURE', {id, err})
  100. })
  101. },
  102. // 获取首页新闻
  103. loadNewsSnapshot ({ commit }, params = {}) {
  104. commit('news/REQUEST_SNAPSHOT')
  105. return axios.get('/api/news/created', {params})
  106. .then(response => {
  107. commit('news/GET_SNAPSHOT_SUCCESS', response.data)
  108. }, err => {
  109. commit('news/GET_SNAPSHOT_FAILURE', err)
  110. })
  111. },
  112. // 获取器件统计信息
  113. loadProductCounts ({ commit }, params = {}) {
  114. commit('product/common/REQUEST_COUNTS')
  115. return axios.get('/api/product/commoncount', {params})
  116. .then(response => {
  117. commit('product/common/GET_COUNTS_SUCCESS', response.data)
  118. }, err => {
  119. commit('product/common/GET_COUNTS_FAILURE', err)
  120. })
  121. },
  122. // 搜索关键字
  123. searchKeywords ({ commit }, params = {}) {
  124. commit('search/REQUEST_KEYWORDS')
  125. return axios.get('/search/similarKeywords', {params})
  126. .then(response => {
  127. commit('search/GET_KEYWORDS_SUCCESS', response.data)
  128. }, err => {
  129. commit('search/GET_KEYWORDS_FAILURE', err)
  130. })
  131. },
  132. resetSearchKeywords ({ commit }) {
  133. commit('search/RESET_KEYWORDS')
  134. },
  135. // 热卖推荐页面
  136. loadProductHot ({commit}, params = {}) {
  137. commit('original/REQUEST_HOT')
  138. return axios.get('/api/commodity/latest', {params})
  139. .then(response => {
  140. commit('original/GET_HOT_SUCCESS', response.data)
  141. }, err => {
  142. commit('original/GET_HOT_FAILURE', err)
  143. })
  144. },
  145. // 器件详情页面
  146. // 获得器件详情信息
  147. loadComponentDetail ({commit}, params = {}) {
  148. let id = params.id
  149. commit('componentDetail/REQUEST_DETAIL', params)
  150. return axios.get(`/api/product/component/${id}`)
  151. .then(response => {
  152. commit('componentDetail/GET_DETAIL_SUCCESS', response.data)
  153. if (response.data) {
  154. commit('componentMenu/REQUEST_MENU', params)
  155. return axios.get(`/api/product/kind/structing/${response.data.kindid}`)
  156. .then(response => {
  157. commit('componentMenu/GET_MENU_SUCCESS', response.data)
  158. }, err => {
  159. commit('componentMenu/GET_MENU_FAILURE', err)
  160. })
  161. }
  162. }, err => {
  163. commit('componentDetail/GET_DETAIL_FAILURE', err)
  164. })
  165. },
  166. // 获取器件详情页面包屑导航
  167. loadComponentMenu ({commit}, params = {}) {
  168. let pid = params.id
  169. commit('componentMenu/REQUEST_MENU', params)
  170. return axios.get(`/api/product/kind/structing/${pid}`)
  171. .then(response => {
  172. commit('componentMenu/GET_MENU_SUCCESS', response.data)
  173. }, err => {
  174. commit('componentMenu/GET_MENU_FAILURE', err)
  175. })
  176. },
  177. // 器件详情页选择商家
  178. loadComponentStore ({commit}, params = {}) {
  179. let id = params.uuid
  180. commit('componentStore/REQUEST_STORE', params)
  181. return axios.get(`/api/store-service/stores/uuid/${id}`)
  182. .then(response => {
  183. commit('componentStore/GET_STORE_SUCCESS', response.data)
  184. }, err => {
  185. commit('componentStore/GET_STORE_FAILURE', err)
  186. })
  187. },
  188. // 器件详情页商家列表
  189. loadComponentInformation ({commit}, params = {}) {
  190. // let params = {}
  191. // let filter = {uuid: uuid.uuid, ignoreUMall: false, ignoreStore: false}
  192. // // let sorting = {minPriceRMB: 'ASC'}
  193. // params.filter = filter
  194. // // params.sorting = sorting
  195. // params.page = pageParams.page
  196. // params.count = pageParams.count
  197. commit('componentInformation/REQUEST_INFORMATION')
  198. return axios.get('/api/commodity/goods/page', { params })
  199. .then(response => {
  200. commit('componentInformation/GET_INFORMATION_SUCCESS', response.data)
  201. }, err => {
  202. commit('componentInformation/GET_INFORMATION_FAILURE', err)
  203. })
  204. },
  205. // 获取库存寄售店铺storeid
  206. getUmallStoreId ({commit}) {
  207. commit('componentUmallStoreId/REQUEST_STOREID')
  208. return axios.get('/api/store-service/stores/UmallStore')
  209. .then(response => {
  210. commit('componentUmallStoreId/GET_STOREID_SUCCESS', response.data)
  211. }, err => {
  212. commit('componentUmallStoreId/GET_STOREID_FAILURE', err)
  213. })
  214. },
  215. // 品牌详情页面
  216. // 获得品牌详情信息
  217. loadBrandDetail ({commit, dispatch}, params = {}) {
  218. let id = params.id
  219. commit('brandDetail/REQUEST_DETAIL', params)
  220. return axios.get(`/api/product/brand/${id}`)
  221. .then(response => {
  222. let brand = response.data || {}
  223. commit('brandDetail/GET_DETAIL_SUCCESS', response.data)
  224. return Promise.all([
  225. loadBrandCategories({ commit }, {id: brand.id}),
  226. loadBrandComponent({ commit }, {count: 10, filter: { brandid: brand.id }, page: 1})
  227. ])
  228. }, err => {
  229. commit('brandDetail/GET_DETAIL_FAILURE', err)
  230. })
  231. },
  232. // 获取品牌详情产品分类信息
  233. loadBrandCategories ({commit}, params = {}) {
  234. let id = params.id
  235. commit('brandCategories/REQUEST_CATEGORIES', params)
  236. return axios.get(`/api/product/brand/${id}/kinds`)
  237. .then(response => {
  238. commit('brandCategories/GET_CATEGORIES_SUCCESS', response.data)
  239. }, err => {
  240. commit('brandCategories/GET_CATEGORIES_FAILURE', err)
  241. })
  242. },
  243. // 获取品牌详情型号列表数据
  244. loadBrandComponent ({commit}, params = {}) {
  245. commit('brandComponent/REQUEST_COMPONENT', params)
  246. return axios.get('/api/product/component/list', { params })
  247. .then(response => {
  248. commit('brandComponent/GET_COMPONENT_SUCCESS', response.data)
  249. }, err => {
  250. commit('brandComponent/GET_COMPONENT_FAILURE', err)
  251. })
  252. },
  253. // 获取品牌详情分页信息
  254. loadBrandPages ({commit}, params = {}) {
  255. commit('brandPages/REQUEST_PAGES', params)
  256. return axios.get('/api/product/PAGES/list', { params })
  257. .then(response => {
  258. commit('brandPages/GET__SUCCESS', response.data)
  259. }, err => {
  260. commit('brandPages/GET_COMPONENT_FAILURE', err)
  261. })
  262. },
  263. // 留言板
  264. // 提交了留言板信息
  265. uploadMessageBoardInformation ({commit}, params) {
  266. commit('messageBoard/REQUEST_INFORMATION')
  267. return axios.post('/api/operation/messageBoard', params)
  268. .then(response => {
  269. commit('messageBoard/GET_INFORMATION_SUCCESS', response.data)
  270. }, err => {
  271. commit('messageBoard/GET_INFORMATION_FAILURE', err)
  272. })
  273. },
  274. // 验证用户是否登录
  275. userIsLogin ({commit}) {
  276. commit('messageBoardIsLogin/REQUEST_LOGIN')
  277. return axios.get('/user/authentication')
  278. .then(response => {
  279. commit('messageBoardIsLogin/GET_LOGIN_SUCCESS', response.data)
  280. }, err => {
  281. commit('messageBoardIsLogin/GET_LOGIN_FAILURE', err)
  282. })
  283. },
  284. // 获取留言记录信息
  285. getMessageBoardInformation ({commit}, params) {
  286. let sorting = {createDate: 'DESC'}
  287. params.sorting = sorting
  288. commit('messageBoardInformation/REQUEST_INFORMATION', params)
  289. return axios.get('/operation/messageBoard/pageInfo/user', { params })
  290. .then(response => {
  291. commit('messageBoardInformation/GET_INFORMATION_SUCCESS', response.data)
  292. }, err => {
  293. commit('messageBoardInformation/GET_INFORMATION_FAILURE', err)
  294. })
  295. },
  296. // 获取帮助中心信息
  297. loadHelpSnapsho ({ commit }, params = {}) {
  298. commit('help/REQUEST_SNAPSHO')
  299. return axios.get('/api/help-service/helps', {params})
  300. .then(response => {
  301. commit('help/GET_SNAPSHO_SUCCESS', response.data)
  302. }, err => {
  303. commit('help/GET_SNAPSHO_FAILURE', err)
  304. })
  305. },
  306. // 获取帮助中心二级菜单
  307. loadHelpList ({ commit }, params = {}) {
  308. commit('help/REQUEST_HELPLIST')
  309. return axios.get('/api/help-service/issues', {params})
  310. .then(response => {
  311. commit('help/GET_HELPLIST_SUCCESS', response.data)
  312. }, err => {
  313. commit('help/GET_HELPLIST_FAILURE', err)
  314. })
  315. },
  316. // 获取帮助中心名称
  317. loadHelpTitle ({ commit }, params = {}) {
  318. let id = params.id
  319. commit('help/REQUEST_TITLE')
  320. return axios.get(`/api/help-service/${id}`, {params})
  321. .then(response => {
  322. commit('help/GET_TITLE_SUCCESS', response.data)
  323. }, err => {
  324. commit('help/GET_TITLE_FAILURE', err)
  325. })
  326. },
  327. // 获取详情
  328. loadHelpDetail ({ commit }, params = {}) {
  329. let id = params.id
  330. commit('help/REQUEST_DETAIL')
  331. return axios.get(`/api/help-service/issues/${id}`, {params})
  332. .then(response => {
  333. commit('help/GET_DETAIL_SUCCESS', response.data)
  334. let id = response.data.navId
  335. commit('help/REQUEST_TITLE')
  336. return axios.get(`/api/help-service/${id}`)
  337. .then(response => {
  338. commit('help/GET_TITLE_SUCCESS', response.data)
  339. }, err => {
  340. commit('help/GET_TITLE_FAILURE', err)
  341. })
  342. }, err => {
  343. commit('help/GET_DETAIL_FAILURE', err)
  344. })
  345. }
  346. }