import Vue from 'vue'
import Vuex from 'vuex'
import settings from "@/settings.js"
import moduleA from '@/store/modules/moduleA'
import moduleB from '@/store/modules/moduleB'

Vue.use(Vuex)
export default new Vuex.Store({
  state: {
    text: "我是moduleA模块下state.text的值",
    appId: settings.appId,
    stationId: settings.stationId,
    phoneNumber:uni.getStorageSync('phoneNumber') || "",
    countryCode:uni.getStorageSync('countryCode') || "",
    purePhoneNumber:uni.getStorageSync('purePhoneNumber') || "",
    openId: uni.getStorageSync('openId') || "",
    unionId: uni.getStorageSync('unionId') || "",
    userInfo: !uni.getStorageSync('userInfo') ? {} : JSON.parse(uni.getStorageSync('userInfo')),
    orderInfo:undefined,
    selectedGas:undefined
  },
  getters: {

  },
  mutations: {
    updatePhoneNumber(state, phoneNumber) {
      uni.setStorageSync('phoneNumber', phoneNumber);
      state.phoneNumber = phoneNumber
    },
    updateCountryCode(state, countryCode) {
      uni.setStorageSync('countryCode', countryCode);
      state.countryCode = countryCode
    },
    updatePurePhoneNumber(state, purePhoneNumber) {
      uni.setStorageSync('phoneNumber', phoneNumber);
      state.purePhoneNumber = purePhoneNumber
    },
    updateOpenId(state, openId) { 
      uni.setStorageSync('openId', openId);
      state.openId = openId
    },
    updateUnionId(state, unionId) { 
      uni.setStorageSync('unionId', unionId);
      state.unionId = unionId
    },
    updateUserInfo(state, userInfo) {      
      uni.setStorageSync('userInfo', JSON.stringify(userInfo));
      state.userInfo = userInfo
    },
    updateOrderInfo(state, orderInfo){
      state.orderInfo = orderInfo
    },
    updateSelectedGas(state, selectedGas){
      state.selectedGas = selectedGas
    }
    
    
  },
  actions: {

  },
  modules: {
    moduleA,
    moduleB
  }
})
