import { connect } from 'dva/index';
import React, {Component, Fragment} from 'react';
import {Form, Spin, Tabs} from 'antd';

import {
  sldLlineRtextAddGoods,
  failTip,
  sucTip,
  getSldEmptyH,
  validatorVendorPhone,
  sldComLanguage,
  sldIconBtn,
  sldSearchValClear,
  getTableNum,
  getSldComImg,
  getSldComShowMoreTtex,
  sldtbaleOpeBtnText,
  sldPopConfirmDiy,
  list_com_page_size_10,
  formItemLayoutModal,
  sldHandlePaginationData,
  list_com_page_more
} from '@/utils/utils';
import global from '@/global.less';
import SldTableEdit from '@/components/SldTableEdit/SldTableEdit';
import SldTableAbout from '@/components/SldTableEdit/SldTableAbout';
import { Scrollbars } from 'react-custom-scrollbars';
import ImgModalChoose from "@/components/ImgModalChoose/ImgModalChoose";

import { apiUrl } from '@/utils/sldconfig.js';
import InstanceTemplateLists from "@/pages/store/pc_diy/instance_template_lists";
import DiyLists from "@/pages/store/pc_diy/diy_lists";
import StandardTable from "@/components/StandardTable";
import SldModal from "@/components/SldModal/SldModal";
import SldPreviewImg from "@/components/SldPreviewImg/SldPreviewImg";
import SldUEditor from '@/components/SldUEditor';
import product from "@/pages/goods/models/product";
import BusinessStateSelector from "@/components/BusinessStateSelector"

const TabPane = Tabs.TabPane;
let sthis = '';
let pageSize = list_com_page_size_10;

