123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306 |
- import Vue from 'vue'
- import Vuex from 'vuex'
- Vue.use(Vuex)
- import {code2Session, logout, checkLogin} from '@/api/login.js'
- import {getLookUpDatas} from '@/api/data.js'
- import { getScanVinQty } from '@/api/car.js'
- import { xprhStoreApplyFindLast } from '@/api/xprh.js'
- let lifeData = {};
- try{
-
- lifeData = uni.getStorageSync('lifeData');
- }catch(e){
-
- }
- let saveStateKeys = ['vuex_carBrandList','vuex_uuidTempData','vuex_cartList'];
- const saveLifeData = function(key, value){
-
- if(saveStateKeys.indexOf(key) != -1) {
-
- let tmp = uni.getStorageSync('lifeData');
-
- tmp = tmp ? tmp : {};
- tmp[key] = value;
-
- uni.setStorageSync('lifeData', tmp);
- }
- }
- const store = new Vuex.Store({
- state: {
-
- forcedLogin: false,
- hasLogin: false,
- isOpenLocation: false,
-
-
- vuex_carBrandList: lifeData.vuex_carBrandList ? lifeData.vuex_carBrandList : [] ,
- vuex_carType: {},
- deviceNo: "",
- vuex_storeShelf: null,
- vuex_rewardRule: null,
- vuex_settleRecordDetail: null,
- vuex_settleOrderDetail: null,
- vuex_shelfChoosePart: [],
- vuex_allLookUp: [],
- vuex_paymentTypeList: [],
- vuex_priceTypeList:[],
- vuex_videoTypeList:[],
- vuex_showPrice:[false,'',false],
- vuex_userInfo: null,
- vuex_userPhoto: null,
- vuex_permCodes: [],
- vuex_openid: "",
- vuex_nowStaffData: null,
- vuex_nowRoleInfo: null,
- vuex_vinScanNums:null,
- vuex_scanMaxNums: 10,
- vuex_cartTotal: 0,
- vuex_storeAuthInfo: null ,
- vuex_tempData: null,
- vuex_configPrice: null,
- vuex_hasShopiing: false,
- vuex_showShopAuth: false,
- vuex_uuidTempData: lifeData.vuex_uuidTempData ? lifeData.vuex_uuidTempData : null,
- vuex_cartList: lifeData.vuex_cartList ? lifeData.vuex_cartList : [],
- vuex_tabBarList: [
- {
- "pagePath": "/pages/index/index",
- "iconPath": "/static/tab/tab_home_normal.png",
- "selectedIconPath": "/static/tab/tab_home_pressed.png",
- "text": "首页",
- 'customIcon': false,
- },
- {
- 'iconPath': "/static/tab/tab_scan_normal.png",
- 'selectedIconPath': "/static/tab/tab_scan_pressed.png",
- 'text': '扫描VIN',
- 'customIcon': false,
- 'midButton': false
- },
- {
- "pagePath": "/pages/cart/index",
- "iconPath": "/static/tab/tab_cart_normal.png",
- "selectedIconPath": "/static/tab/tab_cart_pressed.png",
- "text": "购物车",
- 'customIcon': false,
- 'count': 0,
- 'isDot': false
- },
- {
- "pagePath": "/pages/morePage/morePage",
- "iconPath": "/static/tab/tab_personal_normal.png",
- "selectedIconPath": "/static/tab/tab_personal_pressed.png",
- "text": "我的",
- 'customIcon': false,
- }
- ]
- },
- getters:{
- getOpeid(state){
- return state.vuex_openid
- }
- },
- mutations: {
- login(state, data) {
- console.log(data,'-----loginSucees-----')
- state.hasLogin = true;
- state.vuex_userInfo = data.auth_user;
- state.vuex_userPhoto = data.auth_user.extInfo&&data.auth_user.extInfo.userExtInfo ? data.auth_user.extInfo.userExtInfo.headImage : ''
- uni.setStorageSync('userPhoto', state.vuex_userPhoto);
-
- data.auth_user['identifyType'] = data.sysUserFlag == '0' ? 'VISITOR' : 'EMPLOYEE';
- data.auth_user['sysUserFlag'] = data.sysUserFlag;
- uni.setStorageSync('token', data.access_token);
- uni.setStorageSync('userInfo', data.auth_user);
-
- const permCodes = data.sysUserFlag == '0' ? null : data.auth_user.permCodes.filter(item => item.indexOf("_mini")>=0);
- state.vuex_permCodes = permCodes;
- uni.setStorageSync('permCodes', permCodes);
-
-
- const promoIndex = state.vuex_tabBarList.findIndex(item => item.text == '促销')
- if(promoIndex > -1){
- state.vuex_tabBarList.splice(promoIndex,1)
- }
-
- const scanTab = state.vuex_tabBarList.find(item => item.text == '扫描VIN')
- if(scanTab){
- scanTab.iconPath = "/static/tab/tab_scan_normal.png"
- scanTab.midButton = false
- }
- },
- logout(state) {
- console.log(state,'----logout------')
- state.hasLogin = false;
- uni.removeStorageSync('token')
- uni.removeStorageSync('userInfo')
- uni.removeStorageSync('permCodes')
- uni.removeStorageSync('userPhoto')
- state.vuex_storeShelf = null
- state.vuex_userInfo = null
- state.vuex_userPhoto = null
- state.vuex_permCodes = null
- state.vuex_storeAuthInfo = null
- state.vuex_rewardRule = null
- },
- openId(state,id) {
- state.vuex_openid = id
- uni.setStorageSync('openid', id);
- },
- $uStore(state, payload) {
-
- let nameArr = payload.name.split('.');
- let saveKey = '';
- let len = nameArr.length;
- if(nameArr.length >= 2) {
- let obj = state[nameArr[0]];
- for(let i = 1; i < len - 1; i ++) {
- obj = obj[nameArr[i]];
- }
- obj[nameArr[len - 1]] = payload.value;
- saveKey = nameArr[0];
- } else {
-
- state[payload.name] = payload.value;
- saveKey = payload.name;
- }
-
- saveLifeData(saveKey, state[saveKey])
- },
- isOpenLocation(state,isOpenLocation){
- state.isOpenLocation = isOpenLocation
- },
- setHasLogin(state,isLogin){
- state.hasLogin = isLogin;
- state.vuex_userInfo = uni.getStorageSync('userInfo')
- },
- setScanNums(state,nums) {
- state.vuex_vinScanNums = nums
- },
- setStoreAuthInfo(state,obj) {
- state.vuex_storeAuthInfo = obj
- }
- },
- actions: {
-
- getSotreAuth(context,mobile){
- xprhStoreApplyFindLast({contactPhone: mobile}).then(res => {
- console.log(res)
- context.commit('setStoreAuthInfo',res.data || null)
- if(res.status == 200){
- const showStoreAuthTips = uni.getStorageSync('showStoreAuthTips')
- if(res.data&&res.data.auditStatus=='PASS'&&!showStoreAuthTips){
- uni.setStorageSync('showStoreAuthTips',1)
- uni.showModal({
- title: '提示',
- content: '门店认证审核已通过,请重新登录!',
- confirmText: '去登录',
- showCancel: false,
- success(e) {
- console.log(e)
- if (e.confirm) {
- context.commit('logout');
- uni.navigateTo({
- url: '/pages/login/login'
- });
- }
- }
- })
- }
- }else{
- if(res.errCode == 'ACCOUNT_0001'){
- context.commit('logout');
- uni.navigateTo({
- url: '/pages/login/login'
- });
- }
- }
- })
- },
-
- getScanNums(context,provider){
- getScanVinQty().then(res => {
- context.commit('setScanNums',res.data||0)
- })
- },
- wxLogin(context,provider){
- uni.login({
- provider: provider,
- success(result) {
- console.log(result)
- if (result.code) {
- code2Session({
- code: result.code
- }).then(res => {
- console.log(res)
- if (res.status === '200') {
- context.commit('openId',res.data)
- };
- });
- }
- }
- });
- },
-
- userLogout(context,data){
- logout().then(res => {
- console.log(res,'out')
- if(res.status == 200){
- context.commit('logout')
- uni.$emit("refashHome")
- }
- })
- },
-
- checkLogin(context,callback){
- console.log(callback,'--checkLogin--')
- checkLogin().then(res => {
- if(res.status == '200'){
- context.commit('setHasLogin',true)
- }else{
- context.commit('logout')
- }
- callback&&callback(res.status == '200')
- })
- },
-
- checkIsOpenLocation(context,data) {
- uni.authorize({
- scope: 'scope.userLocation',
- success:()=> {
-
- const systemInfo = uni.getSystemInfoSync()
- if(systemInfo.locationAuthorized) {
- context.commit('isOpenLocation', true)
- } else {
- context.commit('isOpenLocation', false)
- }
- },
- fail() {
- uni.getSetting({
- success(res) {
- if(!res.authSetting['scope.userLocation'] || !res.authSetting['scope.userLocationBackground']){
- context.commit('isOpenLocation', false)
- } else {
- context.commit('isOpenLocation', true)
- }
- },
- fail() {
- context.commit('isOpenLocation', false)
- }
- })
-
- }
- })
- },
- }
- })
- export default store
|