知与行后台管理端

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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 styles from '../../style/GoodsList.less';
  5. import router from 'umi/router';
  6. import moment from 'moment';
  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. const [ data, setData ] = useState({})
  16. // const [page, changePage] = useState({})
  17. useEffect(() => {
  18. getList({ pageNum: 1, pageSize: 10 });
  19. },[])
  20. // 查询列表
  21. const getList = (params) => {
  22. request({ ...apis.helpActivity.list, params: { ...params } }).then((data) => {
  23. console.log(data)
  24. setData(data)
  25. })
  26. }
  27. // 跳转到助力新增
  28. const toEditGoods = (helpActivityId) => () => {
  29. router.push({
  30. pathname: '/activity/helpActivity/edithelpActivity',
  31. query: {
  32. helpActivityId
  33. },
  34. });
  35. }
  36. /**
  37. *
  38. *
  39. * @param {*} props
  40. * @returns
  41. */
  42. const columns = [
  43. {
  44. title: '活动标题',
  45. dataIndex: 'title',
  46. key: 'title',
  47. align: 'center',
  48. },
  49. {
  50. title: '活动时间',
  51. dataIndex: 'startDate',
  52. key: 'startDate',
  53. align: 'center',
  54. render: (x, row) => <><span>{`${moment(row.startDate).format('YYYY-MM-DD HH:mm:ss')} —— ${moment(row.endDate).format('YYYY-MM-DD HH:mm:ss')}`}</span></>,
  55. },
  56. {
  57. title: '已参加人数',
  58. dataIndex: 'enlistNum',
  59. key: 'enlistNum',
  60. align: 'center',
  61. },
  62. {
  63. title: '助力成功数',
  64. dataIndex: 'succeedCount',
  65. key: 'succeedCount',
  66. align: 'center',
  67. },
  68. {
  69. title: '状态',
  70. dataIndex: 'isEnlist',
  71. key: 'isEnlist',
  72. align: 'center',
  73. render: (text, records) => {
  74. if (records.activityStatus === 1) { return '未开始' }
  75. if (records.activityStatus === 0) { return '进行中' }
  76. if (records.activityStatus === 2) { return '已结束' }
  77. },
  78. },
  79. {
  80. title: '操作',
  81. dataIndex: 'handle',
  82. key: 'handle',
  83. align: 'center',
  84. render: (x, row) => (
  85. <>
  86. {(row.activityStatus === 0 || row.activityStatus === 2) &&
  87. <AuthButton name="admin.helpRecord.get">
  88. <span style={{ color: '#1990FF', marginRight: '20px', cursor: 'pointer' }} onClick={ getSignList.bind(this, row.helpActivityId)}>助力记录<Icon type="snippets" style={{color:'#bebebe'}} className={styles.shoppingCart} /></span>
  89. </AuthButton>}
  90. {
  91. <AuthButton name="admin.top.update.post" noRight={null}>
  92. <span style={{ color: '#1990FF',marginRight: '20px', cursor: 'pointer' }} onClick={sendOrPublicDynamic.bind(this, row)}>{row.status === 1 ? '取消发布' : '发布'}<Icon type="close-circle" className={styles.edit} /></span>
  93. </AuthButton>
  94. }
  95. {row.activityStatus === 0 &&
  96. <AuthButton name="admin.top.update.post" noRight={null}>
  97. <span style={{ color: '#1990FF', marginRight: '20px', cursor: 'pointer' }} onClick={topDynamic(row, 2)}>结束活动<Icon type="poweroff" style={{color:'#bebebe'}} className={styles.edit} /></span> </AuthButton>
  98. }
  99. {
  100. <AuthButton name="admin.top.update.post" noRight={null}>
  101. <span style={{ color: '#1990FF', marginRight: '20px', cursor: 'pointer' }} onClick={topDynamic(row, 0)}>{ row.weight === 1 ? '取消标签' : '添加标签' }<Icon type="vertical-align-top" style={{color:'#bebebe'}} className={styles.edit} /></span>
  102. <span style={{ color: '#1990FF', marginRight: '20px', cursor: 'pointer' }} onClick={topDynamic(row, 1)}>{ row.isMain === true ? '取消推首页' : '推首页' }<Icon type="vertical-align-top" style={{color:'#bebebe'}} className={styles.edit} /></span>
  103. </AuthButton> }
  104. {(row.activityStatus === 1 || row.activityStatus === 0) &&
  105. <AuthButton name="admin.helpActivity.update.put" noRight={null}>
  106. <span style={{ color: '#FF925C', marginRight: '20px', cursor: 'pointer' }} onClick={toEditGoods(row.helpActivityId)}>编辑<Icon type="form" style={{color:'#bebebe'}} className={styles.edit} /></span>
  107. </AuthButton>
  108. }
  109. </>
  110. ),
  111. },
  112. ];
  113. const getSignList = helpActivityId => {
  114. router.push({
  115. pathname: '/activity/helpActivity/helpRecord',
  116. query: {
  117. helpActivityId,
  118. },
  119. });
  120. }
  121. const finishDynamic = (row) => {
  122. Modal.confirm({
  123. title: '结束以后将无法编辑, 是否继续?',
  124. okText: '确定',
  125. cancelText: '取消',
  126. onOk() {
  127. request({ ...apis.activity.finish, data: {dynamicId: row.dynamicId, top: ""} }).then((data) => {
  128. console.log(data)
  129. message.info('操作成功!')
  130. getList({ pageNum: 1, pageSize: 10, ...props.form.getFieldsValue() })
  131. }).catch((err) => {
  132. console.log(err)
  133. message.info(err.msg || err.message)
  134. })
  135. },
  136. });
  137. }
  138. // 置顶
  139. const topDynamic = (row, code) => () => {
  140. request({ ...apis.helpActivity.top, data: { helpActivityId: row.helpActivityId, status: code } }).then((data) => {
  141. console.log(data)
  142. message.info('操作成功!')
  143. getList({ pageNum: 1, pageSize: 10, ...props.form.getFieldsValue() })
  144. }).catch((err) => {
  145. console.log(err)
  146. message.info(err.msg || err.message)
  147. })
  148. }
  149. const sendOrPublicDynamic = (row) => {
  150. if (row.status === 1) {
  151. cancelDynamic(row)
  152. } else {
  153. sendDynamic(row)
  154. }
  155. }
  156. // 取消活动
  157. const cancelDynamic = (row) => {
  158. request({ ...apis.activity.cancel, urlData: {id: row.dynamicId}}).then((data) => {
  159. message.info('操作成功!')
  160. getList({ pageNum: 1, pageSize: 10, ...props.form.getFieldsValue() })
  161. }).catch((err) => {
  162. console.log(err)
  163. message.info(err.msg || err.message)
  164. })
  165. }
  166. //发布活动
  167. const sendDynamic = (row) => {
  168. request({ ...apis.activity.send, urlData: {id: row.dynamicId}}).then((data) => {
  169. message.info('操作成功!')
  170. getList({ pageNum: 1, pageSize: 10, ...props.form.getFieldsValue() });
  171. }).catch(err => {
  172. console.log(err)
  173. message.info(err.msg || err.message)
  174. })
  175. }
  176. const changePageNum = pageNumber => {
  177. getList({ pageNum: pageNumber, pageSize: 10, ...props.form.getFieldsValue() })
  178. }
  179. // 提交事件
  180. const handleSubmit = (e, props) => {
  181. e.preventDefault();
  182. props.form.validateFields((err, values) => {
  183. const startDate = values.startTime === undefined ? null : moment(values.startTime).format('YYYY-MM-DD')
  184. const endDate = values.endTime === undefined ? null : moment(values.endTime).format('YYYY-MM-DD')
  185. // 删除时间会传默认值 Invalid date
  186. if (!err) {
  187. console.log('提交数据: ', values)
  188. getList({ pageNum: 1, pageSize: 10, ...values, endDate, startDate })
  189. }
  190. });
  191. }
  192. // 重置搜索
  193. function handleReset() {
  194. props.form.resetFields();
  195. getList({ pageNum: 1, pageSize: 10 })
  196. }
  197. const { getFieldDecorator } = props.form
  198. return (
  199. <>
  200. <Form layout="inline" onSubmit={e => handleSubmit(e, props)}>
  201. <Form.Item>
  202. {getFieldDecorator('cityId')(
  203. <SelectCity />,
  204. )}
  205. </Form.Item>
  206. <Form.Item>
  207. {getFieldDecorator('buildingId')(
  208. <BuildSelect />,
  209. )}
  210. </Form.Item>
  211. <Form.Item>
  212. {getFieldDecorator('title')(
  213. <Input
  214. prefix={<Icon type="text" style={{ color: 'rgba(0,0,0,.25)' }} />}
  215. placeholder="请输入标题"
  216. />,
  217. )}
  218. </Form.Item>
  219. <Form.Item>
  220. {getFieldDecorator('startTime')(
  221. <DatePicker placeholder="活动开始时间"/>,
  222. )}
  223. </Form.Item>
  224. <Form.Item>
  225. {getFieldDecorator('endTime')(
  226. <DatePicker placeholder="活动结束时间"/>,
  227. )}
  228. </Form.Item>
  229. <Form.Item>
  230. {getFieldDecorator('activityStatus')(
  231. <Select style={{ width: '180px' }} placeholder="活动状态">
  232. <Option value="1">未开始</Option>
  233. <Option value="0">进行中</Option>
  234. <Option value="2">已结束</Option>
  235. </Select>,
  236. )}
  237. </Form.Item>
  238. <Form.Item>
  239. <Button type="primary" htmlType="submit" className={styles.searchBtn}>
  240. 搜索
  241. </Button>
  242. <Button style={{ marginLeft: 8 }} onClick={handleReset}>
  243. 重置
  244. </Button>
  245. </Form.Item>
  246. </Form>
  247. <AuthButton name="admin.buildingDynamic.add.post" noRight={null}>
  248. <Button name="admin.helpActivity.add.post" noRight={null} type="danger" className={styles.addBtn} onClick={toEditGoods()}>新增</Button>
  249. </AuthButton>
  250. <Table dataSource={data.records} columns={columns} pagination={false} rowKey="activityList"/>
  251. <div style={{ display: 'flex', justifyContent: 'flex-end', marginTop: '30px' }}>
  252. <Pagination showQuickJumper defaultCurrent={1} total={data.total} onChange={changePageNum} current={data.current}/>
  253. </div>
  254. </>
  255. )
  256. }
  257. const WrappedHeader = Form.create({ name: 'header' })(header);
  258. export default WrappedHeader