h5Sample.jsx 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. import React, { useState, useEffect } from 'react';
  2. import { PageHeaderWrapper } from '@ant-design/pro-layout';
  3. import { Form, Pagination, Button, Icon, message, Modal, Table, Input, } from 'antd';
  4. import router from 'umi/router';
  5. import moment from 'moment';
  6. import className from 'classnames';
  7. import Cell from '../../../components/Cell';
  8. import styles from './style.less';
  9. import { fetch, apis } from '../../../utils/request';
  10. import request from '../../../utils/request';
  11. import AuthButton from '@/components/AuthButton';
  12. function header(props) {
  13. // 获取初始化数据
  14. const [data, setData] = useState({})
  15. const [demandIdList, setDemandIdList] = useState([])
  16. useEffect(() => {
  17. getList({ pageNum: 1, pageSize: 10 });
  18. }, [])
  19. // 查询列表
  20. const getList = (params) => {
  21. request({ ...apis.sample.list, params: { ...params } }).then((data) => {
  22. console.log(data)
  23. setData(data)
  24. })
  25. }
  26. // 提交事件
  27. const handleSubmit = (e, props) => {
  28. e.preventDefault();
  29. props.form.validateFields((err, values) => {
  30. if (!err) {
  31. let { createDate, ...submitValue } = values
  32. if (null != createDate && createDate.length > 0) {
  33. const [startCreateDate, endCreateDate] = createDate
  34. submitValue.startCreateDate = moment(startCreateDate).format('YYYY-MM-DD');
  35. submitValue.endCreateDate = moment(endCreateDate).format('YYYY-MM-DD');
  36. } else {
  37. submitValue.startCreateDate = null
  38. submitValue.endCreateDate = null
  39. }
  40. getList({ pageNum: 1, pageSize: 10, ...submitValue })
  41. }
  42. });
  43. }
  44. const changePageNum = (pageNumber) => {
  45. let { createDate, ...submitValue } = props.form.getFieldsValue()
  46. if (null != createDate && createDate.length > 0) {
  47. const [startCreateDate, endCreateDate] = createDate
  48. submitValue.startCreateDate = moment(startCreateDate).format('YYYY-MM-DD');
  49. submitValue.endCreateDate = moment(endCreateDate).format('YYYY-MM-DD');
  50. } else {
  51. submitValue.startCreateDate = null
  52. submitValue.endCreateDate = null
  53. }
  54. getList({ pageNum: pageNumber, pageSize: 10, ...submitValue })
  55. }
  56. /**
  57. *
  58. *
  59. * @param {*} props
  60. * @returns
  61. */
  62. const columns = [
  63. {
  64. title: '模板编号',
  65. dataIndex: 'sampleName',
  66. key: 'sampleName',
  67. align: 'center',
  68. },
  69. {
  70. title: '模板名称',
  71. dataIndex: 'orgName',
  72. key: 'orgName',
  73. align: 'center',
  74. },
  75. {
  76. title: '创建时间',
  77. dataIndex: 'createDate',
  78. key: 'createDate',
  79. align: 'center',
  80. render: (x, row) => <><span>{`${moment(row.createDate).format('YYYY-MM-DD HH:mm:ss')}`}</span></>,
  81. },
  82. ];
  83. function handleReset() {
  84. props.form.resetFields();
  85. getList({ pageNum: 1, pageSize: 10 })
  86. }
  87. const { getFieldDecorator } = props.form
  88. return (
  89. <>
  90. <Form layout="inline" onSubmit={e => handleSubmit(e, props)} style={{marginBottom:'16px'}}>
  91. <Form.Item>
  92. {getFieldDecorator('sampleName')(
  93. <Input
  94. prefix={<Icon type="text" style={{ color: 'rgba(0,0,0,.25)' }} />}
  95. placeholder="样例名"
  96. />,
  97. )}
  98. </Form.Item>
  99. <Form.Item>
  100. <Button type="primary" htmlType="submit" className={styles.searchBtn}>
  101. 搜索
  102. </Button>
  103. <Button style={{ marginLeft: 8 }} onClick={handleReset}>
  104. 重置
  105. </Button>
  106. </Form.Item>
  107. </Form>
  108. <Table rowKey="newsType" dataSource={data.records} columns={columns} pagination={false} />
  109. <div style={{ display: 'flex', justifyContent: 'flex-end', marginTop: '30px' }}>
  110. <Pagination showQuickJumper defaultCurrent={1} total={data.total} onChange={changePageNum} current={data.current} />
  111. </div>
  112. </>
  113. )
  114. }
  115. const WrappedHeader = Form.create({ name: 'header' })(header);
  116. export default WrappedHeader