知与行后台管理端

list.jsx 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  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. console.log(params);
  23. request({ ...apis.groupActivity.list, params: { ...params } }).then((data) => {
  24. console.log(data)
  25. setData(data)
  26. })
  27. }
  28. // 跳转到拼团活动新增
  29. const toEditActivity = (groupActivityId) => () => {
  30. router.push({
  31. pathname: '/activity/groupActivity/editGroupActivity',
  32. query: {
  33. groupActivityId
  34. },
  35. });
  36. }
  37. /**
  38. *
  39. *
  40. * @param {*} props
  41. * @returns
  42. */
  43. const columns = [
  44. {
  45. title: '活动标题',
  46. dataIndex: 'activityName',
  47. key: 'activityName',
  48. align: 'center',
  49. },
  50. {
  51. title: '活动时间',
  52. dataIndex: 'startTime',
  53. key: 'startTime',
  54. align: 'center',
  55. render: (x, row) => <><span>{`${moment(row.startTime).format('YYYY-MM-DD HH:mm:ss')} —— ${moment(row.endTime).format('YYYY-MM-DD HH:mm:ss')}`}</span></>
  56. },
  57. {
  58. title: '所需积分',
  59. dataIndex: 'integral',
  60. key: 'integral',
  61. align: 'center',
  62. },
  63. {
  64. title: '已参与人数',
  65. dataIndex: 'participateNum',
  66. key: 'participateNum',
  67. align: 'center',
  68. },
  69. {
  70. title: '成团数',
  71. dataIndex: 'groupBuyPeople',
  72. key: 'groupBuyPeople',
  73. align: 'center',
  74. },
  75. {
  76. title: '状态',
  77. dataIndex: 'activityStatus',
  78. key: 'activityStatus',
  79. align: 'center',
  80. render: (text, records) => {
  81. if (records.activityStatus === 0) { return '进行中' }
  82. if (records.activityStatus === 1) { return '未开始' }
  83. if (records.activityStatus === 2) { return '已结束' }
  84. },
  85. },
  86. {
  87. title: '操作',
  88. dataIndex: 'handle',
  89. key: 'handle',
  90. align: 'center',
  91. render: (x, row) => (
  92. <>
  93. {row.activityStatus === 0 &&
  94. <AuthButton name="admin.taShareActivity.finish.put" noRight={null}><span style={{ color: '#1990FF', marginRight: '20px', cursor: 'pointer' }} onClick={endGroupActivity(row)}>结束活动<Icon type="poweroff" className={styles.edit} /></span></AuthButton>
  95. }
  96. {(row.activityStatus === 0 || row.activityStatus === 2)&&
  97. <AuthButton name="admin.taShareSuccessRecord.get" noRight={null}>
  98. <span style={{ color: '#1990FF', marginRight: '20px', cursor: 'pointer' }} onClick={getSignList.bind(this, row.groupActivityId)}>拼团记录<Icon type="snippets" className={styles.shoppingCart} /></span>
  99. </AuthButton>
  100. }
  101. {
  102. <AuthButton name="admin.buildingDynamic.send.dynamicId.put" noRight={null}>
  103. <span style={{ color: '#1990FF',marginRight: '20px', cursor: 'pointer' }} onClick={sendOrPublicDynamic.bind(this, row)}>{row.status === 1 ? '取消发布' : '发布'}<Icon type="close-circle" className={styles.edit} /></span>
  104. </AuthButton>
  105. }
  106. {
  107. <AuthButton name="admin.taShareActivity.list.get" noRight={null}>
  108. <span style={{ color: '#1990FF', marginRight: '20px', cursor: 'pointer' }} onClick={topGroupActivity(row, row.weight)}>{row.weight === 1 ? '取消标签' : '添加标签'}<Icon type="vertical-align-top" className={styles.edit} /></span>
  109. <span style={{ color: '#1990FF', marginRight: '20px', cursor: 'pointer' }} onClick={recommendGroupActivity(row)}>{row.sort === true ? '取消推荐首页' : '推荐首页'}<Icon type="vertical-align-top" className={styles.edit} /></span>
  110. </AuthButton>}
  111. {(row.activityStatus === 0 || row.activityStatus === 1) &&
  112. <AuthButton name="admin.taShareActivity.update.put" noRight={null}>
  113. <span style={{ color: '#FF925C', marginRight: '20px', cursor: 'pointer' }} onClick={toEditActivity(row.groupActivityId)}>编辑<Icon type="form" className={styles.edit} /></span>
  114. </AuthButton>
  115. }
  116. </>
  117. ),
  118. },
  119. ];
  120. const getSignList = groupActivityId => {
  121. router.push({
  122. pathname: '/activity/groupActivity/helpRecord',
  123. query: {
  124. groupActivityId,
  125. },
  126. });
  127. }
  128. const finishDynamic = (row) => {
  129. Modal.confirm({
  130. title: '结束以后将无法编辑, 是否继续?',
  131. okText: '确定',
  132. cancelText: '取消',
  133. onOk () {
  134. request({ ...apis.activity.finish, data: { dynamicId: row.dynamicId, top: "" } }).then((data) => {
  135. console.log(data)
  136. message.info('操作成功!')
  137. getList({ pageNum: 1, pageSize: 10, ...props.form.getFieldsValue() })
  138. }).catch((err) => {
  139. console.log(err)
  140. message.info(err.msg || err.message)
  141. })
  142. },
  143. });
  144. }
  145. //结束活动
  146. const endGroupActivity = (row) => () => {
  147. Modal.confirm({
  148. title: '活动会被强制结束,小程序端无法再发起或参与此拼团,如果不想让客户看到活动,请再点击取消发布按钮',
  149. okText: '确定',
  150. cancelText: '取消',
  151. onOk () {
  152. request({ ...apis.groupActivity.finish, urlData: { id: row.groupActivityId } }).then((data) => {
  153. console.log(data)
  154. message.info('操作成功!')
  155. getList({ pageNum: 1, pageSize: 10, ...props.form.getFieldsValue() })
  156. }).catch((err) => {
  157. console.log(err)
  158. message.info(err.msg || err.message)
  159. })
  160. },
  161. });
  162. }
  163. //置顶
  164. const topGroupActivity = (row, weight) => () => {
  165. request({ ...apis.groupActivity.top, data: { groupActivityId: row.groupActivityId, weight: weight } }).then((data) => {
  166. console.log(data)
  167. message.info('操作成功!')
  168. getList({ pageNum: 1, pageSize: 10, ...props.form.getFieldsValue() })
  169. }).catch((err) => {
  170. console.log(err)
  171. message.info(err.msg || err.message)
  172. })
  173. }
  174. const sendOrPublicDynamic = row => {
  175. if (row.status === 1) {
  176. cancelDynamic(row)
  177. } else {
  178. sendDynamic(row)
  179. }
  180. }
  181. // 取消活动
  182. const cancelDynamic = row => {
  183. Modal.confirm({
  184. title: '活动会在小程序端隐藏,后台可以继续编辑重新发布',
  185. okText: '确认',
  186. cancelText: '取消',
  187. onOk() {
  188. request({ ...apis.groupActivity.cancel, urlData: { id: row.groupActivityId } }).then(data => {
  189. message.info('操作成功!')
  190. getList({ pageNum: 1, pageSize: 10, ...props.form.getFieldsValue() })
  191. }).catch(err => {
  192. console.log(err)
  193. message.info(err.msg || err.message)
  194. })
  195. }
  196. });
  197. }
  198. // 发布活动
  199. const sendDynamic = row => {
  200. Modal.confirm({
  201. title: '确定发布吗?',
  202. okText: '确认',
  203. cancelText: '取消',
  204. onOk() {
  205. request({ ...apis.groupActivity.send, urlData: { id: row.groupActivityId } }).then(data => {
  206. message.info('操作成功!')
  207. getList({ pageNum: 1, pageSize: 10, ...props.form.getFieldsValue() });
  208. }).catch(err => {
  209. console.log(err)
  210. message.info(err.msg || err.message)
  211. })
  212. }
  213. });
  214. }
  215. //首页推荐
  216. const recommendGroupActivity = (row, code) => () => {
  217. request({ ...apis.groupActivity.top, data: { groupActivityId: row.groupActivityId, sort: row.sort } }).then((data) => {
  218. console.log(data)
  219. message.info('操作成功!')
  220. getList({ pageNum: 1, pageSize: 10, ...props.form.getFieldsValue() })
  221. }).catch((err) => {
  222. console.log(err)
  223. message.info(err.msg || err.message)
  224. })
  225. }
  226. const changePageNum = pageNumber => {
  227. getList({ pageNum: pageNumber, pageSize: 10, ...props.form.getFieldsValue() })
  228. }
  229. // 提交事件
  230. const handleSubmit = (e, props) => {
  231. e.preventDefault();
  232. props.form.validateFields((err, values) => {
  233. if (!err) {
  234. console.log('提交数据: ', values)
  235. getList({ pageNum: 1, pageSize: 10, ...values })
  236. }
  237. });
  238. }
  239. //重置搜索
  240. function handleReset () {
  241. props.form.resetFields();
  242. getList({ pageNum: 1, pageSize: 10 })
  243. }
  244. const { getFieldDecorator } = props.form
  245. return (
  246. <>
  247. <Form layout="inline" onSubmit={e => handleSubmit(e, props)}>
  248. <Form.Item>
  249. {getFieldDecorator('cityId')(
  250. <SelectCity />,
  251. )}
  252. </Form.Item>
  253. <Form.Item>
  254. {getFieldDecorator('buildingId')(
  255. <BuildSelect />,
  256. )}
  257. </Form.Item>
  258. <Form.Item>
  259. {getFieldDecorator('activityName')(
  260. <Input
  261. prefix={<Icon type="text" style={{ color: 'rgba(0,0,0,.25)' }} />}
  262. placeholder="请输入标题"
  263. />,
  264. )}
  265. </Form.Item>
  266. <Form.Item>
  267. {getFieldDecorator('activityStatus')(
  268. <Select style={{ width: '180px' }} placeholder="活动状态">
  269. <Option value="0">进行中</Option>
  270. <Option value="1">未开始</Option>
  271. <Option value="2">已结束</Option>
  272. </Select>,
  273. )}
  274. </Form.Item>
  275. <Form.Item>
  276. <Button type="primary" htmlType="submit" className={styles.searchBtn}>
  277. 搜索
  278. </Button>
  279. <Button style={{ marginLeft: 8 }} onClick={handleReset}>
  280. 重置
  281. </Button>
  282. </Form.Item>
  283. </Form>
  284. <AuthButton name="admin.taShareActivity.post" noRight={null}>
  285. <Button type="danger" className={styles.addBtn} onClick={toEditActivity()}>新增</Button>
  286. </AuthButton>
  287. <Table style={{marginTop:'30px'}} dataSource={data.records} columns={columns} pagination={false} rowKey="activityList" />
  288. <div style={{ display: 'flex', justifyContent: 'flex-end', marginTop: '30px' }}>
  289. <Pagination showQuickJumper defaultCurrent={1} total={data.total} onChange={changePageNum} current={data.current} />
  290. </div>
  291. </>
  292. )
  293. }
  294. const WrappedHeader = Form.create({ name: 'header' })(header);
  295. export default WrappedHeader