import React from 'react';
import { Button, Table,Popconfirm  } from 'antd';
import AuthButton from '@/components/AuthButton'
import moment from 'moment'

export default props => {
  const { data = {}, onChangePageNum,loading } = props;
  const { records=[], total, current,size } = data;

  const columns = [
    {
      title: '标题',
      dataIndex: 'trendTitle',
      key: 'trendTitle',
    },
    {
      title: '内容',
      dataIndex: 'trendContent',
      key: 'trendContent',
    },
    {
      title: '时间',
      dataIndex: 'trendTime',
      key: 'trendTime',
      render: (_, record) => <span>{moment(record.trendTime).format('YYYY-MM-DD')}</span>,
    },
    {
      title: '操作',
      dataIndex: 'apartmentId',
      key: 'apartmentId',
      render: (_, record) => (
        <>
          <AuthButton name="building.dynamic.edit">
            <Button type="link" onClick={() => props.onEdit(record)}>
              编辑
            </Button>
          </AuthButton>
          <AuthButton name="building.dynamic.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="trendId"
    />
  );
};