@connect(({ store,product }) => ({
  store,product
}))
@Form.create()
export default class Setting extends Component {
  constructor(props) {
    super(props);
    sthis = this;
    this.state = {
      initEditorFlag: false,//加载百度编辑器
      getEditorContentFlag: false,//获取百度编辑器内容标识
      initEditorContent: '',//百度编辑器内容
      flag: 0,
      scroll_h:42,
      search_con: '',
      imgModalvisible:false,
      profilePictureName:'',
      honorName:'',
      companyPictureName:'',
      title: '',
      show_preview_modal: false,//预览图片modal框是否展示
      preview_img: '',//预览图片
      preview_alt_con: '',//预览图片内容
      submitting: false,//提交按钮加载状态
      initLoading: false,//页面初始化加载状态
      submitingModal:false,//编辑新增弹框
      data: {},//列表数据
      honorData: {},//荣誉列表数据
      factoryData:{},//工厂图片数据
      selectedRows: [],
      selectedRowKeys: [],//selectedRows的key
      params: { pageSize: pageSize },
      info_data: [
        {
        type: 'show_content',
        label: `${sldComLanguage('店铺等级')}`,//店铺等级
        name: 'storeGradeName',
        initialValue: '',
      }, {
        type: 'textarea',
        label: `${sldComLanguage('主营商品')}`,//主营商品
        extra: `${sldComLanguage('请输入店铺主营商品关键字，如需填写多个商品，请用英文符号“，”进行分割，如“戒指，项链，耳环”，最多可输入200字。')}`,
        name: 'mainBusiness',
        maxLength: 200,
        placeholder: `${sldComLanguage('请输入店铺主营商品关键字')}`,//请输入店铺主营商品关键字
        initialValue: '',
      }, {
        type: 'upload_img_upload',
        label: `${sldComLanguage('店铺logo')}`,//店铺logo
        name: 'storeLogo',
        extra: `${sldComLanguage('建议上传宽130像素*高130像素的图片')}`,//建议上传宽130像素*高130像素的图片
        fileList: [],
        upload_name: 'file',
        upload_url: apiUrl + `v3/oss/common/upload?source=logo`,
        uploadChange: (info) => this.uploadImg(info, 'storeLogo'),
        uploadPreview: this.uploadImgPre,
        initialValue: '',
      }, {
        type: 'upload_img_upload',
        label: `${sldComLanguage('PC店铺横幅')}`,//PC店铺横幅
        name: 'storeBannerPc',
        extra: `${sldComLanguage('请上传1920*104的图片')}`,//请上传1920*104的图片
        fileList: [],
        upload_name: 'file',
        upload_url: apiUrl + `v3/oss/common/upload?source=logo`,
        uploadChange: (info) => this.uploadImg(info, 'storeBannerPc'),
        uploadPreview: this.uploadImgPre,
        initialValue: '',
      },
        // {
        //   type: 'upload_img_upload',
        //   label: `${sldComLanguage('移动端店铺横幅')}`,//移动端店铺横幅
        //   name: 'storeBannerMobile',
        //   extra: `${sldComLanguage('请上传750*253的图片')}`,//请上传750*253的图片
        //   fileList: [],
        //   upload_name: 'file',
        //   upload_url: apiUrl + `v3/oss/common/upload?source=logo`,
        //   uploadChange: (info) => this.uploadImg(info, 'storeBannerMobile'),
        //   uploadPreview: this.uploadImgPre,
        //   initialValue: '',
        // },
        {
          type: 'input',
          label: `${sldComLanguage('店铺客服电话')}`,//店铺客服电话
          extra: `${sldComLanguage('请输入用于交易联系的电话号码，方便买家进行咨询沟通')}`,//请输入用于交易联系的电话号码，方便买家进行咨询沟通
          name: 'servicePhone',
          placeholder: '',
          initialValue: '',
          rules: [{ validator: (rule, value, callback) => validatorVendorPhone(rule, value, callback) }],
        },
        {
          type: 'input',
          label: `${sldComLanguage('店铺地址')}`,//店铺地址
          extra: `${sldComLanguage('请输入用于交易联系的店铺地址，方便买家进行咨询沟通')}`,
          name: 'address',
          placeholder: '',
          initialValue: '',
        },
        {
          type: 'input',
          label: `${sldComLanguage('店铺邮箱')}`,//店铺邮箱
          extra: `${sldComLanguage('请输入用于交易联系的店铺邮箱，方便买家进行咨询沟通')}`,
          name: 'email',
          placeholder: '',
          initialValue: '',
        },{
          type: 'textarea',
          label: `${sldComLanguage('SEO关键字')}`,//SEO关键字
          extra: `${sldComLanguage('用于店铺引擎优化，关键字之间请用英文符号“，”进行分割')}`,//用于店铺引擎优化，关键字之间请用英文符号“，”进行分割
          name: 'storeSeoKeyword',
          maxLength: 200,
          placeholder: `${sldComLanguage('请输入SEO关键字')}`,//请输入SEO关键字
          initialValue: '',
        },  {
          type: 'textarea',
          label: `${sldComLanguage('SEO标题')}`,//SEO店铺描述
          extra: `${sldComLanguage('用于店铺引擎优化')}`,//用于店铺引擎优化，最多输入120字
          maxLength: 120,
          name: 'storeSeoTitle',
          placeholder: `${sldComLanguage('请输入SEO标题')}`,//请输入SEO店铺描述
          initialValue: '',
        },{
          type: 'textarea',
          label: `${sldComLanguage('SEO店铺描述')}`,//SEO店铺描述
          extra: `${sldComLanguage('用于店铺引擎优化')}`,//用于店铺引擎优化，最多输入120字
          maxLength: 120,
          name: 'storeSeoDesc',
          placeholder: `${sldComLanguage('请输入SEO店铺描述')}`,//请输入SEO店铺描述
          initialValue: '',
        },
        {
          type: 'input',
          label: `${sldComLanguage('谷歌地图经度设置')}`,//
          extra: `${sldComLanguage('谷歌地图经度设置')}`,//
          maxLength: 120,
          name: 'storeMapInfo',
          placeholder: `${sldComLanguage('请输入谷歌地图经度')}`,//
          initialValue: '',
        },
        {
          type: 'input',
          label: `${sldComLanguage('谷歌地图纬度设置')}`,//
          extra: `${sldComLanguage('谷歌地图纬度设置')}`,//
          maxLength: 120,
          name: 'storeMapInfoW',
          placeholder: `${sldComLanguage('请输入谷歌地图纬度')}`,//
          initialValue: '',
        },

      ],
      activeKey: '1',
      columns: [
        {
          title: ' ',
          dataIndex: 'brandId',
          align: 'center',
          width: 55,
          render: (text, record, index) => getTableNum(this.state.params, pageSize, index),
        },
        {
          title: `${sldComLanguage('图片名称')}`,
          dataIndex: 'name',
          align: 'center',
          width: 100,
        },
        {
          title: `${sldComLanguage('图片预览')}`,
          dataIndex: 'url',
          align: 'center',
          width: 100,
          render: (text) => {
            return getSldComImg(text,160,60,85,30);//图片预览
          },
        },
        {
          title: `${sldComLanguage('创建时间')}`,
          dataIndex: 'createTime',
          align: 'center',
          width: 100,
          render: (text) => {
            return text == null ? '--' : text;
          },
        },
        {
          title: `${sldComLanguage('更新时间')}`,//品牌分类
          dataIndex: 'updateTime',
          align: 'center',
          width: 100,
          render: (text) => {
            return text == null ? '--' : text;
          },
        },
        {
          title: `${sldComLanguage('操作')}`,
          align: 'center',
          width: 80,
          render: (text, record) => (
            <Fragment>
              {record.state != 1&&
              <Fragment>
                {sldtbaleOpeBtnText(`${sldComLanguage('编辑')}`, () => this.editBrand(record))}
                <span className={global.splitLine}></span>
              </Fragment>
              }

              {/*删除后不可恢复，是否确定删除？*/}
              {sldPopConfirmDiy('leftBottom', `${sldComLanguage('删除后不可恢复，是否确定删除')}`, () => this.operateBrand({id:record.id}, 'del'), `${sldComLanguage('确定')}`, `${sldComLanguage('取消')}`,
                sldtbaleOpeBtnText(`${sldComLanguage('删除')}`, () => null))}
            </Fragment>
          ),
        },
      ],
      addData: [
        {
        type: 'input',
        label: `${sldComLanguage('图片名称')}`,
        name: 'name',
        placeholder: `${sldComLanguage('请输入图片名称')}`,
        extra: `${sldComLanguage('最多输入100个字')}`,
        initialValue: '',
        maxLength:100,
        rules: [{
          required: true,
          whitespace: true,
          message: `${sldComLanguage('请输入品牌名称')}`,
        }]},{
        type: 'upload_img_upload',
        label: `${sldComLanguage('公司介绍图')}`,
        name: 'profile',
        show:false,
        extra: `${sldComLanguage('建议上传宽360像素*高270像素的图片')}`,
        fileList: [],
        img_info: {},
        upload_name: 'file',
        required: true,
        upload_url: apiUrl + `v3/oss/common/upload?source=profile`,
        uploadPreview: this.uploadImgPreModel,
        uploadChange: (info) => this.uploadImgModal(info, 'profile'),
        initialValue: '',
      },{
          type: 'upload_img_upload',
          label: `${sldComLanguage('荣誉资质图')}`,
          name: 'certificate',
          extra: `${sldComLanguage('建议上传宽度不低于800的高清图')}`,
          fileList: [],
          show:false,
          img_info: {},
          upload_name: 'file',
          required: true,
          upload_url: apiUrl + `v3/oss/common/upload?source=certificate`,
          uploadPreview: this.uploadImgPreModel,
          uploadChange: (info) => this.uploadImgModal(info, 'certificate'),
          initialValue: '',
        },{
          type: 'upload_img_upload',
          label: `${sldComLanguage('工厂介绍图')}`,
          name: 'companyShow',
          extra: `${sldComLanguage('建议上传宽度不低于800的高清图')}`,
          fileList: [],
          show:false,
          img_info: {},
          upload_name: 'file',
          required: true,
          upload_url: apiUrl + `v3/oss/common/upload?source=companyShow`,
          uploadPreview: this.uploadImgPreModel,
          uploadChange: (info) => this.uploadImgModal(info, 'companyShow'),
          initialValue: '',
        },
        {
          type: 'upload_multiple_img_upload_with_products_choose',
          label: `${sldComLanguage('请选择媒体库图片')}`,
          openChooseProductsImgModal: () => this.openChooseProductsImgModal()
        },{
        type: 'input',
        label: `${sldComLanguage('排序')}`,
        name: 'sort',
        required: true,
        placeholder: `${sldComLanguage('请输入排序')}`,
        extra: `${sldComLanguage('数字越小，排序越靠前')}`,
        initialValue: '',
        maxLength:20,
        rules: [{
          required: true,
          message: `${sldComLanguage('请输入排序')}`,
        }],
      }
      ],//modal框的数据
      imgModalList:[],
    };
  }


