
import { getStoreTypeList,deleteStoreType } from '@/services/stock';
import { queryTable } from '@/utils/request';
import { PageContainer, ProTable } from '@ant-design/pro-components';
import { useNavigate } from 'react-router-dom';
import { Button, message, Popconfirm } from 'antd';
import { useRef, useState } from 'react';

const StockList = (props) => {
  const [showDetail, setShowDetail] = useState(false);
  const [activeKey, setActiveKey] = useState('');
  const actionRef = useRef();
  const navigate = useNavigate();

  const handleDelete = (id) => {
    if (id) {
      deleteStoreType(id).then((res) => {
        message.success('删除成功');
        actionRef.current.reload();
      });
    }
  };

  const columns = [
    {
      title: '分类名称',
      dataIndex: 'name',
    },

    {
      title: '排序',
      dataIndex: 'isFood',
      search: false,
      valueEnum: {
        1: '是',
        0: '否',
      },
    },

    {
      title: '操作',
      valueType: 'option',
      width: 200,
      render: (_, record) => [
        <Button
          key={2}
          style={{ padding: 0 }}
          type="link"
          onClick={() => {
            navigate(`/system/stockClassification/edit?id=${record.id}`);
          }}
        >
          修改
        </Button>,

        <Popconfirm
          key={3}
          title="您是否确认删除 ?"
          onConfirm={() => handleDelete(record.id)}
          okText="确定"
          cancelText="取消"
        >
          {/* manualPush */}
          <Button style={{ padding: 0 }} type="link">
            删除
          </Button>
        </Popconfirm>,
      ],
    },
  ];

  return (
    <PageContainer>
      <ProTable
        actionRef={actionRef}
        rowKey="id"
        toolBarRender={() => [
          <Button
            key="2"
            type="primary"
            onClick={() => {
              navigate('/system/stockClassification/edit');
            }}
          >
            新增
          </Button>,
        ]}
        // search={false}
        request={queryTable(getStoreTypeList)}
        columns={columns}
      />
    </PageContainer>
  );
};

export default StockList;
