Blame view

src/pages/coupon/CouponOperation/components/CouponLog.tsx 3.74 KB
37010f1f   赵凤   优惠券记录
1
  import React, { useState, useEffect } from "react";
1c570a92   赵凤   优惠券运维
2
  import { getCouponLog, setCouponDelay } from "../api";
37010f1f   赵凤   优惠券记录
3
  import useInitial from "@/hooks/useInitail";
1c570a92   赵凤   优惠券运维
4
5
  import {
    Modal,
1c570a92   赵凤   优惠券运维
6
    Table,
1c570a92   赵凤   优惠券运维
7
8
9
10
11
    Form,
    DatePicker,
    Button,
    message,
  } from "antd";
e6d4533f   莫红玲   bugfix
12
  import moment from 'moment';
37010f1f   赵凤   优惠券记录
13
14
  
  interface Props {
5acf3da2   莫红玲   优惠券运维优化
15
    couponLog: { visible: boolean; id: number; no: string, delay?: boolean };
37010f1f   赵凤   优惠券记录
16
    setCouponLog: Function;
1369a5a1   赵凤   优惠券核销
17
    onChange: () => void;
37010f1f   赵凤   优惠券记录
18
  }
37010f1f   赵凤   优惠券记录
19
20
21
22
23
24
25
26
27
28
29
30
31
  // 日志类型
  enum LogTypeEnum {
    "创建",
    "待生效",
    "待使用",
    "已锁定",
    "已使用 ",
    "已过期",
    "已作废 ",
    "激活 ",
    "延期",
  }
  const { Column } = Table;
1c570a92   赵凤   优惠券运维
32
33
  function CouponLog({ couponLog, setCouponLog, onChange }: Props) {
    const [form] = Form.useForm();
37010f1f   赵凤   优惠券记录
34
35
36
37
38
39
    const { data, setParams, params, loading } = useInitial(
      getCouponLog,
      [],
      couponLog.id,
      !couponLog.id
    );
37010f1f   赵凤   优惠券记录
40
41
42
43
44
    useEffect(() => {
      if (couponLog.visible) {
        setParams(params, true);
      }
    }, [couponLog]);
1c570a92   赵凤   优惠券运维
45
46
47
48
49
50
51
52
53
54
55
56
57
  
    const [confirmLoading, setConfirmLoading] = useState(false);
  
    const onFinish = () => {
      console.log("提交延迟");
      form
        .validateFields()
        .then((field) => {
          setConfirmLoading(true);
          setCouponDelay({ ...field, id: couponLog.id })
            .then((res) => {
              message.success("优惠券延期成功", 2);
              setCouponLog({ ...couponLog, visible: false });
1369a5a1   赵凤   优惠券核销
58
              onChange && onChange();
1c570a92   赵凤   优惠券运维
59
60
61
62
63
64
            })
            .catch((err) => message.error(err.message))
            .finally(() => setConfirmLoading(false));
        })
        .catch((error) => message.error(error.message, 2));
    };
37010f1f   赵凤   优惠券记录
65
66
    return (
      <Modal
1c570a92   赵凤   优惠券运维
67
        title={couponLog.delay ? "优惠券延期" : "优惠券记录"}
37010f1f   赵凤   优惠券记录
68
69
        visible={couponLog.visible}
        onCancel={() => setCouponLog({ visible: false })}
1c570a92   赵凤   优惠券运维
70
71
72
73
74
        afterClose={() => form.resetFields()}
        footer={
          !couponLog.delay
            ? null
            : [
5acf3da2   莫红玲   优惠券运维优化
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
              <Button
                key="submit"
                type="primary"
                loading={confirmLoading}
                onClick={() => form.submit()}
              >
                确定
              </Button>,
              <Button
                key="back"
                onClick={() => setCouponLog({ visible: false })}
              >
                取消
              </Button>,
            ]
1c570a92   赵凤   优惠券运维
90
        }
37010f1f   赵凤   优惠券记录
91
      >
1c570a92   赵凤   优惠券运维
92
93
94
        {couponLog.delay ? (
          <>
            <Form onFinish={onFinish} form={form}>
5acf3da2   莫红玲   优惠券运维优化
95
96
97
              <Form.Item label="优惠券编码">
                <div>{couponLog.no}</div>
              </Form.Item>
1c570a92   赵凤   优惠券运维
98
99
              <Form.Item
                label="延期时间"
1369a5a1   赵凤   优惠券核销
100
                style={{ width: "100%" }}
1c570a92   赵凤   优惠券运维
101
102
103
                name="delayTime"
                rules={[{ required: true, message: "请选择延期时间!" }]}
              >
1369a5a1   赵凤   优惠券核销
104
                <DatePicker showTime style={{ width: "100%" }} />
1c570a92   赵凤   优惠券运维
105
106
107
108
109
110
111
              </Form.Item>
            </Form>
          </>
        ) : (
          <Table
            dataSource={data}
            loading={loading}
aa8f3ce6   莫红玲   优惠券记录rowKey
112
            rowKey="id"
1c570a92   赵凤   优惠券运维
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
          >
            <Column
              title="日志类型"
              dataIndex="type"
              key="type"
              render={(text) => (
                <span>{text !== undefined ? LogTypeEnum[text] : "--"}</span>
              )}
            />
            <Column
              title="调用系统"
              dataIndex="gateName"
              key="gateName"
              render={(text) => <span>{text || "--"}</span>}
            />
            <Column
5acf3da2   莫红玲   优惠券运维优化
129
              title="创建时间"
1c570a92   赵凤   优惠券运维
130
131
              dataIndex="createTime"
              key="createTime"
5acf3da2   莫红玲   优惠券运维优化
132
              render={(text) => <span>{text ? moment(text).format("YYYY-MM-DD HH:mm") : "--"}</span>}
1c570a92   赵凤   优惠券运维
133
134
135
136
137
138
139
140
141
            />
            <Column
              title="备注"
              dataIndex="remark"
              key="type"
              render={(text) => <span>{text || "--"}</span>}
            />
          </Table>
        )}
37010f1f   赵凤   优惠券记录
142
143
144
145
146
      </Modal>
    );
  }
  
  export default CouponLog;