index.jsx 7.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. import React, { useState, useEffect } from 'react';
  2. import { PageHeaderWrapper } from '@ant-design/pro-layout';
  3. import { Form, Input, Button, Icon, Select, message, Table, Divider, Tag, Pagination, Modal, Breadcrumb } from 'antd';
  4. import router from 'umi/router';
  5. import moment from 'moment';
  6. import styles from './style.less';
  7. import { fetch, apis } from '../../../utils/request';
  8. import request from '../../../utils/request';
  9. import AuthButton from '@/components/AuthButton';
  10. function header(props) {
  11. const [taNoticeList, setTaNoticeList] = useState([])
  12. const [ data, setData ] = useState({})
  13. useEffect(() => {
  14. getList({ pageNum: 1, pageSize: 10 });
  15. }, [])
  16. // 查询列表
  17. const getList = params => {
  18. request({ ...apis.openScreen.list, params: { ...params } }).then(data => {
  19. setData(data)
  20. })
  21. }
  22. const toEditResource = (id) => () => {
  23. if(id){
  24. router.push({
  25. pathname: '/resource/openScreen/edit',
  26. query: {
  27. id
  28. },
  29. });
  30. }else{
  31. router.push({
  32. pathname: '/resource/openScreen/add',
  33. query: {
  34. id
  35. },
  36. });
  37. }
  38. }
  39. const handleSubmit = (e, props) => {
  40. e.preventDefault();
  41. getList({ pageNum: 1, pageSize: 10, ...props.form.getFieldsValue() });
  42. }
  43. function handleReset() {
  44. props.form.resetFields();
  45. getList({ pageNum: 1, pageSize: 10 });
  46. }
  47. const toDelBatch = rowData => () => {
  48. console.log(taNoticeList, 'taNoticeList')
  49. if (taNoticeList.length < 1) {
  50. message.error('请至少选择一条数据')
  51. return
  52. }
  53. Modal.confirm({
  54. title: '确定删除批次信息吗',
  55. okText: '确定',
  56. cancelText: '取消',
  57. onOk() {
  58. request({ ...apis.openScreen.delete, data: taNoticeList, }).then((data) => {
  59. message.info("操作成功")
  60. getList({ pageNum: 1, pageSize: 10 });
  61. setTaNoticeList([])
  62. }).catch((err) => {
  63. })
  64. },
  65. });
  66. }
  67. const changePageNum = pageNumber => {
  68. getList({ pageNum: pageNumber, pageSize: 10, ...props.form.getFieldsValue() })
  69. }
  70. const columns = [
  71. {
  72. title: '通知标题',
  73. dataIndex: 'title',
  74. key: 'title',
  75. align: 'center',
  76. },
  77. {
  78. title: '通知图',
  79. dataIndex: 'noticeImg',
  80. key: 'noticeImg',
  81. align: 'center',
  82. render: (text, record) => <img style={{width:'140px',height:'92px'}} src={record.noticeImg} className={styles.touxiang} />,
  83. },
  84. {
  85. title: '关联业务类型',
  86. dataIndex: 'targetType',
  87. key: 'targetType',
  88. align: 'center',
  89. },
  90. {
  91. title: '关联业务',
  92. dataIndex: 'targetName',
  93. key: 'targetName',
  94. align: 'center',
  95. },
  96. {
  97. title: '发布状态',
  98. dataIndex: 'status',
  99. key: 'status',
  100. align: 'center',
  101. render: (x, row) => <><span>{row.status === 1 &&moment(row.invalidTime) > moment() ? '是' :'否'}</span></>
  102. },
  103. {
  104. title: '自动下架时间',
  105. dataIndex: 'invalidTime',
  106. key: 'invalidTime',
  107. align: 'center',
  108. render: (x, row) => <><span>{row.invalidTime?`${moment(row.invalidTime).format('YYYY-MM-DD HH:mm:ss')}`:''}</span></>,
  109. },
  110. {
  111. title: '权重',
  112. dataIndex: 'orderNo',
  113. key: 'orderNo',
  114. align: 'center',
  115. },
  116. {
  117. title: '新增时间',
  118. dataIndex: 'createDate',
  119. key: 'createDate',
  120. align: 'center',
  121. render: (x, row) => <><span>{row.createDate?`${moment(row.createDate).format('YYYY-MM-DD HH:mm:ss')}`:''}</span></>,
  122. },
  123. {
  124. title: '操作',
  125. dataIndex: 'handle',
  126. key: 'handle',
  127. align: 'center',
  128. render: (x, row) => (
  129. <>
  130. <span style={{ color: '#FF925C', cursor: 'pointer' }} onClick={toEditResource(row.noticeId)}>
  131. 查看详情<Icon type="form" className={styles.edit} />
  132. </span>
  133. </>
  134. ),
  135. },
  136. ];
  137. const { getFieldDecorator } = props.form
  138. const rowSelection = {
  139. onChange: (selectedRowKeys, selectedRows) => {
  140. console.log('selectedRowKeys:', selectedRowKeys, 'selectedRows: ', selectedRows);
  141. setTaNoticeList(selectedRows)
  142. },
  143. };
  144. return (
  145. <>
  146. <div>
  147. <Form layout="inline" onSubmit={e => handleSubmit(e, props)}>
  148. <Form.Item>
  149. {getFieldDecorator('title')(
  150. <Input
  151. prefix={<Icon type="text" style={{ color: 'rgba(0,0,0,.25)' }} />}
  152. placeholder="通知标题"
  153. />,
  154. )}
  155. </Form.Item>
  156. <Form.Item>
  157. {getFieldDecorator('targetType')(
  158. <Select style={{ width: '180px' }} placeholder="关联业务类型">
  159. <Option value='H5'>H5样例</Option>
  160. </Select>,
  161. )}
  162. </Form.Item>
  163. <Form.Item>
  164. {getFieldDecorator('targetName')(
  165. <Input
  166. prefix={<Icon type="text" style={{ color: 'rgba(0,0,0,.25)' }} />}
  167. placeholder="关联业务"
  168. />,
  169. )}
  170. </Form.Item>
  171. <Form.Item>
  172. {getFieldDecorator('status')(
  173. <Select style={{ width: '180px' }} placeholder="发布状态">
  174. <Option value="">全部</Option>
  175. {/* <Option value="-1">删除</Option> */}
  176. <Option value="0">否</Option>
  177. <Option value="1">是</Option>
  178. </Select>,
  179. )}
  180. </Form.Item>
  181. <Form.Item>
  182. <Button type="primary" htmlType="submit" className={styles.searchBtn}>
  183. 搜索
  184. </Button>
  185. {/* */}
  186. <Button style={{ marginLeft: 8 }} onClick={handleReset}>
  187. 重置
  188. </Button>
  189. </Form.Item>
  190. </Form>
  191. <Button type="danger" className={styles.addBtn} onClick={toEditResource()}>新增</Button>
  192. <Button type="primary" className={styles.addBtn} onClick={toDelBatch()} style={{ marginLeft: '30px' }} >删除</Button>
  193. <Table id='noticeTable' rowSelection={rowSelection} rowKey={r => r.noticeId} dataSource={data.records} columns={columns} pagination={false} />
  194. <div style={{ display: 'flex', justifyContent: 'flex-end', marginTop: '30px' }}>
  195. <Pagination showQuickJumper defaultCurrent={1} total={data.total} onChange={e => changePageNum(e)} current={data.current} />
  196. </div>
  197. </div>
  198. </>
  199. )
  200. }
  201. const WrappedHeader = Form.create({ name: 'header' })(header);
  202. export default WrappedHeader