瀏覽代碼

积分商城

傅行帆 5 年之前
父節點
當前提交
727ffaeffd
共有 1 個檔案被更改,包括 115 行新增67 行删除
  1. 115
    67
      src/pages/integralMall/achieve.jsx

+ 115
- 67
src/pages/integralMall/achieve.jsx 查看文件

@@ -1,86 +1,134 @@
1
-import React from 'react';
2
-import { Form, Input, Button, Icon, Tabs, Row, Col, Table } from 'antd';
1
+import React, { useState, useEffect } from 'react';
2
+import { Form, Input, Button, Icon, Tabs, Row, Col, Table, Pagination, Alert, message } from 'antd';
3 3
 import { FormattedMessage } from 'umi-plugin-react/locale';
4 4
 import styles from '../style/GoodsList.less';
5 5
 import router from 'umi/router';
6
-
6
+import moment from 'moment';
7
+import BuildSelect from '../../components/SelectButton/BuildSelect'
8
+import request from '../../utils/request'
7 9
 
8 10
 const { TabPane } = Tabs;
9
-function callback(key) {
10
-  console.log(key);
11
+
12
+
13
+
14
+
15
+function header(props) {
16
+  const [ carType, setCarType ] = useState({})
17
+  const callback = (key) => {
18
+    setCarType(key)
19
+    getList({ pageNum: 1, pageSize: 10 , type: key});
20
+  }
21
+  
22
+// 获取初始化数据
23
+const [ data, setData ] = useState({})
24
+
25
+useEffect(() => {
26
+  getList({ pageNum: 1, pageSize: 10 , type: 'platform'});
27
+},[])
28
+
29
+// 查询列表
30
+const getList = (params) => {
31
+  request({
32
+      url: '/api/admin/tdPointsRules',
33
+      method: 'GET',
34
+      params: { ...params },
35
+  }).then((data) => {
36
+      console.log(data)
37
+      setData(data)
38
+  })
11 39
 }
12 40
 
13
-/**
14
- *
15
- *
16
- * @param {*} props
17
- * @returns
18
- */
19
-const dataSource = [
20
-  {
21
-    key: '1',
22
-    img: 'http://img0.imgtn.bdimg.com/it/u=4246326797,2657995307&fm=26&gp=0.jpg',
23
-    name: '华为P30 Pro',
24
-  },
25
-  {
26
-    key: '2',
27
-    img: '',
28
-    name: '大米',
29
-  },
30
-];
41
+const changePageNum = (pageNumber) => {
42
+  getList({ pageNum: pageNumber, pageSize: 10, type: carType })
43
+}
31 44
 
32
-const columns = [
33
-  {
34
-    title: '类型',
35
-    dataIndex: 'type',
36
-    key: 'type',
37
-    align: 'center',
38
-  },
39
-  {
40
-    title: '获取积分',
41
-    dataIndex: 'intergral',
42
-    key: 'intergral',
43
-    align: 'center',
44
-  },
45
-  {
46
-    title: '状态',
47
-    dataIndex: 'state',
48
-    key: 'state',
49
-    align: 'center',
50
-  },
51
-  {
52
-    title: '说明',
53
-    dataIndex: 'desc',
54
-    key: 'desc',
55
-    align: 'center',
56
-  },
57
-  {
58
-    title: '操作时间',
59
-    dataIndex: 'time',
60
-    key: 'time',
61
-    align: 'center',
62
-  },
63
-  {
64
-    title: '操作',
65
-    dataIndex: 'handle',
66
-    key: 'handle',
67
-    align: 'center',
68
-    render: () => <><span style={{ color: '#EF273A', marginRight: '20px' }} >停用<Icon type="stop" className={styles.shoppingCart} /></span><span style={{ color: '#EF273A', marginRight: '20px' }} >启用<Icon type="check-circle" className={styles.shoppingCart} /></span><span style={{ color: '#FF925C' }}>编辑<Icon type="form" className={styles.edit} /></span></>,
69
-  },
70 45
 
71
-];
46
+  // 提交事件
47
+  const handleSubmit = (e, props) => {
48
+    e.preventDefault();
49
+    props.form.validateFields((err, values) => {
50
+      if (!err) {
51
+        getList({ pageNum: 1, pageSize: 10, ...values, type: carType})
52
+      }
53
+    });
54
+  }
72 55
 
56
+  const changeStatus = (row) => () => {
57
+    request({
58
+      url: '/api/admin/tdPointsRules/change',
59
+      method: 'PUT',
60
+      data: { ...row },
61
+    }).then((data) => {
62
+      message.info('操作成功!')
63
+      getList({ pageNum: 1, pageSize: 10, type: carType})
64
+    })
65
+  }
66
+
67
+const columns = [
68
+    {
69
+      title: '类型',
70
+      dataIndex: 'ruleName',
71
+      key: 'ruleName',
72
+      align: 'center',
73
+    },
74
+    {
75
+      title: '获取积分',
76
+      dataIndex: 'pointsAmount',
77
+      key: 'pointsAmount',
78
+      align: 'center',
79
+    },
80
+    {
81
+      title: '状态',
82
+      dataIndex: 'status',
83
+      key: 'status',
84
+      align: 'center',
85
+      render: (status) => <span>{status == 1 ? '启用' : '停用'}</span>
86
+    },
87
+    {
88
+      title: '操作时间',
89
+      dataIndex: 'updateDate',
90
+      key: 'updateDate',
91
+      align: 'center',
92
+      render: (updateDate) => <><span>{updateDate != null ? moment(updateDate).format('YYYY-MM-DD') : ''}</span></>
93
+    },
94
+    {
95
+      title: '操作',
96
+      dataIndex: 'handle',
97
+      key: 'handle',
98
+      align: 'center',
99
+      render: (x,row) => <><span style={{ color: '#EF273A', marginRight: '20px' }} onClick={changeStatus(row)}>{row.status == 1?'停用':'启用'}<Icon type="stop" className={styles.shoppingCart} /></span>
100
+                      <span style={{ color: '#FF925C' }}>{row.buildingId != null ? '编辑'`${<Icon type="form" className={styles.edit} />}` : ''}</span></>,
101
+    },
102
+  ];
73 103
 
74
-function header(props) {
75 104
   const { getFieldDecorator } = props.form
76 105
   return (
77 106
     <>
78 107
       <Tabs onChange={callback} type="card">
79
-        <TabPane tab="平台积分" key="1">
80
-          <Table style={{ marginTop: '40px' }} dataSource={dataSource} columns={columns} />
108
+        <TabPane tab="平台积分" key="platform">
109
+          <Table style={{ marginTop: '40px' }} dataSource={data.records} columns={columns} pagination={false}/>
110
+          <div style={{ display: 'flex', justifyContent: 'flex-end', marginTop: '30px' }}>
111
+            <Pagination showQuickJumper defaultCurrent={1} total={data.total} onChange={changePageNum} />
112
+          </div>
81 113
         </TabPane>
82
-        <TabPane tab="项目积分" key="2">
83
-          <Table style={{ marginTop: '40px' }} dataSource={dataSource} columns={columns} />
114
+        <TabPane tab="项目积分" key="project">
115
+        <Form layout="inline" onSubmit={e => handleSubmit(e, props)}>
116
+            <Form.Item>
117
+              {getFieldDecorator('buildingId')(
118
+                <BuildSelect />,
119
+              )}
120
+            </Form.Item>
121
+             
122
+            <Form.Item>
123
+              <Button type="primary" htmlType="submit" className={styles.searchBtn}>
124
+                搜索
125
+              </Button>
126
+            </Form.Item>
127
+          </Form>
128
+          <Table style={{ marginTop: '40px' }} dataSource={data.records} columns={columns} pagination={false}/>
129
+          <div style={{ display: 'flex', justifyContent: 'flex-end', marginTop: '30px' }}>
130
+            <Pagination showQuickJumper defaultCurrent={1} total={data.total} onChange={changePageNum} />
131
+          </div>
84 132
         </TabPane>
85 133
       </Tabs>,
86 134
     </>