carouselFigureList.jsx 9.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. import React, { useState, useEffect } from 'react';
  2. import { Form, Button, Select, message, Table, Pagination, Modal, DatePicker } from 'antd';
  3. import router from 'umi/router';
  4. import moment from 'moment';
  5. import AuthButton from '@/components/AuthButton';
  6. import withActions from '@/components/ActionList';
  7. import EditIcon from '@/components/EditIcon';
  8. import Navigate from '@/components/Navigate';
  9. import SelectCity from '../../components/SelectButton/CitySelect'
  10. import BuildSelect from '../../components/SelectButton/BuildSelect'
  11. import apis from '../../services/apis';
  12. import request from '../../utils/request';
  13. import styles from '../style/GoodsList.less';
  14. const { Option } = Select;
  15. const { MonthPicker, RangePicker, WeekPicker } = DatePicker;
  16. const ContentTypeDict = {
  17. 'notice': '公告',
  18. 'tpNews': '服务',
  19. 'activity': '活动',
  20. 'mall': '积分商城',
  21. 'news': '资讯',
  22. 'nothing': '无',
  23. }
  24. const PositionDict = {
  25. 'index': '首页',
  26. 'mall': '积分商城',
  27. 'property': '物业'
  28. }
  29. const header = (props) => {
  30. const [data, setData] = useState({})
  31. // const [page, changePage] = useState({})
  32. useEffect(() => {
  33. getList({ pageNum: 1, pageSize: 10, showType: 'banner' });
  34. }, [])
  35. // 查询列表
  36. const getList = (params) => {
  37. request({ ...apis.carsuseFigure.extendContent, params: { ...params }, }).then((data) => {
  38. console.log(data)
  39. setData(data)
  40. })
  41. }
  42. // 跳转到编辑页面
  43. const toEditCarouse = (contentId) => () => {
  44. router.push({
  45. pathname: '/carouselFigure/editCarousel',
  46. query: {
  47. contentId
  48. },
  49. });
  50. }
  51. const columns = [
  52. {
  53. title: '主图',
  54. dataIndex: 'image',
  55. key: 'image',
  56. align: 'center',
  57. render: (x, row) => <Navigate onClick={toEditCarouse(row.contentId)} ><img src={row.image} style={{width: '128px', height: '64px'}} /></Navigate>,
  58. },
  59. // {
  60. // title: '发布城市',
  61. // dataIndex: 'cityName',
  62. // key: 'cityName',
  63. // align: 'center',
  64. // },
  65. // {
  66. // title: '关联项目',
  67. // dataIndex: 'buildingName',
  68. // key: 'buildingName',
  69. // align: 'center',
  70. // render: (buildingName) => <span>{buildingName === null ? '无' : buildingName}</span>
  71. // },
  72. {
  73. title: '关联内容类型',
  74. dataIndex: 'contentType',
  75. key: 'contentType',
  76. align: 'center',
  77. render: t => ContentTypeDict[t] || '无'
  78. },
  79. {
  80. title: '发布位置',
  81. dataIndex: 'showPosition',
  82. key: 'showPosition',
  83. align: 'center',
  84. render: t => PositionDict[t] || ''
  85. },
  86. {
  87. title: '发布时间',
  88. dataIndex: 'createDate',
  89. key: 'createDate',
  90. align: 'center',
  91. render: (x, row) => <><span>{moment(row.createDate).format('YYYY-MM-DD')}</span></>
  92. },
  93. {
  94. title: '状态',
  95. dataIndex: 'status',
  96. key: 'status',
  97. align: 'center',
  98. render: (status) => <><span>{status == 1 ? '已上架' : '已下架'}</span></>
  99. },
  100. {
  101. title: '操作',
  102. dataIndex: 'handle',
  103. key: 'handle',
  104. align: 'center',
  105. render: withActions((x, row) => [
  106. <AuthButton name="admin.extendContent.publish" noRight={null}>
  107. <EditIcon type={row.status === 1 ? 'down' : 'up'} text={row.status === 1 ? '下架' : '上架'} onClick={changeStatus(row)} />
  108. </AuthButton>,
  109. <AuthButton name="admin.extendContent.id.put" noRight={null}>
  110. <EditIcon text="编辑" type="edit" onClick={toEditCarouse(row.contentId)} />
  111. </AuthButton>,
  112. <AuthButton name="admin.extendContent.delete" noRight={null}>
  113. <EditIcon text="删除" type="delete" onClick={deleteCarouse(row.contentId)} />
  114. </AuthButton>,
  115. ])
  116. },
  117. ];
  118. const finishDynamic = (row) => {
  119. Modal.confirm({
  120. title: '结束以后将无法编辑, 是否继续?',
  121. okText: '确定',
  122. cancelText: '取消',
  123. onOk() {
  124. request({ ...apis.carsuseFigure.finish, data: { dynamicId: row.dynamicId, top: "" }, }).then((data) => {
  125. console.log(data)
  126. message.info('操作成功!')
  127. getList({ pageNum: 1, pageSize: 10, showType: 'banner' })
  128. }).catch((err) => {
  129. console.log(err)
  130. message.info(err.msg || err.message)
  131. })
  132. },
  133. });
  134. }
  135. //删除
  136. const deleteCarouse = (contentId) => () => {
  137. Modal.confirm({
  138. title: '确认删除此数据?',
  139. okText: '确定',
  140. cancelText: '取消',
  141. onOk() {
  142. request({ ...apis.carsuseFigure.deleteExtendContent, urlData: { id: contentId } }).then((data) => {
  143. message.info('操作成功!')
  144. getList({ pageNum: 1, pageSize: 10, showType: 'banner' })
  145. }).catch((err) => {
  146. console.log(err)
  147. message.info(err.msg || err.message)
  148. })
  149. },
  150. });
  151. }
  152. // 停用启用
  153. const changeStatus = (row) => () => {
  154. console.log(row)
  155. if (row.status === 0) {
  156. Modal.confirm({
  157. title: '确认发布此数据?',
  158. okText: '确定',
  159. cancelText: '取消',
  160. onOk() {
  161. row.status = 1
  162. request({ ...apis.carsuseFigure.updataExtendContent, urlData: { id: row.contentId }, data: row, }).then((data) => {
  163. message.info('操作成功!')
  164. getList({ pageNum: 1, pageSize: 10, showType: 'banner' })
  165. }).catch((err) => {
  166. console.log(err)
  167. row.status = 0
  168. message.info(err.msg || err.message)
  169. })
  170. },
  171. });
  172. } else if (row.status === 1) {
  173. Modal.confirm({
  174. title: '停用后不会再显示在小程序端',
  175. okText: '确定',
  176. cancelText: '取消',
  177. onOk() {
  178. row.status = 0
  179. request({ ...apis.carsuseFigure.updataExtendContent, urlData: { id: row.contentId }, data: row, }).then((data) => {
  180. message.info('操作成功!')
  181. getList({ pageNum: 1, pageSize: 10, showType: 'banner' })
  182. }).catch((err) => {
  183. console.log(err)
  184. row.status = 1
  185. message.info(err.msg || err.message)
  186. })
  187. },
  188. });
  189. }
  190. }
  191. const changePageNum = (pageNumber) => {
  192. getList({ pageNum: pageNumber, pageSize: 10, showType: 'banner', ...props.form.getFieldsValue() })
  193. }
  194. // 提交事件
  195. const handleSubmit = (e, props) => {
  196. e.preventDefault();
  197. props.form.validateFields((err, values) => {
  198. if (!err) {
  199. console.log('提交数据: ', values)
  200. getList({ pageNum: 1, pageSize: 10, ...values, showType: 'banner' })
  201. }
  202. });
  203. }
  204. //重置搜索
  205. function handleReset() {
  206. props.form.resetFields();
  207. getList({ pageNum: 1, pageSize: 10, showType: 'banner' });
  208. }
  209. const { getFieldDecorator } = props.form
  210. return (
  211. <>
  212. <Form layout="inline" onSubmit={e => handleSubmit(e, props)}>
  213. {/* <Form.Item>
  214. {getFieldDecorator('cityId')(
  215. <SelectCity />,
  216. )}
  217. </Form.Item>
  218. <Form.Item>
  219. {getFieldDecorator('buildingId')(
  220. <BuildSelect />,
  221. )}
  222. </Form.Item> */}
  223. <Form.Item>
  224. {getFieldDecorator('contentType')(
  225. <Select style={{ width: '180px' }} placeholder="类型">
  226. <Option value="notice">公告</Option>
  227. <Option value="tpNews">服务</Option>
  228. <Option value="activity">活动</Option>
  229. {/* <Option value="project">项目</Option> */}
  230. <Option value="news">资讯</Option>
  231. {/* <Option value="help">助力</Option>
  232. <Option value="group">拼团</Option>
  233. <Option value="h5">H5</Option> */}
  234. <Option value="nothing">无</Option>
  235. {/* <Option value="other">其他</Option> */}
  236. </Select>,
  237. )}
  238. </Form.Item>
  239. <Form.Item>
  240. {getFieldDecorator('showPosition')(
  241. <Select style={{ width: '180px' }} placeholder="发布位置">
  242. <Option value="index">首页</Option>
  243. <Option value="mall">积分商城</Option>
  244. <Option value="property">物业</Option>
  245. </Select>,
  246. )}
  247. </Form.Item>
  248. <Form.Item>
  249. {getFieldDecorator('status')(
  250. <Select style={{ width: '180px' }} placeholder="状态">
  251. <Option value="1">已上架</Option>
  252. <Option value="0">已下架</Option>
  253. </Select>,
  254. )}
  255. </Form.Item>
  256. <Form.Item>
  257. <AuthButton name="admin.extendContent.search" noRight={null}>
  258. <Button type="primary" htmlType="submit" className={styles.searchBtn}>
  259. 搜索
  260. </Button>
  261. </AuthButton>
  262. <Button style={{ marginLeft: 8 }} onClick={handleReset}>
  263. 重置
  264. </Button>
  265. </Form.Item>
  266. </Form>
  267. <AuthButton name="admin.extendContent.post" noRight={null}>
  268. <Button type="danger" className={styles.addBtn} onClick={toEditCarouse()}>新增</Button>
  269. </AuthButton>
  270. <Table dataSource={data.records} columns={columns} pagination={false} rowKey="carouseFigureList" />
  271. <div style={{ display: 'flex', justifyContent: 'flex-end', marginTop: '30px' }}>
  272. <Pagination showQuickJumper defaultCurrent={1} total={data.total} onChange={changePageNum} current={data.current} />
  273. </div>
  274. </>
  275. )
  276. }
  277. const WrappedHeader = Form.create({ name: 'header' })(header);
  278. export default WrappedHeader