|
@@ -0,0 +1,115 @@
|
|
1
|
+import React, { useEffect, useState } from 'react'
|
|
2
|
+import { Button, Modal, Table, Form, InputNumber, Input, notification } from 'antd'
|
|
3
|
+import moment from 'moment'
|
|
4
|
+import { fetchList, fetch, apis } from '@/utils/request'
|
|
5
|
+
|
|
6
|
+const getPointsRules = fetchList(apis.integralMall.tdPointsRules)
|
|
7
|
+const getPointsRecords = fetch(apis.customer.taPointsRecords)
|
|
8
|
+const savePointsRecords = fetch(apis.customer.savePointsRecords)
|
|
9
|
+
|
|
10
|
+const otherRules = [
|
|
11
|
+ {code: 'goods', ruleName: '商品兑换'}
|
|
12
|
+]
|
|
13
|
+
|
|
14
|
+const layout = {
|
|
15
|
+ labelCol: { span: 4 },
|
|
16
|
+ wrapperCol: { span: 16 },
|
|
17
|
+};
|
|
18
|
+
|
|
19
|
+const isNvl = x => x === undefined || x === null || x === ''
|
|
20
|
+
|
|
21
|
+export default props => {
|
|
22
|
+ const [loading, setLoading] = useState(false)
|
|
23
|
+ const [showModal, setShowModal] = useState(false)
|
|
24
|
+ const [pointsRules, setPointsRules] = useState([])
|
|
25
|
+ const [listData, setListData] = useState([])
|
|
26
|
+ const [queryParams, setQueryParams] = useState({pageNumber: 1, pageSize: 10})
|
|
27
|
+ const [pagination, setPagination] = useState()
|
|
28
|
+
|
|
29
|
+ const [pointsAmount, setPointsAmount] = useState()
|
|
30
|
+ const [changeType, setChangeType] = useState(false)
|
|
31
|
+
|
|
32
|
+ const getChangeName = typ => {
|
|
33
|
+ const target = pointsRules.filter(x => x.code === typ)[0]
|
|
34
|
+
|
|
35
|
+ return target ? target.ruleName : typ
|
|
36
|
+ }
|
|
37
|
+
|
|
38
|
+ const handleChange = (page) => {
|
|
39
|
+ setQueryParams({
|
|
40
|
+ ...queryParams,
|
|
41
|
+ pageNumber: page.current
|
|
42
|
+ })
|
|
43
|
+ }
|
|
44
|
+
|
|
45
|
+ const handleSubmit = () => {
|
|
46
|
+ if (isNvl(pointsAmount) || isNvl(changeType)) {
|
|
47
|
+ notification.warn({message: '请填写积分或者说明'})
|
|
48
|
+ return
|
|
49
|
+ }
|
|
50
|
+
|
|
51
|
+ setLoading(true)
|
|
52
|
+ savePointsRecords({data: { personId: props.userData.personId, pointsAmount, changeType }}).then(res => {
|
|
53
|
+ setQueryParams({
|
|
54
|
+ ...queryParams,
|
|
55
|
+ pageNumber: 1
|
|
56
|
+ })
|
|
57
|
+ toggleModal()
|
|
58
|
+
|
|
59
|
+ notification.success({message: '积分维护成功'})
|
|
60
|
+ setLoading(false)
|
|
61
|
+ }).catch(e => console.error(e) || setLoading(false) || toggleModal())
|
|
62
|
+ }
|
|
63
|
+
|
|
64
|
+ const toggleModal = () => {
|
|
65
|
+ setShowModal(!showModal)
|
|
66
|
+ setPointsAmount()
|
|
67
|
+ setChangeType()
|
|
68
|
+ }
|
|
69
|
+
|
|
70
|
+ useEffect(() => {
|
|
71
|
+ setLoading(true)
|
|
72
|
+
|
|
73
|
+ const params = {
|
|
74
|
+ urlData: {id: props.userData.personId},
|
|
75
|
+ params: queryParams
|
|
76
|
+ }
|
|
77
|
+
|
|
78
|
+ getPointsRecords(params).then(res => {
|
|
79
|
+ const { records = [], current, total, pageSize } = res.result
|
|
80
|
+ setListData(records)
|
|
81
|
+ setPagination({current, total, pageSize})
|
|
82
|
+ setLoading(false)
|
|
83
|
+ }).catch(e => console.error(e) || setLoading(false))
|
|
84
|
+ }, [queryParams, props.userData])
|
|
85
|
+
|
|
86
|
+ useEffect(() => {
|
|
87
|
+ getPointsRules({pageNum: 1, pageSize: 100}).then(res => {
|
|
88
|
+ const [list] = res
|
|
89
|
+ setPointsRules((list || []).concat(otherRules))
|
|
90
|
+ })
|
|
91
|
+ }, [])
|
|
92
|
+
|
|
93
|
+ return (
|
|
94
|
+ <div>
|
|
95
|
+ <div style={{margin: '16px 0'}}>
|
|
96
|
+ <Button icon="plus" onClick={toggleModal}>积分维护</Button>
|
|
97
|
+ </div>
|
|
98
|
+ <Table loading={loading} dataSource={listData} pagination={pagination} onChange={handleChange} rowKey="pointsRecordId">
|
|
99
|
+ <Table.Column title="类型" dataIndex="changeType" key="changeType" render={t => getChangeName(t)} />
|
|
100
|
+ <Table.Column title="积分" dataIndex="pointsAmount" key="pointsAmount" render={t => getChangeName(t)} />
|
|
101
|
+ <Table.Column title="日期" dataIndex="createDate" key="createDate" render={t => moment(t).format('YYYY-MM-DD HH:mm')} />
|
|
102
|
+ </Table>
|
|
103
|
+ <Modal visible={showModal} title="积分维护" onOk={handleSubmit} onCancel={toggleModal}>
|
|
104
|
+ <Form {...layout}>
|
|
105
|
+ <Form.Item label="积分" required>
|
|
106
|
+ <InputNumber placeholder="负值代表消费积分" step={1} value={pointsAmount} style={{width: '100%'}} onChange={e => setPointsAmount(e - 0)}></InputNumber>
|
|
107
|
+ </Form.Item>
|
|
108
|
+ <Form.Item label="说明" required>
|
|
109
|
+ <Input placeholder="填写消费说明" value={changeType} onChange={e => setChangeType(e.target.value)}></Input>
|
|
110
|
+ </Form.Item>
|
|
111
|
+ </Form>
|
|
112
|
+ </Modal>
|
|
113
|
+ </div>
|
|
114
|
+ )
|
|
115
|
+}
|