WaitConfirmList.tsx 8.22 KB
import React, { useEffect, useState } from "react";
import {
  message,
  Modal,
  DatePicker,
  Input,
  Row,
  Select,
  Button,
  Table,
} from "antd";
import { useStore } from "../index";
import _ from "lodash";
import {
  AwardTypeEnum,
  SupportTypeEnum,
  SubjectTypeEnum,
} from "@/pages/stock/AllowanceConfirm/entity";
import usePagination from "@/hooks/usePagination";
import Dimission from "@/pages/cas/Dimission";
import {
  getSupportCheckListApi,
  getSupportWaitCheckListApi,
} from "@/pages/stock/AllowanceConfirm/EditComfirm/Manufacturer/api";

import moment from "moment";

interface Props {
  visible: boolean;
  awardType: number;
  onCancel: () => void;
  onFinish: () => void;
}
const { RangePicker } = DatePicker;
interface Search {
  supportType?: number; //1启票 2实销
  awardType?: number; //1正激励 2负激励
  supportName?: string; //促销政策名称
  rebateTimeBegin?: string; //折让兑现时间起
  rebateTimeEnd?: string; //折让对象时间止
  subjectType?: number;
}

export default function WaitConfirmList(props: Props) {
  const { visible, onCancel, onFinish, awardType } = props;
  const {
    subsidyTypeList,
    rebateId,
    setVisible,
    data,
    setLoading: setDetailLoading,
    currentItem,
    setOrderId,
    commonOrderList,
    orderId,
    detailVisible,
    setDetailVisible,
    commonComfirmApi,
    setSubmitSelectedRowkeys,
    commonWaitCheckList,
    commonCheckList,
    commonRemoveCheckList,
    commonEnterCheckList,
  } = useStore();
  const { dimension } = currentItem;
  const [comfrimloading, setComfirmLoading] = useState(false);

  const [delay, setDelay] = useState(true);
  const [checkDelay, setCheckDelay] = useState(true);
  /**
   * 存储待确认促销活动列表
   */
  const [orderList, setOrderList] = useState<
    FvmAllowance.SuportWaitCheckItems[]
  >([]);
  const [confirmOrderList, setConfirmOrderList] = useState([]);
  /**
   * 查询待确认促销活动列表 ==》搜索参数
   */
  const [searchParams, setSearchParams] = useState<Search>({});

  /** 选中行 */
  const [selectedRowKeys, setSelectedRowkeys] = useState<React.Key[]>([]);
  /**
   * 查询待确认促销活动列表
   */
  const {
    list,
    loading,
    setParams,
    paginationConfig,
    setLoading,
    innerParams,
  } = usePagination<FvmAllowance.SuportWaitCheckItems>(
    getSupportWaitCheckListApi,
    { rebateId },
    { delay }
  );

  useEffect(() => {
    if (visible) {
      fetchTableList();
    }
  }, [rebateId, visible]);

  useEffect(() => {
    if (list instanceof Array) {
      setOrderList([...list]);
    }
  }, [list]);

  const fetchTableList = (paramas: Search) => {
    //查询待确认促销活动列表
    if (rebateId) {
      setParams(
        {
          rebateId,
          ...paramas,
        },
        true
      );
      setDelay(false);
    }
  };

  const columns = [
    {
      title: "促销活动名称",
      dataIndex: "supportName",
      key: "supportName",
    },
    {
      title: "附件",
      dataIndex: "promotionFid",
      key: "promotionFid",
      render: (text: string) => (text ? (
        <a
          title="点击下载文档"
          target="_blank"
          rel="noreferrer"
          href={`/api/file/show?fid=${text}`}
        >
          查看
        </a>
      ) : (
        "--"
      )),
    },
    {
      title: "支持类型",
      dataIndex: "supportType",
      key: "supportType",
      render: (text: number) => text && SupportTypeEnum[text],
    },
    {
      title: "激励类型",
      dataIndex: "awardType",
      key: "awardType",
      render: (text: number) => text && AwardTypeEnum[text],
    },
    {
      title: "考核类型",
      dataIndex: "subjectType",
      key: "subjectType",
      render: (text: number) => text && SubjectTypeEnum[text],
    },
    {
      title: "考核对象",
      dataIndex: "subjectConfigName",
      key: "subjectConfigName",
    },
    {
      title: "折让时间",
      dataIndex: " rebateTime",
      key: " rebateTime",
      render: (text: number) => moment(text).format("YYYY-MM-DD"),
    },
    {
      title: "应折让金额(元)",
      dataIndex: "rebateAmount",
      key: "rebateAmount",
    },
  ];
  const onSelectChange = (
    selectedRowKeys: React.Key[],
    selectedRows: FvmAllowance.WaitCheckListItems[]
  ) => {
    setSelectedRowkeys([...selectedRowKeys]);
  };
  const rowSelection = {
    selectedRowKeys,
    onChange: onSelectChange,
  };

  // 选中促销政策加入折让清单
  const onAdd = async () => {
    const { success, result } = await getSupportCheckListApi({
      rebateId: Number(rebateId),
      awardType,
      // @ts-ignore;
      promotionIds: selectedRowKeys,
    });
    if (!success) {
      message.error(result, 5);
      return;
    }
    onCancel && onCancel();
    // 刷新厂家促销列表
    onFinish && onFinish();
  };
  return (
    <Modal
      title="待确认促销活动列表"
      visible={visible}
      width="70%"
      maskClosable={false}
      confirmLoading={comfrimloading}
      onCancel={() => onCancel && onCancel()}
      onOk={() => onAdd()}
      okText="加入"
    >
      <Row
        justify="space-between"
        align="middle"
        style={{ marginBottom: 16, flexWrap: "wrap" }}
      >
        <div>
          <span>促销政策名称:</span>
          <Input
            style={{ width: 200 }}
            allowClear
            placeholder="搜索促销政策名称"
            onChange={(e) => setSearchParams({
              ...searchParams,
              supportName: e.target.value || undefined,
            })}
          />
        </div>
        <div>
          {/* 支持类型 1启票支持 2实销支持 */}
          <span style={{ marginLeft: 15 }}>支持类型:</span>
          <Select
            allowClear
            style={{ width: 200, marginRight: 15 }}
            placeholder="请选择支持类型"
            onChange={(v) => setSearchParams({
              ...searchParams,
              supportType: v ? Number(v) : undefined,
            })}
          >
            {[1, 2].map((i) => (
              <Select.Option value={i} key={i}>
                {SupportTypeEnum[i]}
              </Select.Option>
            ))}
          </Select>
        </div>

        <div>
          {/* 激励类型 1正激励 2负激励 */}
          <span style={{ marginLeft: 15 }}>激励类型:</span>
          <Select
            allowClear
            style={{ width: 200, marginRight: 15 }}
            placeholder="请选择支持类型"
            onChange={(v) => setSearchParams({
              ...searchParams,
              awardType: v ? Number(v) : undefined,
            })}
          >
            {[1, 2].map((i) => (
              <Select.Option value={i} key={i}>
                {AwardTypeEnum[i]}
              </Select.Option>
            ))}
          </Select>
        </div>
        <div>
          {/* 	考核类型  1同一投资主体 2单一商家*/}
          <span style={{ marginLeft: 15 }}>支持类型:</span>
          <Select
            allowClear
            style={{ width: 200, marginRight: 15 }}
            placeholder="请选择支持类型"
            onChange={(v) => setSearchParams({
              ...searchParams,
              subjectType: v ? Number(v) : undefined,
            })}
          >
            {[1, 2].map((i) => (
              <Select.Option value={i} key={i}>
                {SubjectTypeEnum[i]}
              </Select.Option>
            ))}
          </Select>
        </div>
        <div style={{ marginTop: 20 }}>
          <span>下零售日期范围:</span>
          <RangePicker
            allowClear
            format="YYYY-MM-DD"
            onChange={(v) => setSearchParams({
              ...searchParams,
              rebateTimeBegin: v && v[0] && v[0].valueOf(),
              rebateTimeEnd: v && v[1] && v[1].valueOf(),
            })}
          />
        </div>

        <Button
          type="primary"
          onClick={() => fetchTableList(searchParams)}
        >
          查询
        </Button>
      </Row>
      <Table
        loading={loading}
        pagination={paginationConfig}
        size="small"
        rowKey="id"
        scroll={{ y: 500 }}
        dataSource={orderList}
        columns={columns}
        rowSelection={rowSelection}
      />
    </Modal>
  );
}