HistoryModal.tsx 3.16 KB
import { postServiceOrderQueryHistoryOrderRecord } from '@/services';
import { enumValueToLabel, formatDateTime } from '@/utils';
import { Button, Col, Empty, Flex, Modal, Row } from 'antd';
import { useEffect, useState } from 'react';
import { HISTORY_OPT_TYPE, ORDER_STATUS_OPTIONS } from '../constant';

export default ({ subOrders, onClose }) => {
  let subOrderIds = subOrders?.map((subOrder: any) => {
    return subOrder.id;
  });
  const [data, setData] = useState([]);
  let i = 1;

  const handleOk = () => {
    onClose();
  };

  const getHistory = async () => {
    let res = await postServiceOrderQueryHistoryOrderRecord({
      data: { ids: subOrderIds },
    });
    setData(res.data);
    console.log(data);
  };

  useEffect(() => {
    getHistory();
  }, []);

  const handleCancel = () => {
    onClose();
  };

  return (
    <>
      <Modal
        title="订单历史记录"
        open
        onOk={handleOk}
        onCancel={handleCancel}
        footer={() => (
          <>
            <Button onClick={handleCancel}>返回</Button>
          </>
        )}
      >
        <Row>
          {data.map((item) => {
            return (
              <Col span={24} key="key">
                <Flex vertical>
                  <span className="py-2 text-[#5E5E5E]">{'商品' + i++}</span>
                  <Flex vertical>
                    {item.historySubOrderRecordDto?.map((history) => {
                      return (
                        <div className="py-1" key="key">
                          <span className="pr-2 text-[#5E5E5E]">
                            {formatDateTime(history.createTime)}
                          </span>
                          <span className="text-[#3b83e5]">
                            {history.createByName}
                          </span>
                          进行了
                          <span className="text-[#3b83e5]">
                            {HISTORY_OPT_TYPE.get(history.record)}
                          </span>

                          {enumValueToLabel(
                            history.status,
                            ORDER_STATUS_OPTIONS,
                          ) === undefined
                            ? '子订单开票状态为'
                            : '子订单状态为'}

                          <span className="text-[#3b83e5]">
                            {enumValueToLabel(
                              history.status,
                              ORDER_STATUS_OPTIONS,
                            ) === undefined
                              ? '已开票'
                              : enumValueToLabel(
                                  history.status,
                                  ORDER_STATUS_OPTIONS,
                                )}
                          </span>
                        </div>
                      );
                    })}
                  </Flex>
                </Flex>
              </Col>
            );
          })}
        </Row>
        {data?.length <= 0 ? (
          <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} />
        ) : (
          ''
        )}
      </Modal>
    </>
  );
};