index.js 12 KB

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