import React from 'react';
import { connect } from 'dva';
import { Input, DatePicker, Modal } from 'antd';
import { config, stringUtils } from '@utils';
import { DataTable, UdcSelect, SuggestSelect } from '@components';

const { api } = config;
const { excel } = api;
const { exportExcelURL } = excel;
const { MonthPicker } = DatePicker;
const { confirm } = Modal;
const supplierLifeStyle = ({ dispatch, supplierLifeStyle, loading }) => {
  const { list, total, supplier, showMenu } = supplierLifeStyle;

  const domain = 'supplierLifeStyle';

  const tableProps = {
    rowKey: 'id',
    limit: stringUtils.queryURL('limit'),
    offset: stringUtils.queryURL('offset'),
    sortBy: stringUtils.queryURL('sortBy') || 'suppCode',
    sortDirection: stringUtils.queryURL('sortDirection') || 'DESC',
    scroll: { x: '100%', y: 400 },
    domain,
    dispatch,
    loading,
    total,
    showAdd: false,
    showDelete: false,
    showEdit: false,
    showUpload: !supplier.supplier,
    /*handleDownload: {
      //requestUrl: `${exportExcelURL}/performance`,
      requestUrl: `${exportExcelURL}/performance`,
      requestParam: window.location.search,
    },*/
    buttons: [showMenu[0] && {
      key: 'create',
      type: 'primary',
      name: '修改',
      requiredSelected: 1,
      cb: (selectedKeys) => {
        console.log("selectedKeys");
        dispatch({
          type: `${domain}/getSingle`,
          payload: {
            id: selectedKeys,
            mode: 'update',
          },
        });
      },
    }],
    dataSource: list,
    filter: [{
      title: '供应商',
      dataIndex: 'suppCodeName',
      tag: <Input placeholder="请输入名称/编号" disabled={supplier.supplier} />,
      options: {
        initialValue: supplier.supplier ? supplier.suppName.trim() : supplier.suppCode,
      },
    },{
      title: '评分规则',
      dataIndex: 'perforType',
      options: {
        initialValue: supplier.perforType,
      },
      tag: <UdcSelect domain="SUPP" code="PERFOR_TYPE" />,
    },{
      title: '考核周期',
      dataIndex: 'assessPeriod',
      options: {
        initialValue: supplier.assessPeriod,
      },
      tag: <UdcSelect domain="SUPP" code="ASSESS_PERIOD" />,
    }],
    columns: [{
      title: '编号',
      dataIndex: 'suppCode',
      sorter: true,
      key: 'suppCode',
      width: '25%',
    }, {
      title: '名称',
      dataIndex: 'suppName',
      className: 'alignLeft nowrap',
      key: 'suppName',
      sorter: true,
      width: '25%',
    }, {
      title: '评分规则',
      dataIndex: 'perforType',
      className: 'alignLeft nowrap',
      key: 'perforType',
      sorter: false,
      width: '25%',
    }, {
      title: '考核周期',
      dataIndex: 'assessPeriod',
      className: 'alignLeft nowrap',
      key: 'assessPeriod',
      sorter: false,
      width: '25%',
    }],
  };


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

export default connect(({ supplierLifeStyle, loading }) => ({ supplierLifeStyle, loading }))(supplierLifeStyle);