  cur_edit_id = '';//当前操作数据id


  componentDidMount() {
    this.get_list({ pageSize: pageSize });
    this.get_Honor_list({ pageSize: pageSize });
    this.get_Factory_list({ pageSize: pageSize });
    this.get_vendor_base_info();
    this.setState({ initEditorFlag: true });
    this.getAboutText()
    this.getImgList()

  }

  componentWillUnmount() {

  }

  getImgList = () => {
    let {addData} = this.state
    const { dispatch } = this.props;
    let  dis_type = 'store/get_media_list';
    let type = ''
    for (let i in addData) {
      if (addData[i].show) {
        type = addData[i].name
      }
    }
    let payload = { pageSize: list_com_page_more,type: type };
    dispatch({
      type: dis_type,
      payload: payload,
      callback: (res) => {
        console.log(res.data.list)
        if (res.state == 200) {
          this.setState({ imgModalList:res.data.list });
        }
      },
    });
  };

  //打开选择图片框
  openChooseProductsImgModal = () => {
    this.setState({
      imgModalvisible:true
    });
  };
  //关闭选择图片框
  imgModalhandleCancel = e => {
    this.setState({
      imgModalvisible: false,
    });
  };

  //点击确定接收数组后，处理当前数据业务
  imgModalhandleOk = (val) => {
    console.log(val)
    let { addData } = this.state;
    for (let i in addData) {
      if (addData[i].show) {
        addData[i].fileList = val;
        addData[i].img_info = val[0].response.data;
      }
    }
    this.setState({ addData });
  };


