98 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
			
		
		
	
	
			98 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
import { removeToken } from '@/config/auth.js'
 | 
						|
import { getInfo, logout } from '@/config/login.js'
 | 
						|
 | 
						|
import { getShoppingCount, getSmallCount } from '@/config/goods'
 | 
						|
const getDefaultState = () => {
 | 
						|
  return {
 | 
						|
    user: '',
 | 
						|
    shopCarLength: 0,
 | 
						|
    smallCarLength: 0,
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
const state = getDefaultState()
 | 
						|
 | 
						|
const mutations = {
 | 
						|
  SET_USER: (state, user) => {
 | 
						|
    state.user = user
 | 
						|
  },
 | 
						|
  SET_SMALL_CAR_LENGTH: (state, data) => {
 | 
						|
    state.smallCarLength = data
 | 
						|
  },
 | 
						|
  SET_SHOP_CAR_LENGTH: (state, data) => {
 | 
						|
    state.shopCarLength = data
 | 
						|
  },
 | 
						|
}
 | 
						|
 | 
						|
const actions = {
 | 
						|
  // 获取用户信息
 | 
						|
  GetInfo({ commit, state }) {
 | 
						|
    return new Promise((resolve, reject) => {
 | 
						|
      getInfo()
 | 
						|
        .then(res => {
 | 
						|
          if (res) {
 | 
						|
            commit('SET_USER', res.data)
 | 
						|
            uni.setStorageSync('User', res.data)
 | 
						|
            resolve(res)
 | 
						|
          }
 | 
						|
        })
 | 
						|
        .catch(error => {
 | 
						|
          reject(error)
 | 
						|
        })
 | 
						|
    })
 | 
						|
  },
 | 
						|
 | 
						|
  // 退出登录
 | 
						|
  LogOut({ commit, state }) {
 | 
						|
    return new Promise((resolve, reject) => {
 | 
						|
      logout(state.token)
 | 
						|
        .then(() => {
 | 
						|
          removeToken()
 | 
						|
          resolve()
 | 
						|
        })
 | 
						|
        .catch(error => {
 | 
						|
          reject(error)
 | 
						|
        })
 | 
						|
    })
 | 
						|
  },
 | 
						|
  getCarLength({ commit }, data) {
 | 
						|
    return new Promise((resolve, reject) => {
 | 
						|
      let pkCountry
 | 
						|
      let userInfo = uni.getStorageSync('User')
 | 
						|
      if (data == 1) {
 | 
						|
        if (uni.getStorageSync('pkCountry')) {
 | 
						|
          pkCountry = uni.getStorageSync('pkCountry')
 | 
						|
        } else {
 | 
						|
          pkCountry = userInfo.pkSettleCountry
 | 
						|
        }
 | 
						|
      } else {
 | 
						|
        pkCountry = userInfo.pkSettleCountry
 | 
						|
      }
 | 
						|
      let obj = { specialArea: data, pkCountry: pkCountry }
 | 
						|
      getShoppingCount(obj).then(res => {
 | 
						|
        if (res.code == 200) {
 | 
						|
          getSmallCount(obj).then(res1 => {
 | 
						|
            if (res.code == 200) {
 | 
						|
              commit('SET_SMALL_CAR_LENGTH', res1.data.smallCount)
 | 
						|
              commit('SET_SHOP_CAR_LENGTH', res.data.cont)
 | 
						|
              resolve(res)
 | 
						|
            }
 | 
						|
          })
 | 
						|
        }
 | 
						|
      })
 | 
						|
    })
 | 
						|
  },
 | 
						|
  setSmallCarLength({ commit }, data) {
 | 
						|
    commit('SET_SMALL_CAR_LENGTH', data)
 | 
						|
  },
 | 
						|
  setShopCarLength({ commit }, data) {
 | 
						|
    commit('SET_SHOP_CAR_LENGTH', data)
 | 
						|
  },
 | 
						|
}
 | 
						|
 | 
						|
export default {
 | 
						|
  state,
 | 
						|
  mutations,
 | 
						|
  actions,
 | 
						|
}
 |