import React, { useRef, useState, useEffect } from 'react';
import { Button, message, Table, Modal, Card } from 'antd';
import withActions from '@/components/ActionList';
import EditIcon from '@/components/EditIcon';
import router from 'umi/router';
import request from '@/utils/request';
import apis from '@/services/apis';
import AuthButton from '@/components/AuthButton';
import TableList from '@/components/TableList';

const header = props => {
  const ref = useRef();


  function addHouseTypes(id) {
    console.log()
    router.push({
      pathname: '/news/Sellhouse/houseTypes/Newindex',
      query: {id:id},
    });
  }
  function onDelete(ids, status) {
    Modal.confirm({
      title: '确认要删除此条内容吗',
      okText: '确认',
      cancelText: '取消',
      onOk() {
        request({ ...apis.system.deletePolicyType, urlData: { id: ids } })
          .then(data => {
            ref.current.reload();
            message.info('操作成功');
          })
          .catch(err => {
            console.log(err);
            message.info(err?.msg || err?.message);
          });
      },
    });
  }

  const columns = [
    // {
    //   title: '商品图片',
    //   dataIndex: 'img',
    //   key: 'img',
    //   align: 'center',

    //   render: (text, record) => <img src={record.img} className={channels.touxiang} />,
    // },
    {
      title: '类型名称',
      dataIndex: 'policyTypeName',
      key: 'policyTypeName',
      align: 'center',
    },
    {
      title: '顺序',
      dataIndex: 'sort',
      key: 'sort',
      align: 'center',
    },

    {
      title: '操作  ',
      dataIndex: 'status',
      key: 'status',
      align: 'center',

      render: withActions((text, record) => [
     
          <AuthButton name="encyclopedias.type.delete" noRight={null}>
            <EditIcon type="delete" text="删除" onClick={() => onDelete(record.policyTypeId)} />
          </AuthButton>
       ,

        <AuthButton name="encyclopedias.type.edit" noRight={null}>
          <EditIcon text="编辑" type="edit" onClick={() => addHouseTypes(record.policyTypeId)} />
        </AuthButton>,
      ]),
    },
  ];
  //   <AuthButton name="admin.tdBuildingType.delete" noRight={null}>
  //   <EditIcon text="删除" type="delete" onClick={() => deleteType(record)} />
  // </AuthButton>,
  // <AuthButton name="admin.tdBuildingType.update" noRight={null}>
  //   <EditIcon text="编辑" type="edit" onClick={() => toEdi(record.buildingTypeId)} />
  // </AuthButton>,

  const actionRender = () => {
    return (
      <AuthButton name="encyclopedias.type.add" noRight={null}>
        <Button type="primary" style={{ margin: '20px 0' }} onClick={()=>addHouseTypes()}>
          新增
        </Button>
      </AuthButton>
    );
  };

  return (
    <Card>
      <TableList
        ref={ref}
        api={apis.system.getPolicyTypeList}
        columns={columns}
        actionRender={actionRender}
      />
    </Card>
  );
};
export default header;
