知与行后台管理端

Detail.jsx 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. import React, { useState, useEffect } from 'react';
  2. import { Form, Input, Button, Icon, Select, message, Table, Divider, Tag, Pagination, Modal, DatePicker } from 'antd';
  3. import router from 'umi/router';
  4. import { FormattedMessage } from 'umi-plugin-react/locale';
  5. import styles from '../../style/GoodsList.less';
  6. import moment from 'moment';
  7. import apis from '../../../services/apis';
  8. import request from '../../../utils/request';
  9. import { SSL_OP_SSLEAY_080_CLIENT_DH_BUG } from 'constants';
  10. import AuthButton from '../../../components/AuthButton';
  11. import { timeout } from 'q';
  12. const data = []
  13. const header = (props) => {
  14. const { drainageId, name } = props.location.query
  15. const [datas, setDatas] = useState([])
  16. const [content, setContent] = useState([{}, {}])
  17. const [columns, setColumns] = useState([])
  18. const [startDate, setStartDate] = useState('')
  19. const [endDate, setEndDate] = useState('')
  20. const [total, setTotal] = useState({})
  21. // let content = {}
  22. useEffect(() => {
  23. gettaDrainageRecord({ pageNum: 1, pageSize: 10, drainageId: drainageId })
  24. }, [])
  25. function gettaDrainageRecord (params) {
  26. request({ ...apis.activity.taDrainageRecord, params: { ...params } }).then((data) => {
  27. // setDatas(data)
  28. console.log(data, '3333333333333')
  29. if (data.total != 0) {
  30. setTotal(data)
  31. setDatas(tableData(data.records))
  32. // content = data.records[0]
  33. console.log('json: ', eval('(' + data.records[0].content + ')'))
  34. setContent(eval('(' + data.records[0].content + ')'))
  35. setColumns(tableTitle(data.records))
  36. }
  37. else {
  38. setDatas([])
  39. message.info('数据为空')
  40. }
  41. }).catch((err) => {
  42. console.log(err)
  43. message.info(err.msg || err.message)
  44. })
  45. }
  46. function tableData (data) {
  47. console.log('tabledata', data)
  48. return data.map((row, inx) => {
  49. return eval('(' + row.content + ')').reduce((acc, col) => {
  50. const r = {
  51. key: inx + 1,
  52. createDate: row.createDate,
  53. [`${col.key}`]: col.value,
  54. ...acc,
  55. }
  56. console.log('r', r)
  57. return r
  58. }, {})
  59. })
  60. }
  61. function tableTitle (data) {
  62. tableTitle = eval('(' + data[0].content + ')')
  63. const cols = [{
  64. title: "提交时间",
  65. dataIndex: "createDate",
  66. key: "createDate",
  67. render: (x, row) => <><span>{`${moment(row.createDate).format('YYYY-MM-DD HH:mm:ss')}`}</span></>,
  68. }]
  69. return cols.concat(tableTitle.map((item) => {
  70. const col = {
  71. title: item.label,
  72. dataIndex: item.key,
  73. key: item.key
  74. }
  75. return col
  76. }))
  77. }
  78. // function datalist () {
  79. // gettaDrainageRecord({ pageNum: 1, pageSize: 10, drainageId: drainageId, startTime: Time(startDate), endTime: Time(endDate) })
  80. // }
  81. function fromTime (str) {
  82. return str === '' ? null : `${moment(str).format('YYYY-MM-DDT00:00:00.000')}Z`
  83. }
  84. function Time (str) {
  85. return str === '' ? null : `${moment(str).format('YYYY-MM-DD')}`
  86. }
  87. // 2019-10-30T11:04:49
  88. function onChangetime (dates, dateStrings) {
  89. console.log(dateStrings[1])
  90. setEndDate(dateStrings[1])
  91. setStartDate(dateStrings[0])
  92. }
  93. const changePageNum = pageNumber => {
  94. gettaDrainageRecord({ pageNum: pageNumber, pageSize: 10, drainageId: drainageId, startTime: Time(startDate), endTime: Time(endDate) })
  95. }
  96. function excelPort () {
  97. // const fieldsValue = getFieldsValue()
  98. request({ ...apis.activity.exporttaDrainageRecord, params: { drainageId: drainageId, startTime: fromTime(startDate), endTime: fromTime(endDate) } })
  99. .then(response => {
  100. download(response)
  101. }).catch(error => {
  102. })
  103. }
  104. function download (data) {
  105. if (!data) {
  106. return
  107. }
  108. const url = window.URL.createObjectURL(new Blob([data]))
  109. const link = document.createElement('a')
  110. link.style.display = 'none'
  111. link.href = url
  112. link.setAttribute('download', '引流.xlsx')
  113. document.body.append(link)
  114. link.click()
  115. }
  116. function handleReset (e) {
  117. console.log(e)
  118. props.form.resetFields();
  119. }
  120. const handleSubmit = (e, props) => {
  121. e.preventDefault();
  122. gettaDrainageRecord({ pageNum: 1, pageSize: 10, drainageId: drainageId, startTime: Time(startDate), endTime: Time(endDate) })
  123. }
  124. const { RangePicker } = DatePicker;
  125. const { getFieldDecorator } = props.form
  126. return (
  127. <>
  128. <Form layout="inline" onSubmit={e => handleSubmit(e, props)}>
  129. <Form.Item>
  130. {getFieldDecorator('time')(
  131. <RangePicker showTime format="YYYY-MM-DD"
  132. showTime
  133. onChange={onChangetime}
  134. />,
  135. )}
  136. </Form.Item>
  137. <Form.Item>
  138. <Button type="primary" htmlType="submit" >
  139. 搜索
  140. </Button>
  141. <Button style={{ marginLeft: 8 }} onClick={handleReset}>
  142. 重置
  143. </Button>
  144. </Form.Item>
  145. </Form>
  146. <div>
  147. <div style={{ display: 'flex', justifyContent: 'space-between' }}>
  148. <div style={{ lineHeight: '92px', width: '600px', fontWeight: 'bold', fontSize: '18px' }}>
  149. H5项目:{name}
  150. </div>
  151. {/* H5项目名称 style={{ float: 'right', margin: '20px 0', zIndex: 1 }} */}
  152. <AuthButton name="admin.taDrainageRecord.export.get" noRight={null}>
  153. <Button type="primary" style={{ marginLeft: '30px', float: 'right', marginTop: '30px', marginBottom: '30px', zIndex: 1 }} onClick={excelPort}>导出数据</Button>
  154. </AuthButton>
  155. </div>
  156. <Table columns={columns} dataSource={datas} pagination={false} />
  157. <div style={{ display: 'flex', justifyContent: 'flex-end', marginTop: '30px' }}>
  158. <Pagination showQuickJumper defaultCurrent={1} total={total.total} onChange={(e) => changePageNum(e)} current={total.current} />
  159. </div>
  160. </div>
  161. </>
  162. )
  163. }
  164. const WrappedHeader = Form.create({ name: 'header' })(header);
  165. export default WrappedHeader