知与行后台管理端

achieve.jsx 4.1KB

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