知与行后台管理端

NewsList.jsx 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. import React, { useState, useEffect } from 'react';
  2. import { Form, Icon, Input, Button, DatePicker, Select, Modal, message, Card, Row, Col, Pagination, Alert } from 'antd';
  3. import moment from 'moment';
  4. import router from 'umi/router';
  5. import request from '../../../utils/request';
  6. import apis from '../../../services/apis';
  7. import Styles from './style.less';
  8. import styles from '../../style/GoodsList.less';
  9. import NewsTypeSelect from '../../../components/SelectButton/NewTypeSelect'
  10. import BuildSelect from '../../../components/SelectButton/BuildSelect'
  11. import SelectCity from '../../../components/SelectButton/CitySelect'
  12. import AuthButton from '@/components/AuthButton';
  13. const { Option } = Select;
  14. // eslint-disable-next-line @typescript-eslint/no-unused-vars
  15. const { Meta } = Card;
  16. const tempDate = [{ code: 's101' }]
  17. /**
  18. *
  19. *
  20. * @param {*} props
  21. * @returns
  22. */
  23. function body(props) {
  24. const { getFieldDecorator } = props.form
  25. // eslint-disable-next-line react-hooks/rules-of-hooks
  26. const [dataSource, setDataSource] = useState({ records: [] })
  27. // eslint-disable-next-line react-hooks/rules-of-hooks
  28. useEffect(() => {
  29. getList({ pageNum: 1, pageSize: 6 })
  30. }, [])
  31. function getList(params) {
  32. // 网路请求
  33. request({ ...apis.news.getList, params: { ...params } }).then(res => {
  34. setDataSource(res)
  35. }).catch(err => {
  36. // eslint-disable-next-line no-unused-expressions
  37. <Alert
  38. style={{
  39. marginBottom: 24,
  40. }}
  41. message={err}
  42. type="error"
  43. showIcon
  44. />
  45. })
  46. }
  47. // 提交事件
  48. function handleSubmit(e) {
  49. e.preventDefault();
  50. props.form.validateFields((err, values) => {
  51. if (!err) {
  52. console.log('提交数据: ', values)
  53. const { startDate } = values
  54. getList({ pageNum: 1, pageSize: 6, ...values })
  55. }
  56. });
  57. }
  58. // 跳转到编辑资讯列表
  59. const toEditList = (id) => () => {
  60. router.push({
  61. pathname: '/news/list/editNewsList',
  62. query: {
  63. id
  64. },
  65. });
  66. }
  67. /**
  68. *卡片
  69. *
  70. * @returns
  71. */
  72. function CartBody(props) {
  73. const { data } = props
  74. console.log(data);
  75. const cancelPage = () => {
  76. router.push({
  77. pathname: '/news/list/NewsList',
  78. });
  79. }
  80. //删除资讯
  81. const changeNewsListStatus = (row, newsId) => () => {
  82. Modal.confirm({
  83. title: '资讯会被删除,小程序端和后台都无法再看到',
  84. okText: '确认',
  85. cancelText: '取消',
  86. onOk() {
  87. request({ ...apis.news.put, urlData: { id: newsId }, data: { ...row, status: -1 } }).then((data) => {
  88. message.info('操作成功!')
  89. getList({ pageNum: 1, pageSize: 10 });
  90. }).catch((err) => {
  91. console.log(err)
  92. message.info(err.msg || err.message)
  93. })
  94. }
  95. });
  96. }
  97. // 跳转到编辑资讯列表
  98. const toEditList = (newsId) => () => {
  99. router.push({
  100. pathname: '/news/list/editNewsList',
  101. query: {
  102. newsId
  103. },
  104. });
  105. }
  106. // 置顶
  107. const topNews = (weightParam, newsId) => () => {
  108. const weight = Math.abs(weightParam - 1)
  109. request({ ...apis.news.weight, params: {newsId: newsId, weight} }).then((data) => {
  110. console.log(data)
  111. message.info('操作成功!')
  112. getList({ pageNum: 1, pageSize: 10 })
  113. }).catch((err) => {
  114. console.log(err)
  115. message.info(err.msg || err.message)
  116. })
  117. }
  118. function cancelRelease(newsId, newsStatus, buildingId, newsTypeId) {
  119. console.log("newsId" + newsId + "status" + newsStatus);
  120. if (newsStatus === 1) {
  121. Modal.confirm({
  122. title: '资讯会在小程序端隐藏,后台可继续编辑重新发布',
  123. okText: '确认',
  124. cancelText: '取消',
  125. onOk() {
  126. request({ ...apis.news.cancel, data: { "newsStatus": newsStatus, "buildingId": buildingId, "newsTypeId": newsTypeId }, urlData: { id: newsId }, }).then((data) => {
  127. message.info('操作成功!')
  128. getList({ pageNum: 1, pageSize: 10 });
  129. }).catch((err) => {
  130. console.log(err)
  131. message.info(err.msg || err.message)
  132. })
  133. },
  134. onCancel() {
  135. console.log('Cancel');
  136. },
  137. });
  138. } else if (newsStatus === 0) {
  139. Modal.confirm({
  140. title: '确认发布该资讯?',
  141. okText: '确认',
  142. cancelText: '取消',
  143. onOk() {
  144. request({ ...apis.news.cancel, data: { "newsStatus": newsStatus, "buildingId": buildingId, "newsTypeId": newsTypeId }, urlData: { id: newsId }, }).then((data) => {
  145. message.info('操作成功!')
  146. getList({ pageNum: 1, pageSize: 10 });
  147. }).catch((err) => {
  148. console.log(err)
  149. message.info(err.msg || err.message)
  150. })
  151. },
  152. onCancel() {
  153. console.log('Cancel');
  154. },
  155. });
  156. }
  157. }
  158. return (
  159. <Card
  160. hoverable
  161. style={{ height: '230px', minWidth: '570px', borderRadius: '12px', margin: '10px', boxShadow: '0px 0px 16px 2px rgba(0,0,0,0.12)', position: 'relative' }}
  162. cover={<img alt="example" src={data.newsImg} style={{ borderRadius: '12px 0 0 12px', width: '230px', height: '228px' }}></img>}
  163. bodyStyle={{ padding: '10px 20px' }}
  164. >
  165. <AuthButton name="admin.taNews.weight.put" noRight={null}>
  166. <span style={{ position: 'absolute', right: '100px', top: '19px', fontSize: ' 0.106rem',zIndex:1, color: '#FF7E48', cursor: 'pointer' }} onClick={topNews(data.weight, data.newsId)}>{ data.weight === 1 ? '取消置顶' : '置顶' }</span>
  167. </AuthButton>
  168. <AuthButton name="admin.taNews.id.put" noRight={null}>
  169. <span style={{ position: 'absolute', right: '20px', top: '20px', fontSize: ' 0.106rem',zIndex:1, color: '#FF7E48', cursor: 'pointer' }} onClick={toEditList(data.newsId)}>
  170. 编辑
  171. <Icon type="form" style={{ color: '#C0C4CC', marginLeft: '10px' }} />
  172. </span>
  173. {data.newsStatus === 0 ?
  174. <span style={{ position: 'absolute', left: '250px', bottom: ' 10px', fontSize: ' 0.106rem', color: '#FF7E48', zIndex: 1, cursor: 'pointer' }} onClick={cancelRelease.bind(this, data.newsId, 1, data.buildingId, data.newsType.newsTypeId)}>
  175. 取消发布
  176. <Icon type="close-circle" style={{ color: '#C0C4CC', marginLeft: '8px' }} />
  177. </span> :
  178. <span style={{ position: 'absolute', left: '250px', bottom: ' 10px', fontSize: ' 0.106rem', color: '#FF7E48', zIndex: 1, cursor: 'pointer' }} onClick={cancelRelease.bind(this, data.newsId, 0, data.buildingId, data.newsType.newsTypeId)}>
  179. 发布
  180. <Icon type="form" style={{ color: '#C0C4CC', marginLeft: '8px' }} />
  181. </span>
  182. }
  183. </AuthButton>
  184. <AuthButton name="admin.taNews.id.delete" noRight={null}>
  185. <span style={{ position: 'absolute', right: '20px', bottom: ' 10px', fontSize: ' 0.106rem', color: '#FF7E48', cursor: 'pointer', zIndex: 1 }} onClick={changeNewsListStatus(data, data.newsId)}>
  186. 删除
  187. <Icon type="rest" style={{ color: '#C0C4CC', marginLeft: '8px' }} />
  188. </span>
  189. </AuthButton>
  190. <div style={{ position: 'absolute', left: '240px', top: '0px', padding: '16px 10px', width: '64%' }}>
  191. <p style={{
  192. fontSize: ' 0.106rem', color: '#333', fontWeight: '600', marginBottom: '10px', overflow: 'hidden',
  193. textOverflow: 'ellipsis',
  194. whiteSpace: 'nowrap',
  195. width: '75%',
  196. }}>{data.newsName}</p>
  197. <p style={{ fontSize: ' 0.106rem', color: '#555', marginBottom: '8px', display: 'flex' }}>
  198. <span style={{ display: 'inline-block', width: '50%', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>资讯类型:{data.newsType.newsTypeName}</span>
  199. <span>状态:{data.newsStatus == 0 ? "已发布" : "未发布"}</span>
  200. </p>
  201. <p style={{ fontSize: ' 0.106rem', color: '#555', marginBottom: '8px', display: 'flex', alignItems: 'center' }}>
  202. <span style={{ display: 'inline-block', width: '50%', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>阅读数量:{data.pvNum}</span>
  203. <span>转发数量:{data.shareNum}</span>
  204. </p>
  205. <p style={{ fontSize: ' 0.106rem', color: '#555', marginBottom: '8px', display: 'flex', alignItems: 'center' }}>
  206. <span style={{ display: 'inline-block', width: '50%', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>点赞数量:{data.favorNum}</span>
  207. <span>收藏数量:{data.saveNum}</span>
  208. </p>
  209. <p style={{ fontSize: ' 0.106rem', color: '#999', marginBottom: '8px' }}>发布时间:{moment(data.createDate).format('YYYY-MM-DD HH:mm:ss')}</p>
  210. </div>
  211. </Card>
  212. )
  213. }
  214. // Change 事件
  215. function handleSelectChange(e) {
  216. // eslint-disable-next-line no-console
  217. console.log(e)
  218. }
  219. // 分页
  220. function onChange(pageNumber) {
  221. // eslint-disable-next-line react-hooks/rules-of-hooks
  222. getList({ pageNum: pageNumber, pageSize: 6 })
  223. }
  224. //重置搜索
  225. function handleReset() {
  226. props.form.resetFields();
  227. }
  228. function getDate(value, dateString) {
  229. // moment(value).format('YYYY-MM-DD HH:mm:ss')
  230. console.log(value, dateString)
  231. }
  232. return (
  233. <>
  234. <Form layout="inline" onSubmit={e => handleSubmit(e, props)}>
  235. <Form.Item>
  236. {getFieldDecorator('cityId')(
  237. <SelectCity />,
  238. )}
  239. </Form.Item>
  240. <Form.Item>
  241. {getFieldDecorator('buildingId')(
  242. <BuildSelect />,
  243. )}
  244. </Form.Item>
  245. <Form.Item>
  246. {getFieldDecorator('title')(
  247. <Input
  248. prefix={<Icon type="text" style={{ color: 'rgba(0,0,0,.25)' }} />}
  249. placeholder="请输入标题"
  250. />,
  251. )}
  252. </Form.Item>
  253. <Form.Item>
  254. {getFieldDecorator('newsTypeId')(
  255. <NewsTypeSelect />,
  256. )}
  257. </Form.Item>
  258. <Form.Item>
  259. {getFieldDecorator('newsStatus')(
  260. <Select style={{ width: '180px' }} placeholder="状态">
  261. <Option value="0">已发布</Option>
  262. <Option value="1">未发布</Option>
  263. </Select>,
  264. )}
  265. </Form.Item>
  266. <Form.Item>
  267. <Button type="primary" htmlType="submit" >
  268. 搜索
  269. </Button>
  270. <Button style={{ marginLeft: 8 }} onClick={handleReset}>
  271. 重置
  272. </Button>
  273. </Form.Item>
  274. </Form>
  275. <AuthButton name="admin.taNews.post" noRight={null}>
  276. <Button type="danger" style={{ padding: '0 40px', margin: '20px 0' }} onClick={toEditList()}>
  277. 新增
  278. </Button>
  279. </AuthButton>
  280. {/* 卡片内容,显示楼盘项目 */}
  281. <Row>
  282. {
  283. dataSource.records.map((item, index) => (
  284. <Col span={12}>
  285. <CartBody data={item} key={item.buildingId} />
  286. </Col>
  287. ))
  288. }
  289. </Row>
  290. {/* 分页 */}
  291. <div style={{ display: 'flex', justifyContent: 'flex-end', marginTop: '30px' }}>
  292. <Pagination showQuickJumper defaultCurrent={1} total={dataSource.total} onChange={onChange} current={dataSource.current}/>
  293. </div>
  294. </>
  295. );
  296. }
  297. const WrappedBody = Form.create({ name: 'body' })(body);
  298. export default WrappedBody