  //编辑新增 弹窗上传图片
  uploadImgModal = (info, type) => {
    let { addData } = this.state;
    if(info.file.status!=undefined&&info.file.status!='error') {
      for (let i in addData) {
        if (addData[i].name == type) {
          addData[i].fileList = info.fileList;
          addData[i].img_info = (info.file.response != undefined && info.fileList.length > 0 && info.file.response.data != undefined) ? info.file.response.data : [];
        }
      }
      console.log(addData)

      this.setState({ addData });
    }

  };
  //编辑新增 弹窗预览图片
  uploadImgPreModel = (info) => {
    let img = '';
    if(info.response!=undefined&&info.response.data!=undefined){
      img = info.response.data.url;
    }else{
      img = info.url;
    }
    this.viewImgModal(true, img);
  };

  //预览图片/关闭预览图片
  viewImgModal = (flag, img = '', text = '') => {
    this.setState({
      preview_img: img,
      preview_alt_con: text,
      show_preview_modal: flag,
    });
  };

  //获取店铺的基本信息
  get_vendor_base_info = () => {
    const { dispatch } = this.props;
    let { info_data } = this.state;
    dispatch({
      type: 'manage/getVendorSetting',
      callback: (res) => {
        if (res.state == 200) {
          if(!res.data.storeGradeName){
            info_data = info_data.filter(item=>item.name!='storeGradeName');
          }
          for (let i in info_data) {
            if (info_data[i].name == 'storeLogo') {
              let fileList = [];
              if (res.data.storeLogo) {
                let tmp_data = {};
                tmp_data.uid = new Date();
                tmp_data.name = res.data.storeLogo;
                tmp_data.status = 'done';
                tmp_data.url = res.data.storeLogoPath;
                fileList.push(tmp_data);
              }
              info_data[i].fileList = fileList;
              info_data[i].img_succ_info = { path: res.data.storeLogo };
            } else if (info_data[i].name == 'storeBannerPc') {
              let fileList = [];
              if (res.data.storeBannerPc) {
                let tmp_data = {};
                tmp_data.uid = new Date();
                tmp_data.name = res.data.storeBannerPc;
                tmp_data.status = 'done';
                tmp_data.url = res.data.storeBannerPcPath;
                fileList.push(tmp_data);
              }
              info_data[i].fileList = fileList;
              info_data[i].img_succ_info = { path: res.data.storeBannerPc };
            } else if (info_data[i].name == 'storeBannerMobile') {
              let fileList = [];
              if (res.data.storeBannerMobile) {
                let tmp_data = {};
                tmp_data.uid = new Date();
                tmp_data.name = res.data.storeBannerMobile;
                tmp_data.status = 'done';
                tmp_data.url = res.data.storeBannerMobilePath;
                fileList.push(tmp_data);
              }
              info_data[i].fileList = fileList;
              info_data[i].img_succ_info = { path: res.data.storeBannerMobile };
            } else {
              info_data[i].initialValue = res.data[info_data[i].name];
            }
          }
          if (info_data.length > 0) {
            info_data.push({
              type: 'button',
              label: '',
              name: 'button',
            });
          }
        }
        this.setState({ info_data, flag: 1 });
      },
    });
  };

  //预览图片
  uploadImgPre = (info) => {
    this.viewImg(true, info.name);
  };

