import React from 'react'
import { Button, Table,Popconfirm } from 'antd'
import TableList from '@/components/TableList';
import request from '@/utils/request';
import apis from '@/services/apis';
import moment from 'moment';
import AuthButton from '@/components/AuthButton'

export default (props) => {
  const { data = {}, onChangePageNum,loading } = props;
  const { records=[], total, current,size } = data;
  
  const columns = [
    {
      title: '房源',
      dataIndex: 'roomName',
      key: 'roomName',
    },
    {
      title: '户型',
      dataIndex: 'unitType',
      key: 'unitType',
    },
    {
      title: '面积',
      dataIndex: 'area',
      key: 'area',
      render: (t) => <span>{`${t || ' -- '} ㎡`}</span>,
    },
    {
      title: '开始时间',
      dataIndex: 'startTime',
      key: 'startTime',
      render: (_, record) => <span>{moment(record.startTime).format('YYYY-MM-DD')}</span>,
    },
    {
      title: '结束时间',
      dataIndex: 'endTime',
      key: 'endTime',
      render: (_, record) => <span>{moment(record.endTime).format('YYYY-MM-DD')}</span>,
    },
    {
      title: '操作',
      dataIndex: 'apartmentId',
      key: 'apartmentId',
      render: (_, record) => (
        <>
          <AuthButton name="building.special.edit">
            <Button type="link" onClick={() => props.onEdit(record)}>编辑</Button>
          </AuthButton>
          <AuthButton name="building.special.delete">
            <Popconfirm
              title="确定要进行删除操作 ?"
              onConfirm={() => props.onDelete(record)}
            >
              <Button type="link" style={{ color: 'red' }}>删除</Button>
            </Popconfirm>
          </AuthButton>
        </>
      ),
    },
  ]

  return (
    <Table
    columns={columns}
    dataSource={records}
    loading={loading}
    pagination={{ defaultCurrent: 1, total: total, onChange: onChangePageNum, current: current, pageSize:size }}
    style={{ marginTop: '1em', width: '100%' }}
    rowKey="specialRoomId"
  />
    // <Table columns={columns} style={{marginTop: '1em', width: '100%'}} rowKey="specialRoomId" />
    // <TableList
    //     // ref={ref}
    //     rowKey="specialRoomId"
    //     api={apis.building.getTrendList}
    //     // params={{buildingId}}
    //     // searchFields={searchFields}
    //     // actionRender={actionRender}
    //     style={{marginTop: '1em', width: '100%'}}
    //     columns={columns}
    //   />
  )
}
