SignupGifts.tsx
6.76 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
import React, { useEffect, useState } from 'react';
import { Button, Card, message, Popconfirm, Space, Table } from 'antd';
import { PlusOutlined } from '@ant-design/icons';
import { useStore } from "@/pages/mkt/ActivityCreate/index";
import UpsertCoupon from "@/pages/coupon/CouponConfig";
import { getCouponChangeDetails, saveChangeCoupon, saveChangeGift } from '../../api';
const { Column } = Table;
// 门店范围
enum ShopLimit {
"发券门店" = 1,
"自定义门店",
}
interface Props {
value?: ExternalPromotion.Gifts,
onChange?: Function,
disabled?: boolean,
}
interface Coupon {
visible: boolean;
index?: number;
confNo?: string;
giftItemId?: number;
}
function SignupGifts({ value, onChange, disabled }: Props) {
const { baseInfo, readOnly, getFlowConfig, getACarList } = useStore();
const { bizType, changeEnable, activityNo } = baseInfo;
const [giftList, setGiftList] = useState<ExternalPromotion.giftItems[]>([]);
const [coupon, setCoupon] = useState<Coupon>({ visible: false, index: undefined, confNo: undefined });
/**优惠券创建状态 */
const couponStatus = changeEnable && !coupon.giftItemId && coupon.confNo;
useEffect(() => {
value && value[0].giftItems && setGiftList(value[0].giftItems);
}, [value]);
function onSave(v: any) {
const currentData = [...giftList];
const pa: ExternalPromotion.giftItems = {
...v,
relySchemeType: v.data && v.data.relySchemeList.length
? v.data.relySchemeList[0]
: 0,
couponCode: v.confNo,
giftType: v.classifyCode,
giftName: v.classifyName,
discountsAmount: v.amount,
data: undefined,
};
if (coupon.confNo) {
//编辑
let tempObj = currentData.find((item) => item.couponCode === coupon.confNo);
tempObj = { ...pa };
const _tempDataSource = currentData.map((item) => (item.couponCode === tempObj.couponCode ? tempObj : item));
setGiftList(_tempDataSource);
onChange && onChange([{ ...value && value[0], giftItems: _tempDataSource }]);
} else {
// 新增优惠券
currentData.push(pa);
setGiftList(currentData);
onChange && onChange([{ ...value && value[0], giftItems: currentData }]);
}
setCoupon({ ...coupon, visible: false, confNo: undefined, giftItemId: undefined });
}
function deleteQestion(i: number) {
const currentData = [...giftList];
currentData.splice(i, 1);
setGiftList([...currentData]);
onChange && onChange([{ ...value && value[0], giftItems: currentData }]);
}
return (
<div>
<Card
style={{ display: "block" }}
extra={
(!disabled || changeEnable) && (
<div
style={{
flex: 1,
display: "flex",
justifyContent: "space-between",
flexDirection: "row",
}}
>
<Button
type="link"
icon={<PlusOutlined />}
disabled={disabled && !changeEnable}
onClick={() => setCoupon({
...coupon,
visible: true,
confNo: undefined,
})}
>
新增
</Button>
</div>
)
}
>
<Table
bordered
dataSource={giftList}
rowKey={(record: ExternalPromotion.giftItems, index?: number) => record.classifyCode || record.couponCode}
>
<Column
title="优惠券类型"
dataIndex="giftName"
key="giftType"
width="6%"
/>
<Column
title="优惠券别名"
dataIndex="aliasName"
key="orgType"
width="10%"
render={(text: string) => <span>{text || "--"}</span>}
/>
<Column
title="金额"
dataIndex="discountsAmount"
key="discountsAmount"
width="4%"
/>
<Column
title="使用条件"
dataIndex="orgType"
key="orgType"
width="10%"
render={(text: number) => (
<span>{text ? ShopLimit[text] : "--"}</span>
)}
/>
<Column
title="操作"
width="4%"
render={(
text,
record: ExternalPromotion.giftItems,
index: number
) => (
disabled && !changeEnable ? (
<>
<Button type="link" onClick={() => setCoupon({ ...coupon, visible: true, confNo: record.couponCode })}>查看</Button>
{/* {record.giftItemId && (
<Popconfirm title="是否确定替换该优惠券,已发放优惠券不受影响,将在审批通过后生效" onConfirm={() => setCoupon({ ...coupon, visible: true, giftItemId: record.giftItemId })}>
{!!changeEnable && <Button type="link" style={{ margin: 0, fontSize: 12 }} danger>替换后续发放优惠券</Button>}
</Popconfirm>
)} */}
</>
) : (
<Space>
<Button
type="link"
// disabled={disabled}
onClick={() => {
setCoupon({
...coupon,
visible: true,
confNo: record.couponCode,
});
}}
>
编辑
</Button>
<Popconfirm
title="删除将丢失优惠券信息,确定删除?"
okText="确定"
cancelText="取消"
onConfirm={() => deleteQestion(index)}
>
<Button type="link" danger>
删除
</Button>
</Popconfirm>
</Space>
)
)}
/>
</Table>
</Card>
<UpsertCoupon
visible={coupon.visible}
onCancel={() => setCoupon({ ...coupon, visible: false, confNo: undefined, giftItemId: undefined })}
disabled={coupon.giftItemId ? false : disabled && !changeEnable}
onSave={onSave}
remark="市场活动"
confNo={coupon.confNo}
carSelectApi={bizType == 1 ? getACarList : undefined}
changeEditKeys={couponStatus ? ["aliasName", "schemeList"] : undefined}
getCouponDetailsApi={couponStatus ? (v: string) => getCouponChangeDetails({ activityNo, confNo: v }) : undefined}
saveChangeCouponApi={couponStatus ? (values: any) => saveChangeCoupon({ ...values, activityNo }) : undefined}
/>
</div>
);
}
export default React.memo(SignupGifts);