  //上传图片 dataType:用于区分更改那个数据
  uploadImg = (info, dataType) => {
    let { info_data } = this.state;
    if (info.file.status != undefined && info.file.status != 'error') {
      for (let i in info_data) {
        if (info_data[i].name == dataType) {
          info_data[i].fileList = info.fileList;
          info_data[i].img_succ_info = (info.file.response != undefined && info.fileList.length > 0 && info.file.response.data != undefined) ? info.file.response.data : [];
        }
      }
      this.setState({ info_data });
    }
  };

  //保存事件
  handleSubmit = (values) => {
    this.setState({ submitting: true });
    const { dispatch } = this.props;
    const { info_data } = this.state;
    let param = {};
    delete info_data.button;
    for (let i in info_data) {
      if (info_data[i].name == 'storeLogo') {
        param.storeLogo = info_data[i].img_succ_info != undefined && info_data[i].img_succ_info.path != undefined ? info_data[i].img_succ_info.path : '';
      } else if (info_data[i].name == 'storeBannerMobile') {
        param.storeBannerMobile = info_data[i].img_succ_info != undefined && info_data[i].img_succ_info.path != undefined ? info_data[i].img_succ_info.path : '';
      } else if (info_data[i].name == 'storeBannerPc') {
        param.storeBannerPc = info_data[i].img_succ_info != undefined && info_data[i].img_succ_info.path != undefined ? info_data[i].img_succ_info.path : '';
      }
    }
    dispatch({
      type: 'store/save_vendor_base_info',
      payload: { ...param, ...values },
      callback: (res) => {
        if (res.state == 200) {
          sucTip(res.msg);
        } else {
          failTip(res.msg);
        }
        this.setState({ submitting: false });
      },
    });
  };


  onHandleTabClick = (e) => {
    this.setState({activeKey:e})
    this.sldSearClear()
  }

  //搜索框内容的变化
  sldSearChange = (val) => {
    this.setState({
      search_con: val.target.value,
    });
  };

  //清空搜索内容
  sldSearClear = () => {
    this.setState({
      search_con: '',
    });
    this.sldSearch('');
  };

  //搜索
  sldSearch = (val) => {
    let query = {};
    let { activeKey } = this.state;
    this.setState({params: { pageSize: pageSize } });
    if(activeKey == 2){
      query.profilePictureName = val;
      this.get_list({ pageSize: pageSize, ...query });
    }else if(activeKey == 3){
      query.honorName = val
      this.get_Honor_list({ pageSize: pageSize, ...query });
    }else if(activeKey == 4){
      query.companyPictureName = val
      this.get_Factory_list({ pageSize: pageSize, ...query });
    }
  };

  //获取数据列表
  get_list = (params) => {
    this.setState({ initLoading: true });
    const { dispatch } = this.props;
    dispatch({
      type: 'manage/getStoreProfile',
      payload: params,
      callback: (res) => {
        this.setState({ initLoading: false });
        if (res.state == 200) {
          if ((res.data.list==null||res.data.list.length == 0) && this.state.params.current > 1) {
            params.current = params.current - 1;
            this.get_list(params);
          } else {
            this.setState({
              data: res.data,
            });
          }
        }
      },
    });
  };

  //获取荣誉证书数据列表
  get_Honor_list = (params) => {
    this.setState({ initLoading: true });
    const { dispatch } = this.props;
    dispatch({
      type: 'manage/getStoreCertificate',
      payload: params,
      callback: (res) => {
        this.setState({ initLoading: false });
        if (res.state == 200) {
          if ((res.data.list==null||res.data.list.length == 0) && this.state.params.current > 1) {
            params.current = params.current - 1;
            this.get_Honor_list(params);
          } else {
            this.setState({
              honorData: res.data,
            });
          }
        }
      },
    });
  };

  //获取工厂图片证书数据列表
  get_Factory_list = (params) => {
    this.setState({ initLoading: true });
    const { dispatch } = this.props;
    dispatch({
      type: 'manage/getStoreFactory',
      payload: params,
      callback: (res) => {
        this.setState({ initLoading: false });
        if (res.state == 200) {
          if ((res.data.list==null||res.data.list.length == 0) && this.state.params.current > 1) {
            params.current = params.current - 1;
            this.get_Factory_list(params);
          } else {
            this.setState({
              factoryData: res.data,
            });
          }
        }
      },
    });
  };

