知与行后台管理端

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