import React from 'react';
import { connect } from 'dva';
import { DataTable } from '@components';
import { Button } from 'antd';
import { ExcelImport } from '@bizComponents';

const Deployment = ({ dispatch, suppAccount, loading }) => {
  const { accounts, total, showUploadModal } = suppAccount;
  const suppAccountDomain = 'suppAccount';

  const tableProps = {
    rowKey: 'id',
    limit: 15,
    offset: 0,
    sortDirection: 'DESC',
    scroll: { x: '100%' },
    domain: suppAccountDomain,
    dispatch,
    loading,
    total,
    showAdd: false,
    showView: false,
    showEdit: false,
    showDelete: false,
    dataSource: accounts,
    filter: [],
    columns: [{
      title: '供应商名称',
      dataIndex: 'suppName',
      width: '20%',
    }, {
      title: '供应商编号',
      dataIndex: 'suppCode',
      width: '20%',
    }, {
      title: '负责人电话',
      dataIndex: 'bussPicTel',
      width: '20%',
    }, {
      title: '负责人邮箱',
      dataIndex: 'bussPicMail',
      width: '20%',
    }],
    buttons: [{
      key: 'syncSuppAccount',
      type: 'primary',
      name: '批量生成账号',
      requiredSelected: 0,
      cb: (selectedKeys) => {
        dispatch({
          type: `${suppAccountDomain}/syncSuppAccount`
        });
      },
    }, {
      key: 'syncSuppAccountOne',
      type: 'primary',
      name: '生成登录账号',
      requiredSelected: 1,
      cb: (selectedKeys) => {
        dispatch({
          type: `${suppAccountDomain}/syncSuppAccountOne`,
          payload: {
            id: selectedKeys,
          },
        });
      },
    }],
  };

  const performance = () => {
    dispatch({
      type: `${suppAccountDomain}/syncPerformance`
    });
  }

  const uploadModal = {
    domain: suppAccountDomain,
    dispatch,
    showModal: showUploadModal,
    dataSource: [{
      aim: 'newsupp',
      name: '新供应商导入',
      temp: 'Supplier_Import',
      tempName: '新供应商导入模板',
    }],
  };
  
  const suppImportBtn = () => {
    dispatch({
      type: `${suppAccountDomain}/updateState`,
      payload: {
        showUploadModal: true
      }
    });
  }

  return (
    <div className="content-inner">
      {/* <DataTable {...tableProps} />

      <Button onClick={performance}>生成绩效数据</Button> */}

      <Button onClick={suppImportBtn}>新供应商导入</Button>
      {showUploadModal && <ExcelImport {...uploadModal} />}
    </div>
  );
};
export default connect(({ suppAccount, loading }) => ({ suppAccount, loading }))(Deployment);