  //添加公司图片
  addBrand = () => {
    let { addData,activeKey } = this.state;
    for (let i in addData) {
      addData[i].show = false
      if (addData[i].type == 'upload_img_upload') {
        addData[i].fileList = [];
        addData[i].img_info = {};
      } else {
        addData[i].initialValue = '';
      }
    }
    addData[activeKey - 1].show = true
    this.setState({ modalVisible: true, type: 'add', title: `${sldComLanguage('添加图片')}`, addData: addData });
    this.getImgList()
  };


  //编辑公司图片
  editBrand = (val) => {
    let { addData,activeKey } = this.state;
    for (let i in addData) {
      addData[i].show = false
      if (addData[i].name == 'profile' || addData[i].name == 'certificate' || addData[i].name == 'companyShow') {
        let fileList = [];
        let tmp_data = {};
        tmp_data.uid = val.id;
        tmp_data.name = val.name;
        tmp_data.status = 'done';
        tmp_data.url = val.url;
        fileList.push(tmp_data);
        addData[i].fileList = fileList;
        addData[i].img_info.path = val.path;
      }else if (addData[i].name == 'name') {
        addData[i].initialValue = val.name
      }else if (addData[i].name == 'sort') {
        addData[i].initialValue = val.sort
      }
    }
    addData[activeKey - 1].show = true
    this.cur_edit_id = val.id;//当前操作数据id
    this.setState({ type: 'edit', title: `${sldComLanguage('编辑品牌')}`, addData: addData, modalVisible: true });
    this.getImgList()
  };

  //弹窗业务-取消
  sldHandleCancle = () => {
    this.setState({ modalVisible: false });
  };

  //弹窗业务-确定
  sldHandleConfirm = (val) => {
    const { type, addData,activeKey } = this.state;
    const { dispatch } = this.props;
    let _this = this;
    let params = {}
    params.name = val.name;
    params.sort = val.sort;
    for (let i in addData) {
      if ((addData[i].name == 'profile' || addData[i].name == 'certificate' || addData[i].name == 'companyShow') && addData[i].show) {
        if (addData[i].img_info.path == undefined) {
          failTip(`${sldComLanguage('请上传图片')}`);
          return false;
        } else {
          params.path = addData[i].img_info.path;
        }
      }
    }
    let url = ''
    if(activeKey == 2){
      url = 'manage/getStroeAboutAdd'
    }else if(activeKey == 3){
      url = 'manage/getStoreCertificateAdd'
    }else if(activeKey == 4){
      url = 'manage/getStoreFactoryAdd'
    }
    this.setState({ submiting: true });
    if (type == 'edit') {
      params.id = this.cur_edit_id;
      this.operateBrand(params,'edit');
    } else {
      dispatch({
        type: url,
        payload: params,
        callback: (res) => {
          if (res.state == 200) {
            sucTip(res.msg);
            if(activeKey == 2){
              _this.get_list({ pageSize: pageSize });
            }else if(activeKey == 3){
              _this.get_Honor_list({ pageSize: pageSize });
            }else if(activeKey == 4){
              _this.get_Factory_list({ pageSize: pageSize });
            }
            this.setState({
              modalVisible: false,
              formValues: {},
              search_con: '',
            });
          } else {
            failTip(res.msg);
          }
          this.setState({ submiting: false });
        },
      });
    }
  };

  //编辑和删除
  operateBrand = (params, type) => {
    const { activeKey } = this.state;
    const { dispatch } = this.props;
    let dis_type = '';
    if (type == 'edit') {
      if(activeKey == 2){
        dis_type = 'manage/getStroeAboutEdit';
      }else if(activeKey == 3){
        dis_type = 'manage/getStoreCertificateEdit';
      }else if(activeKey == 4){
        dis_type = 'manage/getStoreFactoryEdit';
      }
    } else if (type == 'del') {
      if(activeKey == 2){
        dis_type = 'manage/getStroeAboutDel';
      }else if(activeKey == 3){
        dis_type = 'manage/getStoreCertificateDel';
      }else if(activeKey == 4){
        dis_type = 'manage/getStoreFactoryDel';
      }
    }
    dispatch({
      type: dis_type,
      payload: params,
      callback: (res) => {
        if (res.state == 200) {
          sucTip(res.msg);
          if(activeKey == 2){
            this.get_list(this.state.params);
          }else if(activeKey == 3){
            this.get_Honor_list(this.state.params)
          }else if(activeKey == 4){
            this.get_Factory_list(this.state.params)
          }
          this.setState({
            modalVisible: false,
          });
        } else {
          failTip(res.msg);
        }
        this.setState({ submiting: false });
      },
    });
  };


