index.tsx
4.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import React, { useState, useEffect } from "react";
import { Button, Card, Form, message, Modal, Spin } from "antd";
import FullReduce from "@/pages/coupon/CouponConfig/components/FullReduce";
import * as api from "./api";
interface Props extends MktConponSpace.CouponProps {
}
export default function UpsertCoupon({ visible, onCancel, onSave, remark, disabled, confNo, limitCoupon, carSelectApi, expires, expiresDay, getCouponDetailsApi, ...others }: Props) {
const [form] = Form.useForm();
const [info, setInfo] = useState<MktConponSpace.ConListParams>({} as MktConponSpace.ConListParams);
const [loading, setLoading] = useState<boolean>(false);
const [saveLoading, setSaveLoading] = useState<boolean>(false);
useEffect(() => {
if (!confNo) {
return;
}
getDetails(confNo);
}, [confNo]);
function getDetails(no: string) {
setLoading(true);
const detailApi = getCouponDetailsApi || api.fetchCasView;
detailApi(no).then((res) => {
const data = res.data || {} as any;
setInfo(data);
form.setFieldsValue({
...data,
expires: expiresDay,
classifyCode: data.classifyCode ? { value: data.classifyCode, label: data.classifyName } : undefined,
exchangeTypeId: data.exchangeTypeId ? { value: data.exchangeTypeId, label: data.exchangeTypeName } : undefined,
orgList: data.orgList ? data.orgList.map((i) => ({ value: i.orgId, label: i.orgName })) : undefined,
amsCode: data.amsCode ? [{ code: data.amsCode, name: data.amsName, spec: data.amsSpec }] : undefined,
});
setLoading(false);
}).catch((e) => {
setLoading(false);
message.error(e.message);
});
}
function deleteItem() {
Modal.confirm({
title: `优惠券删除后不可恢复,是否删除该优惠券配置?`,
okText: "确定",
okType: "danger",
cancelText: "取消",
onOk: () => {
api
.deleteConfigList(confNo)
.then((res) => {
message.success("删除成功");
onSave && onSave();
})
.catch((e) => {
message.error(e.message);
});
},
});
}
function formSubmit(fields?: any) {
form.validateFields().then((fields) => {
const params = {
id: info.id,
confNo: info.confNo,
...fields,
orgList: fields.orgList ? fields.orgList.map((i: { value: any; label: any }) => ({ orgId: i.value, orgName: i.label })) : [],
classifyCode: fields.classifyCode.value,
classifyName: fields.classifyCode.label,
exchangeTypeId: fields.exchangeTypeId && fields.exchangeTypeId.value,
exchangeTypeName: fields.exchangeTypeId && fields.exchangeTypeId.label,
schemeList: fields.schemeList ? fields.schemeList.map((i: MktConponSpace.LimitList) => ({ ...i, externalRely: i.externalRely || false })) : [],
amsCode: fields.amsCode && fields.amsCode.map((i: { code: string; }) => i.code).join(','),
remark,
};
setSaveLoading(true);
const saveApi = others.saveChangeCouponApi || api.saveConpon;
saveApi(params)
.then((res) => {
const result = {
...res,
confNo: res.data && res.data.confNo || info.confNo,
classifyCode: res.data && res.data.classifyCode,
classifyName: params.classifyName,
exchangeTypeId: params.exchangeTypeId,
exchangeTypeName: params.exchangeTypeName,
aliasName: params.aliasName,
amount: params.amount,
orgType: params.orgType,
discountsType: info.discountsType,
expires: params.expires,
// aliasName: params.aliasName,
};
message.success("保存成功");
setInfo({});
onCancel();
form.resetFields();
onSave && onSave(result);
setSaveLoading(false);
})
.catch((e) => {
message.error(e.message);
setSaveLoading(false);
});
});
}
return (
<Modal
title="优惠券配置"
visible={visible}
width="60%"
afterClose={() => form.resetFields()}
confirmLoading={loading || saveLoading}
onOk={formSubmit}
footer={disabled && !others.changeEditKeys ? false : undefined}
onCancel={() => { onCancel(); setInfo({}); }}
>
<Card>
<Spin spinning={loading}>
<FullReduce
{...others}
limitCoupon={limitCoupon}
info={info}
readonly={!!disabled}
confNo={confNo}
form={form}
carSelectApi={carSelectApi}
expires={expires}
getCouponType={(pa: number) => {
setInfo({ ...info, discountsType: pa });
}}
/>
</Spin>
</Card>
</Modal>
);
}