| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350 |
- import axios from '~plugins/axios'
- // 获取品牌详情产品分类信息
- function loadBrandCategories ({commit}, params = {}) {
- let id = params.id
- commit('brandCategories/REQUEST_CATEGORIES', params)
- return axios.get(`/api/product/brand/${id}/kinds`)
- .then(response => {
- commit('brandCategories/GET_CATEGORIES_SUCCESS', response.data)
- }, err => {
- commit('brandCategories/GET_CATEGORIES_FAILURE', err)
- })
- }
- // 获取品牌详情型号列表数据
- function loadBrandComponent ({commit}, params = {}) {
- commit('brandComponent/REQUEST_COMPONENT', params)
- return axios.get('/api/product/component/list', { params })
- .then(response => {
- commit('brandComponent/GET_COMPONENT_SUCCESS', response.data)
- }, err => {
- commit('brandComponent/GET_COMPONENT_FAILURE', err)
- })
- }
- export const actions = {
- // 全局服务初始化
- nuxtServerInit (store, { params, route, isDev, isServer, req }) {
- // 检查设备类型
- const userAgent = isServer ? req.headers['user-agent'] : navigator.userAgent
- const isMobile = /(iPhone|iPod|Opera Mini|Android.*Mobile|NetFront|PSP|BlackBerry|Windows Phone)/ig.test(userAgent)
- const cookie = isServer ? req.headers['cookie'] : null
- store.commit('option/SET_MOBILE_LAYOUT', isMobile)
- store.commit('option/SET_USER_AGENT', userAgent)
- store.commit('option/SET_COOKIES', cookie)
- // 设置跳转的URL
- if (!isDev) {
- store.commit('option/UPDATE_URL', 'http://www.usoftmall.com')
- }
- return Promise.all([
- // 全局数据
- store.dispatch('loadUserInfo')
- ])
- },
- // 获取用户信息
- loadUserInfo ({ commit }) {
- commit('option/REQUEST_USER_INFO')
- return axios.get('/user/authentication')
- .then(response => {
- commit('option/REQUEST_USER_INFO_SUCCESS', response.data)
- }, err => {
- commit('option/REQUEST_USER_INFO_FAILURE', err)
- })
- },
- // 用户退出
- logout ({ commit }) {
- return axios.get('/logout')
- .then(response => {
- commit('option/REQUEST_LOGOUT_SUCCESS', response.data)
- })
- },
- // 获取楼层配置
- loadFloors ({ commit }) {
- commit('floor/REQUEST_LIST')
- return axios.get('/api/floors/home')
- .then(response => {
- commit('floor/GET_LIST_SUCCESS', response.data)
- }, err => {
- commit('floor/GET_LIST_FAILURE', err)
- })
- },
- // 获取轮播配置
- loadBanners ({ commit }) {
- commit('carousel/REQUEST_BANNER')
- return axios.get('/api/carousel/home%20page%20banner')
- .then(response => {
- commit('carousel/GET_BANNER_SUCCESS', response.data)
- }, err => {
- commit('carousel/GET_BANNER_FAILURE', err)
- })
- },
- // 获取子器件类目
- loadProductKinds ({ commit }, params = {}) {
- let id = params.id
- commit('product/kind/REQUEST_KIND', params)
- return axios.get(`/api/product/kind/${id}/children`)
- .then(response => {
- commit('product/kind/GET_KIND_SUCCESS', { id, result: response.data })
- }, err => {
- commit('product/kind/GET_KIND_FAILURE', {id, err})
- })
- },
- // 获取全部子器件类目
- loadAllProductKinds ({ commit }, params = {}) {
- let id = params.id
- commit('product/kind/REQUEST_KIND', params)
- return axios.get(`/api/product/kind/${id}/children_all`)
- .then(response => {
- commit('product/kind/GET_KIND_SUCCESS', { id, result: response.data })
- }, err => {
- commit('product/kind/GET_KIND_FAILURE', {id, err})
- })
- },
- // 获取首页新闻
- loadNewsSnapshot ({ commit }, params = {}) {
- commit('news/REQUEST_SNAPSHOT')
- return axios.get('/api/news/created', {params})
- .then(response => {
- commit('news/GET_SNAPSHOT_SUCCESS', response.data)
- }, err => {
- commit('news/GET_SNAPSHOT_FAILURE', err)
- })
- },
- // 获取器件统计信息
- loadProductCounts ({ commit }, params = {}) {
- commit('product/common/REQUEST_COUNTS')
- return axios.get('/api/product/commoncount', {params})
- .then(response => {
- commit('product/common/GET_COUNTS_SUCCESS', response.data)
- }, err => {
- commit('product/common/GET_COUNTS_FAILURE', err)
- })
- },
- // 搜索关键字
- searchKeywords ({ commit }, params = {}) {
- commit('search/REQUEST_KEYWORDS')
- return axios.get('/search/similarKeywords', {params})
- .then(response => {
- commit('search/GET_KEYWORDS_SUCCESS', response.data)
- }, err => {
- commit('search/GET_KEYWORDS_FAILURE', err)
- })
- },
- resetSearchKeywords ({ commit }) {
- commit('search/RESET_KEYWORDS')
- },
- // 热卖推荐页面
- loadProductHot ({commit}, params = {}) {
- commit('original/REQUEST_HOT')
- return axios.get('/api/commodity/latest', {params})
- .then(response => {
- commit('original/GET_HOT_SUCCESS', response.data)
- }, err => {
- commit('original/GET_HOT_FAILURE', err)
- })
- },
- // 器件详情页面
- // 获得器件详情信息
- loadComponentDetail ({commit}, params = {}) {
- let id = params.id
- commit('componentDetail/REQUEST_DETAIL', params)
- return axios.get(`/api/product/component/${id}`)
- .then(response => {
- commit('componentDetail/GET_DETAIL_SUCCESS', response.data)
- if (response.data) {
- commit('componentMenu/REQUEST_MENU', params)
- return axios.get(`/api/product/kind/structing/${response.data.kindid}`)
- .then(response => {
- commit('componentMenu/GET_MENU_SUCCESS', response.data)
- }, err => {
- commit('componentMenu/GET_MENU_FAILURE', err)
- })
- }
- }, err => {
- commit('componentDetail/GET_DETAIL_FAILURE', err)
- })
- },
- // 获取器件详情页面包屑导航
- loadComponentMenu ({commit}, params = {}) {
- let pid = params.id
- commit('componentMenu/REQUEST_MENU', params)
- return axios.get(`/api/product/kind/structing/${pid}`)
- .then(response => {
- commit('componentMenu/GET_MENU_SUCCESS', response.data)
- }, err => {
- commit('componentMenu/GET_MENU_FAILURE', err)
- })
- },
- // 器件详情页选择商家
- loadComponentStore ({commit}, params = {}) {
- let id = params.uuid
- commit('componentStore/REQUEST_STORE', params)
- return axios.get(`/api/store-service/stores/uuid/${id}`)
- .then(response => {
- commit('componentStore/GET_STORE_SUCCESS', response.data)
- }, err => {
- commit('componentStore/GET_STORE_FAILURE', err)
- })
- },
- // 器件详情页商家列表
- loadComponentInformation ({commit}, uuid = '', pageParams = { page: 1, count: 10 }) {
- let params = {}
- let filter = {uuid: uuid.uuid, ignoreUMall: false, ignoreStore: false}
- // let sorting = {minPriceRMB: 'ASC'}
- params.filter = filter
- // params.sorting = sorting
- params.page = pageParams.page
- params.count = pageParams.count
- commit('componentInformation/REQUEST_INFORMATION')
- return axios.get('/api/commodity/goods/page', { params })
- .then(response => {
- commit('componentInformation/GET_INFORMATION_SUCCESS', response.data)
- }, err => {
- commit('componentInformation/GET_INFORMATION_FAILURE', err)
- })
- },
- // 获取库存寄售店铺storeid
- getUmallStoreId ({commit}) {
- commit('componentUmallStoreId/REQUEST_STOREID')
- return axios.get('/api/store-service/stores/UmallStore')
- .then(response => {
- commit('componentUmallStoreId/GET_STOREID_SUCCESS', response.data)
- }, err => {
- commit('componentUmallStoreId/GET_STOREID_FAILURE', err)
- })
- },
- // 品牌详情页面
- // 获得品牌详情信息
- loadBrandDetail ({commit, dispatch}, params = {}) {
- let id = params.id
- commit('brandDetail/REQUEST_DETAIL', params)
- return axios.get(`/api/product/brand/${id}`)
- .then(response => {
- let brand = response.data || {}
- commit('brandDetail/GET_DETAIL_SUCCESS', response.data)
- return Promise.all([
- loadBrandCategories({ commit }, {id: brand.id}),
- loadBrandComponent({ commit }, {count: 10, filter: { brandid: brand.id }, page: 1})
- ])
- }, err => {
- commit('brandDetail/GET_DETAIL_FAILURE', err)
- })
- },
- // 获取品牌详情产品分类信息
- loadBrandCategories ({commit}, params = {}) {
- let id = params.id
- commit('brandCategories/REQUEST_CATEGORIES', params)
- return axios.get(`/api/product/brand/${id}/kinds`)
- .then(response => {
- commit('brandCategories/GET_CATEGORIES_SUCCESS', response.data)
- }, err => {
- commit('brandCategories/GET_CATEGORIES_FAILURE', err)
- })
- },
- // 获取品牌详情型号列表数据
- loadBrandComponent ({commit}, params = {}) {
- commit('brandComponent/REQUEST_COMPONENT', params)
- return axios.get('/api/product/component/list', { params })
- .then(response => {
- commit('brandComponent/GET_COMPONENT_SUCCESS', response.data)
- }, err => {
- commit('brandComponent/GET_COMPONENT_FAILURE', err)
- })
- },
- // 获取品牌详情分页信息
- loadBrandPages ({commit}, params = {}) {
- commit('brandPages/REQUEST_PAGES', params)
- return axios.get('/api/product/PAGES/list', { params })
- .then(response => {
- commit('brandPages/GET__SUCCESS', response.data)
- }, err => {
- commit('brandPages/GET_COMPONENT_FAILURE', err)
- })
- },
- // 留言板
- // 提交了留言板信息
- uploadMessageBoardInformation ({commit}, params) {
- commit('messageBoard/REQUEST_INFORMATION')
- return axios.post('/api/operation/messageBoard', params)
- .then(response => {
- commit('messageBoard/GET_INFORMATION_SUCCESS', response.data)
- }, err => {
- commit('messageBoard/GET_INFORMATION_FAILURE', err)
- })
- },
- // 验证用户是否登录
- userIsLogin ({commit}) {
- commit('messageBoardIsLogin/REQUEST_LOGIN')
- return axios.get('/user/authentication')
- .then(response => {
- commit('messageBoardIsLogin/GET_LOGIN_SUCCESS', response.data)
- }, err => {
- commit('messageBoardIsLogin/GET_LOGIN_FAILURE', err)
- })
- },
- // 获取留言记录信息
- getMessageBoardInformation ({commit}, params) {
- let sorting = {createDate: 'DESC'}
- params.sorting = sorting
- commit('messageBoardInformation/REQUEST_INFORMATION', params)
- return axios.get('/operation/messageBoard/pageInfo/user', { params })
- .then(response => {
- commit('messageBoardInformation/GET_INFORMATION_SUCCESS', response.data)
- }, err => {
- commit('messageBoardInformation/GET_INFORMATION_FAILURE', err)
- })
- },
- // 获取帮助中心信息
- loadHelpSnapsho ({ commit }, params = {}) {
- commit('help/REQUEST_SNAPSHO')
- return axios.get('/api/help-service/helps', {params})
- .then(response => {
- commit('help/GET_SNAPSHO_SUCCESS', response.data)
- }, err => {
- commit('help/GET_SNAPSHO_FAILURE', err)
- })
- },
- // 获取帮助中心二级菜单
- loadHelpList ({ commit }, params = {}) {
- commit('help/REQUEST_HELPLIST')
- return axios.get('/api/help-service/issues', {params})
- .then(response => {
- commit('help/GET_HELPLIST_SUCCESS', response.data)
- }, err => {
- commit('help/GET_HELPLIST_FAILURE', err)
- })
- },
- // 获取帮助中心名称
- loadHelpTitle ({ commit }, params = {}) {
- let id = params.id
- commit('help/REQUEST_TITLE')
- return axios.get(`/api/help-service/${id}`, {params})
- .then(response => {
- commit('help/GET_TITLE_SUCCESS', response.data)
- }, err => {
- commit('help/GET_TITLE_FAILURE', err)
- })
- },
- // 获取详情
- loadHelpDetail ({ commit }, params = {}) {
- let id = params.id
- commit('help/REQUEST_DETAIL')
- return axios.get(`/api/help-service/issues/${id}`, {params})
- .then(response => {
- commit('help/GET_DETAIL_SUCCESS', response.data)
- let id = response.data.navId
- commit('help/REQUEST_TITLE')
- return axios.get(`/api/help-service/${id}`)
- .then(response => {
- commit('help/GET_TITLE_SUCCESS', response.data)
- }, err => {
- commit('help/GET_TITLE_FAILURE', err)
- })
- }, err => {
- commit('help/GET_DETAIL_FAILURE', err)
- })
- }
- }
|