  handleTablePagination = (pagination, filtersArg, sorter, type = 'main') => {
    const { formValues,activeKey } = this.state;
    const params = sldHandlePaginationData(pagination, filtersArg, sorter, formValues);
    pageSize = params.pageSize;
    this.setState({
      params: params,
    });
    if(activeKey == 2){
      this.get_list(params);
    }else if(activeKey == 3){
      this.get_Honor_list(params);
    }else if(activeKey == 4){
      this.get_Factory_list(params);
    }
  };


  handleSaveAllData = () => {
    this.setState({ getEditorContentFlag: true });
  };


  //获取编辑器内容
  getEditorContent = (con) => {
    this.saveData(con);
    this.setState({ getEditorContentFlag: false });
  };

  //编辑器保存
  saveData = (editorCon) => {
    let _this = this;
    this.props.form.validateFieldsAndScroll((err, values) => {
      if (!err) {
        const { dispatch } = this.props;
        values.storeDesc = editorCon;
        dispatch({
          type: 'manage/getAboutTextEdit',
          payload: values,
          callback: (res) => {
            if (res.state == 200) {
              sucTip(res.msg);
            } else {
              failTip(res.msg);
            }
          },
        });
      }
    });
  };

  getAboutText = () => {
    const { dispatch } = this.props;
    dispatch({
      type: 'manage/getAboutText',
      callback: (res) => {
        if (res.state == 200) {
          this.setState({
            initEditorContent: res.data.content,
          });
        } else {
          failTip(res.msg);
        }
      },
    });
  }

  renderHeaderTip = () => {
    return (
      <span className={global.common_header_tip}>
        <span>{'('}</span>
        <span>{sldComLanguage('将店铺状态设为')}</span>
        <span className={global.common_header_tip_text}>{`“${sldComLanguage('经营中')}”`}</span>
        <span>{'，'}</span>
        <span>{sldComLanguage('立即上线营业')}</span>
        <span>{' )'}</span>
      </span>
    )
  }


