import { history, Link } from 'umi';
import { useRef, useState, useEffect } from 'react';
import { Button, Popconfirm, message, Tooltip } from 'antd';
import { PlusOutlined, QuestionCircleOutlined, DownOutlined } from '@ant-design/icons';
import { PageHeaderWrapper } from '@ant-design/pro-layout';
import ProTable from '@ant-design/pro-table';

export default (props) => {
  const dataSource = [
    {
      id: 2121329,
      title: '这是是一个标题标题',
      name: '胡彦斌',
      pushPerson: '农机手',
      status: 'APP内消息中心推送',
    },

  ];
  const gotoDetail = (id) => {
    history.push(`./MessageEdit`)
  }

  const actions = () => [
    <Button key="add" type="primary" icon={<PlusOutlined />} onClick={() => gotoDetail()}>
      新增商户
    </Button>,
  ];
  const columns = [
    {
      title: '消息ID',

      key: 'id',
      dataIndex: 'id',
      search: false,

      render: (t, record) => (
        <Link key={1} to={`./edit?id=${record.shopId}`}>
          {record.shopName}
        </Link>
      ),
    },

    {
      title: '消息标题',
      key: 'title',
      dataIndex: 'title',
      render: (t, record) => (
        <Link key={1} to={`./package?shopId=${record.shopId}`}>
          {record?.packageNum}
        </Link>
      ),
    },

    {
      title: '推送对象',
      key: 'pushPerson',
      search: false,
      dataIndex: 'pushPerson',
      render: (t, record) => (record.pushPerson === 1 ? '农机手' : '农户'),
    },

    {
      title: '推送方式',
      key: 'status',
      dataIndex: 'status',
      // render: (t, record) => record.status === 1 ? '发布' : '未发布',
      formItemProps: { label: '推送方式' },
      valueType: 'select',
      valueEnum: {
        0: { text: '通知栏推送' },
        1: { text: 'APP内消息中心推送' },
        2: { text: '短信推送' },
      },
    },

    {
      title: (
        <>
          创建时间
          <Tooltip placement="top">
            <QuestionCircleOutlined style={{ marginLeft: 4 }} />
          </Tooltip>
        </>
      ),
      width: 140,
      key: 'createdAt',
      dataIndex: 'createdAt',
      valueType: 'date',
      // render: (t) => formatterTime(t),
      sorter: (a, b) => a.createdAt - b.createdAt,
    },

    {
      title: '操作',
      valueType: 'option',
      width: '300px',
      render: (_, record) => [
        <Link key={2} to={`./MessageEdit`}>
          查看
        </Link>,
        <Popconfirm
          key={3}
          title="您是否确认删除 ?"
          onConfirm={() => handleDelete(record.noticeId)}
          okText="确定"
          cancelText="取消"
        >
          <a href="#">删除</a>
        </Popconfirm>,
      ],
    },
  ];

  return (
    <PageHeaderWrapper>
      <ProTable
        dataSource={dataSource}
        columns={columns}
        // request={getList}
        rowKey="id"
        options={false}
        toolBarRender={actions}
        scroll={{ x: 1000 }}
      />
    </PageHeaderWrapper>
  );
};
