import Vue from 'vue';
import Vuex from 'vuex';
import publicFun from '@/assets/publicFunction';
Vue.use(Vuex);
/**
 * 设置全局访问的state对象
 */
const state = {
  gameRatio:'', //玩法比率数据
  activity: 'StMorningPlate', //publicFun.getItem('activity'),//活动类别
  ball_code: 'zq', //publicFun.getItem('ballId'),//球类代码
  paly_code: 'CO', //玩法代码默认早盘玩法concede_size
  controlRouting:'',//控制路由
  loading:'',//Loading组件的状态显隐
  // isShow:false,//登录按钮点击显示登录页
  rgShow:false,//注册组件显示
  macth_id: '', //publicFun.getItem('macth_id'),//赛事id
  betting:[],//JSON.parse(publicFun.getItem('betting')),//投注数据
  passBetting:'',//串式投注数据
  bettingType:1,// 1为单式、2为串式
  leagueChoose:'',//联赛赛事选择
  leagueData:[],//联赛数据
  // isBetting:publicFun.getItem('isBetting'),//是否展示投注窗口
  deleteType:'',//投注框数据删除id或类型
  token:'', //用户凭证
  limit:0,//限制投注窗投注数量
  passLimit:'',//限制投注窗投注数量
  // headTitle:JSON.parse(publicFun.getItem('headTitle')),//头部导航数据信息
  // noRoll:false, // 禁止背景滚动
  playAlias:'',//玩法别名


}

/**
 * 实时监听state里面值的变法(最新变法)
 */
const getters = {
  getGameRatio(state){
     return state.gameRatio;
  },
  getActivity(state) {
    return state.activity;
  },
  getBallCode(state) {
    return state.ball_code;
  },
  getPaly_code(state) {
    return state.paly_code;
  },
  getControlRouting(state) {
    return state.controlRouting;
  },
  getLoading(state){
      return  state.loading;
  },
  // getIsShow(state){
  //     return  state.isShow;
  // },
  getRgShow(state){
      return state.rgShow;
  },
  getMatchId(state){
    return state.macth_id;
  },
  getBetting(state){
    return state.betting;
  },
  getPassBetting(state){
    return state.passBetting == '' ? JSON.parse(publicFun.getItem('passBetting')) : state.passBetting;
  },
  getBettingType(state){
    return state.bettingType;
  },
  getLeagueChoose(state){
    return state.leagueChoose;
  },
  getLeagueData(state){
    return state.leagueData;
  },
  // getIsBetting(state){
  //     return state.isBetting;
  // },
  getDeleteType(state){
      return state.deleteType;
  },
  getToken(state) {
    return state.token;
  },
  getLimit(state){
      return state.limit;
  },
  getPassLimit(state){
    return state.passLimit =='' ? publicFun.getItem('passLimit') :state.passLimit;
  },
  // getHeadTitle(state){
  //     return state.headTitle;
  // },
  // getNoRoll(state){
  //     return state.noRoll
  // },
  getPlayAlias(state){
    return state.playAlias == '' ? JSON.parse(publicFun.getItem('playAlias')) : state.playAlias;
  },

}
/**
 * 设置对外可调用的方法
 */
const mutations = {
  newGameRatio(state,val){
      //publicFun.getCache('activity')
      state.gameRatio = val; 
  },
  newActivity(state, val) {
    state.activity = val;
    //publicFun.setItem('activity',val)
  },
  newBallCode(state, val) {
    state.ball_code = val;
    //publicFun.setItem('ballId',val)
  },
  newPaly_code(state, val) {
    state.paly_code = val;
  },
  newControlRouting(state, val) {
    state.controlRouting = val;
  },
  newLoading(state,val){
      state.loading = val;
  },
  // newisShow(state,val){
  //     state.isShow = val;
  // },
  newRgShow(state,val){
      state.rgShow = val;
  },
  newMacth_id(state,val){
    state.macth_id = val;
    // publicFun.setItem('macth_id',val);
  },
  newBetting(state,val){
    let index =0;
    if(val){
        val.forEach(e=> {
            index += e.data.length 
        });
    }
    state.limit = index
    state.betting = val
  },
  newPassBetting(state,val){
      let index =0;
      if(val){
          val.forEach(e=> {
              index += e.data.length 
          });
      }
      state.passBetting = val;
      publicFun.setItem('passBetting',val);
      state.passLimit =index;
      publicFun.setItem('passLimit',index);
  },
  newBettingType(state,val){
    state.bettingType = val;
  },
  newLeagueChoose(state,val){
    state.leagueChoose = val;
  },
  newLeagueData(state,val){
    state.leagueData = val;
  },
  // newIsBetting(state,val){
  //     state.isBetting = val;
  //     publicFun.setItem('isBetting',val);
  // },
  newToken(state, val) {
    state.token = val;
    publicFun.setItem('token', val);
  },
  newDeleteType(state,val){
      state.deleteType = val;
  },
  // newLimit(state,val){
  //     state.limit = val;
  //     publicFun.setItem('limit',val);
  // },
  newPassLimit(state,val){
    state.limit = val;
    publicFun.setItem('passLimit',val);
  },
  // newHeadTitle(state,val){
  //     state.headTitle = val;
  //     publicFun.setItem('ehadTitle',val);
  // },
  // newNoRoll(state,val){
  //     state.noRoll = val
  // },
  newPlayAlias(state,val){
    state.playAlias = val;
    publicFun.setItem('playAlias',val);
  },
}

/**
 * 这里面的方法是用来异步触发mutations里面的方法
 */
const actions = {
  SETACTIVITY(context, val) {
    context.commit('newActivity', val);
  },
  SET_BALL_CODE(context, val) {
    context.commit('newBallCode', val);
  },
  SET_PALY_CODE(context, val) {
    context.commit('newPaly_code', val);
  },
  SET_CONTROLROUTING(context, val) {
    context.commit('newControlRouting', val);
  },
  GETLOADING(context,val){
      context.commit('newLoading',val)
  },
  // GET_ISSHOW(context,val){
  //     context.commit('newisShow',val)
  // },
  GETRGSHOW(context,val){
      context.commit('newRgShow',val)
  },
  MACTH_ID(context,val){
    context.commit('newMacth_id',val)
  },
  SET_BETTING(context,val){
      context.commit('newBetting',val)
  },
  SET_PASSBETTING(context,val){
      context.commit('newPassBetting',val)
  },
  SET_BETTINGTYPE(context,val){
      context.commit('newBettingType',val)
  },
  SET_LEAGUECHOOSE(context,val){
      context.commit('newLeagueChoose',val)
  },
  SET_LEAGUEDATA(context,val){
      context.commit('newLeagueData',val)
  },
  // ISBETTING(context,val){
  //     context.commit('newIsBetting',val)
  // },
  DEL_TYPE(context,val){
      context.commit('newDeleteType',val)
  },
  SET_TOKEN(context, val) {
    context.commit('newToken', val)
  },
  // SET_LIMIT(context,val){
  //     context.commit('newLimit',val)
  // },
  SET_PASSLIMIT(context,val){
    context.commit('newPassLimit',val)
  },
  // SET_HEADTITLE(context,val){
  //     context.commit('newHeadTitle',val)
  // },
  // SET_NOROLL(context,val){
  //     context.commit('newNoRoll',val)
  // },
  GETGAMERATIO(context,val){
      context.commit('newGameRatio',val)
  },
  SET_PLAYALIAS(context,val){
    context.commit('newPlayAlias',val)
  },
}
const store = new Vuex.Store({
  state,
  getters,
  mutations,
  actions
});
export default store;
