EPCModal.tsx 4.5 KB
import React, { useState, useEffect } from 'react';
import { Button, Modal, Table, Card, message, Divider, Popconfirm, Input } from "antd";
import { useStore } from '../index';
import usePagination from '@/hooks/usePagination';
import { getEpcdetailApi, deleteApi } from '../api';
import AddepcModal from './AddepcModal';

const { Column } = Table;

export default function FactoryEpcDetailModal() {
  const { currentItem, setEpcVisible, epcVisible, setCurrentInfo } = useStore();
  const [delay, setDelay] = useState(true);
  const [addVisible, setAddVisible] = useState(false);
  const { list, loading, setLoading, setParams, paginationConfig } = usePagination(getEpcdetailApi, { partCode: currentItem.partCode }, { delay });

  const _onChange = (param: string) => {
    setParams({ partCode: currentItem.partCode, current: 1, keywords: param }, true);
  };

  useEffect(() => {
    if (currentItem.partCode) {
      setParams({ partCode: currentItem.partCode }, true);
      setDelay(false);
    } else {
      setLoading(false);
      setDelay(false);
    }
  }, [currentItem]);

  function _delete(_item: PartRepertorySpace.PartEpc) {
    deleteApi({ id: _item.id }).then(() => {
      message.success('操作成功');
      setLoading(true);
    }).catch(e => {
      message.error(e.message);
    });
  }

  return (
    <Modal
      title="知识库标准"
      width={650}
      visible={epcVisible}
      maskClosable={false}
      onCancel={() => setEpcVisible(false)}
      // forceRender
      footer={
        <div>
          <Button onClick={() => setEpcVisible(false)}>取消</Button>
        </div>
      }
    >
      <Card title="配件信息" style={{ marginBottom: 20 }}>
        <div style={{ display: "flex", flexDirection: "column", paddingLeft: 15, paddingRight: 15 }}>
          <div style={{ display: "flex", flexDirection: "row", justifyContent: "flex-start", marginBottom: 20 }}>
            <span style={{ width: "50%" }}>
              <span style={{ color: 'red' }}>*</span>
              {`备件编码:${currentItem.partCode || '无'}`}
            </span>
            <span>
              <span style={{ color: 'red' }}>*</span>
              {`备件件号:${currentItem.partNo || '无'}`}
            </span>
          </div>
          <div style={{ display: "flex", flexDirection: "row", justifyContent: "flex-start", marginBottom: 20 }}>
            <span style={{ width: "50%" }}>
              <span style={{ color: 'red' }}>*</span>
              {`备件名称:${currentItem.partName || '无'}`}
            </span>
            <span>
              <span style={{ color: 'red' }}>*</span>
              {`备件单位:${currentItem.unit || '无'}`}
            </span>
          </div>
        </div>
      </Card>
      <Card title="知识库信息">
        <div style={{ display: 'flex', flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', marginBottom: 10 }}>
          <Input.Search
            placeholder="搜索车型代码"
            allowClear
            style={{ width: 200 }}
            onSearch={v => _onChange(v)}
            enterButton
          />
          <Button type="primary" onClick={() => { setAddVisible(true); setCurrentInfo({}); }}>新增</Button>
        </div>
        <Table
          size="small"
          loading={loading}
          pagination={paginationConfig}
          dataSource={list}
          rowKey={record => `id ${record.id}`}
          scroll={{ y: 400 }}
        >
          <Column title="车型代码" dataIndex="specCode" />
          <Column title="标准类型" dataIndex="stdType" render={(text) => <span>{text == 1 ? '厂家标准' : '霏微标准'}</span>} />
          <Column title="使用数量" dataIndex="partCount" />
          <Column
            title="操作"
            render={(text, _item: PartRepertorySpace.PartEpc) => (
              <>
                <a onClick={() => { setAddVisible(true); setCurrentInfo(_item); }}> 编辑</a>
                <Divider type="vertical" />
                <Popconfirm
                  title={`是否删除${_item.partCode}?`}
                  onConfirm={() => _delete(_item)}
                  okText="确定"
                  cancelText="取消"
                >
                  <a onClick={(e) => { e.preventDefault(); }}>删除</a>
                </Popconfirm>
              </>
            )} 
          />
        </Table>
      </Card>
      <AddepcModal
        visible={addVisible}
        onCancel={() => setAddVisible(false)}
        onFreshing={() => setLoading(true)}
      />
    </Modal>
  );
}