index.tsx
4.17 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
import React, { useState } from "react";
import { Table, Popconfirm, Row, Button, message, Space, Divider } from "antd";
import { useStore } from "../index";
import * as api from "./api";
import { PlusOutlined } from "@ant-design/icons";
import AddRewardsModal from "../components/AddRewardsModal";
import { RewardsType } from "@/pages/stock/AllowanceConfirm/entity";
const { Column } = Table;
interface Props {
rewardsType: number;
// data: FvmAllowance.RewardsItemList[];
}
function RewardsList(props: Props) {
// const { rewardsType, data } = props;
const { rewardsType } = props;
const {
setParams,
params,
rewardOrder,
disCountOrder,
RewardOrderPagination,
DiscountOrderPagination,
setRewardOrderParams,
setDiscountOrderParams,
rebateId,
readOnly,
} = useStore();
const paginationTypeList = {
1: DiscountOrderPagination,
2: RewardOrderPagination,
};
const tableData = { 1: disCountOrder, 2: rewardOrder };
const [saveLoading, setSaveLoading] = useState(false);
const [visible, setVisible] = useState(false);
// 当前编辑项
const [currentItem, setCurrentItem] = useState({});
function handleDelete(record: api.ListVO) {
setSaveLoading(true);
api
.getDeleteListApi(record.id)
.then((res) => {
message.success("操作成功");
setSaveLoading(false);
fetchList();
})
.catch((e) => {
setSaveLoading(false);
message.error(e.message);
});
}
// 配置
const onEdit = (record: api.ListVO) => {
setVisible(true);
setCurrentItem({ ...record });
};
// 获取奖励、扣款清单
const fetchList = () => {
setDiscountOrderParams({ rebateId, rewardType: 1 }, true);
setRewardOrderParams({ rebateId, rewardType: 2 }, true);
};
return (
<div style={{ marginTop: 100 }}>
<Row justify="space-between" style={{ marginBottom: 20 }}>
<h3>{rewardsType == 1 ? "1、扣款清单" : "2、奖励清单"}</h3>
<Button
type="primary"
icon={<PlusOutlined />}
onClick={() => setVisible(true)}
disabled={readOnly}
>
新增{rewardsType == 1 ? "扣款" : "奖励"}
</Button>
</Row>
<Table
dataSource={tableData[rewardsType]}
pagination={paginationTypeList[rewardsType]}
rowKey="id"
loading={false}
>
<Column title="名称" width="30%" dataIndex="fundsName" align="center" />
<Column
title="类型"
width="30%"
dataIndex="rewardsType"
align="center"
render={(text: number) => (text ? RewardsType[text] : "--")}
/>
<Column
title="实际折让金额(元)"
dataIndex="actualRebateAmount"
align="center"
/>
<Column
title="折让分摊"
align="center"
width={150}
render={(text, record: api.ListVO) => (
<>
<Space>
<Button
type="link"
loading={saveLoading}
onClick={() => onEdit(record)}
>
{/* 配置 */}
{readOnly?'查看':'配置'}
</Button>
<Divider type="vertical" />
<Popconfirm
title={`确定删除【${record.fundsName}】配置?`}
onConfirm={() => handleDelete(record)}
okText="确定"
cancelText="取消"
>
<Button
type="link"
style={{ color: "red" }}
loading={saveLoading}
>
删除
</Button>
</Popconfirm>
</Space>
</>
)}
/>
</Table>
<AddRewardsModal
visible={visible}
onCancel={() => {
setVisible(false);
setCurrentItem({});
}}
currentItem={currentItem}
rewardsType={rewardsType}
dimension={5}
fetchList={() => {
fetchList();
}}
/>
</div>
);
}
export default React.memo(RewardsList);