知与行后台管理端

ActivityList.jsx 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  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 { FormattedMessage } from 'umi-plugin-react/locale';
  4. import router from 'umi/router';
  5. import moment from 'moment';
  6. import styles from '../style/GoodsList.less';
  7. import SelectCity from '../../components/SelectButton/CitySelect'
  8. import BuildSelect from '../../components/SelectButton/BuildSelect'
  9. import apis from '../../services/apis';
  10. import request from '../../utils/request';
  11. import AuthButton from '@/components/AuthButton';
  12. const { Option } = Select;
  13. const { MonthPicker, RangePicker, WeekPicker } = DatePicker;
  14. const header = props => {
  15. // eslint-disable-next-line react-hooks/rules-of-hooks
  16. const [data, setData] = useState({ list: [], total: 0 })
  17. // const [page, changePage] = useState({})
  18. const [time, setTime] = useState('')
  19. // 查询列表
  20. const getList = params => {
  21. request({ ...apis.activity.list, params: { ...params } }).then(data => {
  22. console.log(data)
  23. setData(data)
  24. })
  25. }
  26. // eslint-disable-next-line react-hooks/rules-of-hooks
  27. useEffect(() => {
  28. getList({ pageNum: 1, pageSize: 10 });
  29. }, [])
  30. // 跳转到编辑商品
  31. const toEditGoods = dynamicId => () => {
  32. router.push({
  33. pathname: '/activity/editActivity',
  34. query: {
  35. dynamicId,
  36. },
  37. });
  38. }
  39. const newQrcode = row => {
  40. const x = new XMLHttpRequest();
  41. const resourceUrl = row.qrCode
  42. x.open('GET', resourceUrl, true);
  43. x.responseType = 'blob';
  44. x.onload = function (e) {
  45. const url = window.URL.createObjectURL(x.response)
  46. const a = document.createElement('a');
  47. a.href = url;
  48. a.style.display = 'none'
  49. a.download = '活动二维码.png';
  50. a.click();
  51. }
  52. x.send();
  53. }
  54. /**
  55. *
  56. *
  57. * @param {*} props
  58. * @returns
  59. */
  60. const columns = [
  61. {
  62. title: '活动标题',
  63. dataIndex: 'title',
  64. key: 'title',
  65. align: 'center',
  66. // width: '15%',
  67. render: (x, row) => <><div style={{overflow: 'hidden',textOverflow: 'ellipsis',whiteSpace: 'nowrap', width: '201px',title:'content'}}>{row.title}</div></>,
  68. // width: '300px',
  69. // ellipsis:'true'overflow: hidden; /*溢出隐藏*/
  70. // text-overflow: ellipsis; /*以省略号...显示*/
  71. // white-space: nowrap;
  72. },
  73. {
  74. title: '活动时间',
  75. dataIndex: 'startDate',
  76. key: 'startDate',
  77. align: 'center',
  78. // width: '15%',
  79. // width: '20%',
  80. render: (x, row) => <><span>{`${moment(row.startDate).format('YYYY-MM-DD')} —— ${moment(row.endDate).format('YYYY-MM-DD')}`}</span></>,
  81. },
  82. {
  83. title: '已参加人数',
  84. dataIndex: 'count',
  85. key: 'count',
  86. align: 'center',
  87. // width: '10%',
  88. // width: '6%',
  89. },
  90. {
  91. title: '阅读量',
  92. dataIndex: 'pvNum',
  93. key: 'pvNum',
  94. align: 'center',
  95. // width: '10%',
  96. },
  97. {
  98. title: '转发量',
  99. dataIndex: 'shareNum',
  100. key: 'shareNum',
  101. align: 'center',
  102. // width: '10%',
  103. },
  104. {
  105. title: '收藏数',
  106. dataIndex: 'saveNum',
  107. key: 'saveNum',
  108. align: 'center',
  109. // width: '10%',
  110. },
  111. {
  112. title: '报名状态',
  113. dataIndex: 'activityStatus',
  114. key: 'activityStatus',
  115. align: 'center',
  116. // width: '10%',
  117. render: activityStatus => <><span>{activityStatus == 0 ? '进行中' : activityStatus == 1 ? '未开始' : '已结束'}</span></>,
  118. },
  119. {
  120. title: '权重',
  121. dataIndex: 'heavy',
  122. key: 'heavy',
  123. align: 'center',
  124. },
  125. {
  126. title: '操作',
  127. dataIndex: 'handle',
  128. key: 'handle',
  129. align: 'center',
  130. render: (x, row) => (
  131. <>
  132. <AuthButton name="admin.SignList.get" noRight={null}>
  133. {(row.activityStatus === 0 || row.activityStatus === 2) && <span style={{ color: '#1990FF',marginRight: '20px', cursor: 'pointer' }} onClick={getSignList.bind(this, row.dynamicId)}>{row.isEnlist == '1' ? '报名记录' : ''}{ (row.isEnlist==1) && <Icon type="snippets" className={styles.shoppingCart} />}</span>}
  134. </AuthButton>
  135. <AuthButton name="admin.buildingDynamic.send.dynamicId.put" noRight={null}>
  136. <span style={{ color: '#1990FF',marginRight: '20px', cursor: 'pointer' }} onClick={sendOrPublicDynamic.bind(this, row)}>{row.status === 1 ? '取消发布' : '发布'}<Icon type="close-circle" className={styles.edit} /></span>
  137. </AuthButton>
  138. <AuthButton name="admin.buildingDynamic.finish.put" noRight={null}>
  139. {row.activityStatus === 0 && <span style={{ color: '#1990FF',marginRight: '20px', cursor: 'pointer' }} onClick={finishDynamic.bind(this, row)}>结束活动<Icon type="poweroff" className={styles.edit} /></span>}
  140. </AuthButton>
  141. <AuthButton name="admin.buildingDynamic.update.put" noRight={null}>
  142. <span style={{ color: '#1990FF', marginRight: '20px', cursor: 'pointer' }} onClick={topDynamic(row)}>{row.weight === 1 ? '取消标签' : '添加标签'}<Icon type="vertical-align-top" className={styles.edit} /></span>
  143. {(row.activityStatus === 0 || row.activityStatus === 1) && <span style={{ color: '#FF925C',marginRight: '20px', cursor: 'pointer' }} onClick={toEditGoods(row.dynamicId)}>编辑<Icon type="form" className={styles.edit} /></span>}
  144. </AuthButton>
  145. {(row.activityStatus === 0 || row.activityStatus === 2) &&<span style={{ color: '#1990FF', marginRight: '20px', cursor: 'pointer' }} onClick={newQrcode.bind(this, row)}>{row.isEnlist === 1 && '下载二维码'} {row.isEnlist === 1 && <Icon type="qrcode" className={styles.shoppingCart} />}</span>}
  146. </>
  147. ),
  148. },
  149. ];
  150. const getSignList = dynamicId => {
  151. router.push({
  152. pathname: '/activity/SignList',
  153. query: {
  154. dynamicId,
  155. },
  156. });
  157. }
  158. const finishDynamic = row => {
  159. Modal.confirm({
  160. title: '结束以后将无法编辑, 是否继续?',
  161. okText: '确定',
  162. cancelText: '取消',
  163. onOk () {
  164. request({ ...apis.activity.finish, data: { dynamicId: row.dynamicId, top: '' } }).then(data => {
  165. console.log(data)
  166. message.info('操作成功!')
  167. getList({ pageNum: 1, pageSize: 10, ...props.form.getFieldsValue() })
  168. }).catch(err => {
  169. console.log(err)
  170. message.info(err.msg || err.message)
  171. })
  172. },
  173. });
  174. }
  175. // 置顶
  176. const topDynamic = row => () => {
  177. const weight = Math.abs(row.weight - 1)
  178. request({ ...apis.activity.weight, params: { dynamicId: row.dynamicId, weight } }).then(data => {
  179. console.log(data)
  180. message.info('操作成功!')
  181. getList({ pageNum: 1, pageSize: 10, ...props.form.getFieldsValue() })
  182. }).catch(err => {
  183. console.log(err)
  184. message.info(err.msg || err.message)
  185. })
  186. }
  187. const sendOrPublicDynamic = row => {
  188. if (row.status === 1) {
  189. cancelDynamic(row)
  190. } else {
  191. sendDynamic(row)
  192. }
  193. }
  194. // 取消活动
  195. const cancelDynamic = row => {
  196. request({ ...apis.activity.cancel, urlData: { id: row.dynamicId } }).then(data => {
  197. message.info('操作成功!')
  198. getList({ pageNum: 1, pageSize: 10, ...props.form.getFieldsValue() })
  199. }).catch(err => {
  200. console.log(err)
  201. message.info(err.msg || err.message)
  202. })
  203. }
  204. // 发布活动
  205. const sendDynamic = row => {
  206. request({ ...apis.activity.send, urlData: { id: row.dynamicId } }).then(data => {
  207. message.info('操作成功!')
  208. getList({ pageNum: 1, pageSize: 10, ...props.form.getFieldsValue() });
  209. }).catch(err => {
  210. console.log(err)
  211. message.info(err.msg || err.message)
  212. })
  213. }
  214. const changePageNum = pageNumber => {
  215. getList({ pageNum: pageNumber, pageSize: 10, ...props.form.getFieldsValue() })
  216. }
  217. // 提交事件
  218. const handleSubmit = e => {
  219. e.preventDefault();
  220. props.form.validateFields((err, values) => {
  221. if (!err) {
  222. console.log('提交数据: ', values)
  223. if (time) {
  224. values.time = `${moment(time).format('YYYY-MM-DDT00:00:00.000')}Z`
  225. } else {
  226. values.time = null
  227. }
  228. getList({ pageNum: 1, pageSize: 10, ...values })
  229. }
  230. });
  231. }
  232. // 重置搜索
  233. function handleReset () {
  234. props.form.resetFields();
  235. setTime('')
  236. getList({ pageNum: 1, pageSize: 10 })
  237. }
  238. // 时间回调
  239. function timeOnChange(date, dateString) {
  240. console.log(date, dateString)
  241. setTime(date)
  242. }
  243. const { getFieldDecorator } = props.form
  244. return (
  245. <>
  246. {/* style={{ display: 'none' }} */}
  247. <div id="qrcode"></div>
  248. <Form layout="inline" onSubmit={e => handleSubmit(e)}>
  249. <Form.Item>
  250. {getFieldDecorator('cityId')(
  251. <SelectCity />,
  252. )}
  253. </Form.Item>
  254. <Form.Item>
  255. {getFieldDecorator('buildingId')(
  256. <BuildSelect />,
  257. )}
  258. </Form.Item>
  259. <Form.Item>
  260. {getFieldDecorator('title')(
  261. <Input
  262. prefix={<Icon type="text" style={{ color: 'rgba(0,0,0,.25)' }} />}
  263. placeholder="请输入标题"
  264. />,
  265. )}
  266. </Form.Item>
  267. <Form.Item>
  268. {getFieldDecorator('time')(
  269. <DatePicker onChange={timeOnChange}/>,
  270. )}
  271. </Form.Item>
  272. <Form.Item>
  273. {getFieldDecorator('isEnlist')(
  274. <Select style={{ width: '180px' }} placeholder="是否报名">
  275. <Option value="1">已报名</Option>
  276. <Option value="0">未报名</Option>
  277. </Select>,
  278. )}
  279. </Form.Item>
  280. <Form.Item>
  281. <Button type="primary" htmlType="submit" className={styles.searchBtn}>
  282. 搜索
  283. </Button>
  284. <Button style={{ marginLeft: 8 }} onClick={handleReset}>
  285. 重置
  286. </Button>
  287. </Form.Item>
  288. </Form>
  289. <AuthButton name="admin.buildingDynamic.add.post" noRight={null}>
  290. <Button type="danger" className={styles.addBtn} onClick={toEditGoods()}>新增</Button>
  291. </AuthButton>
  292. <Table dataSource={data.list} columns={columns} pagination={false} rowKey="activityList" />
  293. <div style={{ display: 'flex', justifyContent: 'flex-end', marginTop: '30px' }}>
  294. <Pagination showQuickJumper defaultCurrent={1} total={data.total} onChange={e => changePageNum(e)} current={data.current}/>
  295. </div>
  296. </>
  297. )
  298. }
  299. const WrappedHeader = Form.create({ name: 'header' })(header);
  300. export default WrappedHeader