import { createStore } from 'vuex'

import login from './login'
import indexPage from './indexPage'
import cartPage from './cartPage'
import goodPage from './goodPage'
import addressVue from './address'
import waybill from './waybill'
import loginApi from '@/apis/login'

export const store = createStore({
    state: {
        loading: false,
        confirmCheckShow: true,
        countTime: 5,
        isShowShop: true,// 是否显示购物之类的，用于抖音、apple 提交审核时
        iosOrAndroid: {}  // 手机信息
    },
    mutations: {
        showLoad: state => {
            state.loading = true
            // #ifdef MP
            // uni.showNavigationBarLoading()
            // #endif
        },
        hideLoad: state => {
            state.loading = false
            // #ifdef MP
            // uni.hideNavigationBarLoading()
            // #endif
        },
        cancelConfirmCheckShow: (state) => {
            state.confirmCheckShow = false
        },
        setIsShowShop: (state, json) => {
            state.isShowShop = json
        },
        setIosOrAndroid: (state, json) => {
            state.iosOrAndroid = json
        }
    },
    actions: {
        isHiddenCart: async ({ commit }, appid) => {
            // let res = await loginApi.getVersionController('tta6a1d01c399f264201', appid)
            let res = await loginApi.getVersionController(appid)
            // console.log('获取版本信息', JSON.parse(res[0].value).update.isForceUpdate)
            commit('setIsShowShop', JSON.parse(res[0].value).update.isForceUpdate)
        }
    },
    getters: {
        loading: state => state.loading,
        confirmCheckShow: state => state.confirmCheckShow,
        countTime: state => state.countTime,
        isShowShop: state => state.isShowShop,
        iosOrAndroid: state => state.iosOrAndroid
    },
    modules: {
        login, indexPage, cartPage, goodPage, addressVue, waybill
    }
})