import Vue from 'vue'
import 'es6-promise'
import Vuex from 'vuex'
Vue.use(Vuex)
export default new Vuex.Store({
    state: {
        CONFIG: {}, // 配置
        userInfo: {}, // 用户信息
        finance: 0, // 鸿币余额
        query: {}, // 路由携带参数 pay: game 游戏充值  hb 鸿币充值
        payArg: {}, // 支付传递的参数
        isShowExitGame: false, // 是否显示退出游戏
        /**
         * gamepay页面
         * 显示哪个菜单内容
         * 游戏内充值: "" 鸿币充值优惠明细: hbDetailGamePay
         * 鸿币充值: hbGamePay  鸿币支付确认: hbConfirm
         * 
         */
        showGameInner: "",
        /**
         * android平台
         * 仙界情缘: xjqy
         */
        platform: "",
    },
    getters: {
        // 获取当前支付平台的中文名
        getPayPlatform: function(state) {
            const { query } = state
            let pay_platform;
            switch (query.pay_platform) {
                case "HB":
                    pay_platform = "鸿币"
                    break;
                case "WECHATPAY":
                    pay_platform = "微信"
                    break;
                case "ALIPAY":
                    pay_platform = "支付宝"
                    break;
            }
            return pay_platform;
        }
    },
    // 异步操作
    actions: {
        // 页面配置
        setConfigAction(context, payload) {
            context.commit('setConfigMutation', payload)
        },
        // 用户信息
        userInfoAction(context, payload) {
            context.commit("userInfoMutation", payload)
        },
        // 鸿币余额
        financeAction(context, payload) {
            context.commit("financeMutation", payload)
        },
        // 路由携带参数
        queryAction(context, payload) {
            context.commit("queryMutation", payload)
        },
        // 支付传递过来的参数
        payArgAction(context, payload) {
            context.commit("payArgMutation", payload)
        },
        // 是否显示退出游戏
        isShowExitGameAction(context, payload) {
            context.commit("isShowExitGameMutation", payload)
        },
        // appid
        appidAction(context, payload) {
            context.commit("appidMutation", payload)
        },
        // 显示的菜单内容
        showGameInnerAction(context, payload) {
            context.commit("showGameInnerMutation", payload)
        },
        // 当前android平台
        platformAction(context, payload) {
            context.commit("platformMutation", payload)
        },
    },
    mutations: {
        // 页面配置
        setConfigMutation(state, payload) {
            state.CONFIG = payload
        },
        // 用户信息
        userInfoMutation(state, payload) {
            state.userInfo = payload
        },
        // 鸿币余额
        financeMutation(state, payload) {
            state.finance = payload
        },
        // 路由携带参数
        queryMutation(state, payload) {
            state.query = payload
        },
        // 支付传递过来的参数
        payArgMutation(state, payload) {
            state.payArg = payload
        },
        // 是否展示退出游戏
        isShowExitGameMutation(state, payload) {
            state.isShowExitGame = payload
        },
        // appid
        appidMutation(state, payload) {
            state.appid = payload
        },
        // 当前android平台
        platformMutation(state, payload) {
            state.platform = payload
        },
    }
})