  render() {
    const { imgModalList,imgModalvisible,data,honorData,factoryData,columns,info_data,initEditorFlag,getEditorContentFlag, initEditorContent,preview_img,submitting,show_preview_modal, preview_alt_con,modalVisible,addData,submitingModal,initLoading,title, flag,activeKey,search_con,scroll_h } = this.state;
    return (
      <Spin spinning={initLoading}>
        <div className={global.common_page_20}>
          {/*店铺设置*/}
          <div style={{ display: 'flex', justifyContent: 'space-between', marginBottom: '10px' }}>
              {sldLlineRtextAddGoods('#69A2F2', `${sldComLanguage('店铺设置')}`, this.renderHeaderTip())}
              <BusinessStateSelector />
          </div>
          <Tabs type="card" activeKey={activeKey} animated={false} onTabClick={this.onHandleTabClick}>
            <TabPane tab={`${sldComLanguage('基础设置')}`} key="1">
              <div className={`${global.flex_com_column} ${global.comm_line_sperator}`}>
                {getSldEmptyH(15)}
                {flag == 1 &&
                <SldTableEdit
                  submiting={submitting}
                  width={1200}
                  data={info_data}
                  handleSubmit={this.handleSubmit}
                />
                }
              </div>
            </TabPane>
            <TabPane tab={`${sldComLanguage('公司介绍')}`} key="2">
              <div className={`${global.flex_com_column} ${global.comm_line_sperator}`}>
                <div className={global.operate_bg}>
                  {sldIconBtn(() => this.addBrand(), `${sldComLanguage('新增图片')}`, 7, 7)}
                  {sldSearchValClear(`${sldComLanguage('请输入图片名称')}`, 291, this.sldSearch, `${sldComLanguage('搜索')}`, search_con, this.sldSearChange, this.sldSearClear, 65)}
                </div>

                <Scrollbars autoHeight autoHeightMax={document.body.clientHeight - 240}>

                  <StandardTable
                    totalHeight={document.body.clientHeight - 150-scroll_h-15}
                    data={data}
                    rowKey={'id'}
                    isCheck={false}
                    columns={columns}
                    onChange={(pagination, filtersArg, sorter) => this.handleTablePagination(pagination, filtersArg, sorter, 'main')}
                    resizeTable={(index, size) => this.resizeTable(index, size, 'columns', columns)}
                    isColumnResize={true}
                  />

                  <div className={global.tableListFormAdd}>
                    <div style={{ display: 'flex', flexDirection: 'column' }}>
                      <Form onSubmit={() => this.handleSaveAllData()} layout="inline">
                        {sldLlineRtextAddGoods('#69A2F2', `${sldComLanguage('公司简介')}`)}
                        <div className={global.goods_sku_tab} style={{ marginTop: 20, position: 'relative' }}>
                          {initEditorFlag &&
                          <SldUEditor id={'agreement'} getContentFlag={getEditorContentFlag} getEditorContent={this.getEditorContent} initEditorContent={initEditorContent}/>
                          }
                        </div>
                        <div className={global.m_diy_bottom_wrap_relative} >
                          <div onClick={() => this.handleSaveAllData()}
                               className={`${global.add_goods_bottom_btn} ${global.add_goods_bottom_btn_sel}`}>
                            {sldComLanguage('保存')}
                          </div>
                        </div>
                      </Form>
                    </div>
                  </div>

                </Scrollbars>

              </div>

            </TabPane>
            <TabPane tab={`${sldComLanguage('荣誉资质')}`} key="3">
              <div className={`${global.flex_com_column} ${global.comm_line_sperator}`}>
                {getSldEmptyH(15)}
                <div className={global.operate_bg}>
                  {sldIconBtn(() => this.addBrand(), `${sldComLanguage('新增图片')}`, 7, 7)}
                  {sldSearchValClear(`${sldComLanguage('请输入图片名称')}`, 291, this.sldSearch, `${sldComLanguage('搜索')}`, search_con, this.sldSearChange, this.sldSearClear, 65)}
                </div>

                  <StandardTable
                    totalHeight={document.body.clientHeight - 150-scroll_h-15}
                    data={honorData}
                    rowKey={'id'}
                    isCheck={false}
                    columns={columns}
                    onChange={(pagination, filtersArg, sorter) => this.handleTablePagination(pagination, filtersArg, sorter, 'main')}
                    resizeTable={(index, size) => this.resizeTable(index, size, 'columns', columns)}
                    isColumnResize={true}
                  />
              </div>
            </TabPane>
            <TabPane tab={`${sldComLanguage('工厂图片')}`} key="4">
              <div className={`${global.flex_com_column} ${global.comm_line_sperator}`}>
                {getSldEmptyH(15)}
                <div className={global.operate_bg}>
                  {sldIconBtn(() => this.addBrand(), `${sldComLanguage('新增图片')}`, 7, 7)}
                  {sldSearchValClear(`${sldComLanguage('请输入图片名称')}`, 291, this.sldSearch, `${sldComLanguage('搜索')}`, search_con, this.sldSearChange, this.sldSearClear, 65)}
                </div>

                  <StandardTable
                    totalHeight={document.body.clientHeight - 150-scroll_h-15}
                    data={factoryData}
                    rowKey={'id'}
                    isCheck={false}
                    columns={columns}
                    onChange={(pagination, filtersArg, sorter) => this.handleTablePagination(pagination, filtersArg, sorter, 'main')}
                    resizeTable={(index, size) => this.resizeTable(index, size, 'columns', columns)}
                    isColumnResize={true}
                  />

              </div>
            </TabPane>
          </Tabs>

          {/*新增/编辑对话框-start*/}
          <SldModal
            title={title}
            submiting={submitingModal}
            width={500}
            modalVisible={modalVisible}
            sldHandleConfirm={(val) => this.sldHandleConfirm(val)}
            sldHandleCancle={this.sldHandleCancle}
            formItemLayoutModal={formItemLayoutModal}
            content={addData}
          />
          {/*新增/编辑对话框-end*/}

          {/*图片预览-start*/}
          <SldPreviewImg img={preview_img} show_preview_modal={show_preview_modal} modal_width={300}
                         preview_alt_con={preview_alt_con} closePreviewModal={() => this.viewImgModal(false)}/>
          {/*图片预览-end*/}

          {/*图片库-start*/}
          <ImgModalChoose imgModalListProps={imgModalList} modal_width={500}  show_choose_modal={imgModalvisible} img_data={addData[activeKey-1]} max_length={1}  imgModalhandleOk = { (data) => this.imgModalhandleOk(data) }  imgModalhandleCancel = { this.imgModalhandleCancel }/>
          {/*图片库-end*/}

        </div>
      </Spin>
    );
  }
}
