import React from "react";
import { connect } from "react-redux";
import Banner from "../components/Banner";
import { SHOW_CONFIG_MODAL, CLOSE_CONFIG_MODAL, CHANGE_TYPE, CONFIRM_TYPE } from "../store/types/typeConfig";
import {pushAllDataList} from '@utils/tools';
import {saveMode} from '@store/async-actions/fetchModules';
import config from "@config/index";
import { initItemList } from '@store/async-actions/tabTemplate';
import { allCheckedShow } from '@store/actions/tabTemplate';
import {Notify} from '@commonComp';

function mapStateToProps(state) {
  return {
    //failed:state.typeConfig.failed,
    typeConfig:state.typeConfig.typeConfig||config.defaultValue.mode,
    visible:state.typeConfig.visible
  };
}

function mapDispatchToProps(dispatch) {
  return {
    showConfigModal: () => {
      dispatch({type: SHOW_CONFIG_MODAL})
    },
    closeConfigModal: () => {
      dispatch({type: CLOSE_CONFIG_MODAL})
    },
    changeType: typeConfig => {
      dispatch({type: CHANGE_TYPE, typeConfig})
    },
    confirmType: confirmType => {
      //清空所有数据
      pushAllDataList('','clear');
      Notify.success("模式切换成功");
      //保存模式切换结果
      dispatch(saveMode(confirmType)).then((res)=>{
        if(res.data.code=='0'&&res.data.data){
          dispatch({type: CONFIRM_TYPE, confirmType});
          dispatch(initItemList(confirmType));
          dispatch(allCheckedShow(false))    //全选反选显示重置
        }else{
          Notify.error(res.data.msg+",请稍后再试");
          //dispatch({type:MODE_CHANGE_FAIL,data:true});      //保存失败弹窗提示
          //alert('模式保存失败')
        }
      });

    }
  };
}

const BannerContainer = connect(
  mapStateToProps,
  mapDispatchToProps
)(Banner);

export default BannerContainer;
