知与行后台管理端

index.jsx 9.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. import React, { useState, useEffect } from 'react';
  2. import { Form, Icon, Input, Button, DatePicker, Select, Card, Row, Col, Pagination, Alert, notification, Modal } from 'antd';
  3. import moment from 'moment';
  4. import request from '../../../utils/request';
  5. import apis from '../../../services/apis';
  6. import Styles from './style.less';
  7. import { router } from 'umi';
  8. const { Option } = Select;
  9. // eslint-disable-next-line @typescript-eslint/no-unused-vars
  10. const { Meta } = Card;
  11. const tempDate = [{ code: 's101' }]
  12. function openNotificationWithIcon(type, message) {
  13. notification[type]({
  14. message,
  15. description:
  16. '',
  17. });
  18. }
  19. /**
  20. *卡片
  21. *
  22. * @returns
  23. */
  24. function CartBody(props) {
  25. const { data } = props
  26. function toEdi(record) {
  27. router.push({
  28. pathname: '/building/list/add',
  29. query: {
  30. id: record.buildingId,
  31. },
  32. })
  33. }
  34. /**
  35. *发布 取消 发布
  36. *
  37. * @param {*} record
  38. */
  39. function pulicAndUnPulic(record) {
  40. const modal = Modal.confirm();
  41. const buidingStatus = record.status === 1 ? 2 : 1
  42. const title = record.status === 1 ? '确认取消发布此数据?' : '确认发布此数据?'
  43. modal.update({
  44. content: title,
  45. okText: '确认',
  46. cancelText: '关闭',
  47. onOk: () => {
  48. request({ ...apis.building.updateStatus, data: { id: record.buildingId, status: buidingStatus } }).then(() => {
  49. openNotificationWithIcon('success', '操作成功')
  50. props.onSuccess()
  51. }).catch(err => {
  52. openNotificationWithIcon('error', err.message)
  53. })
  54. modal.destroy();
  55. },
  56. onCancel: () => {
  57. modal.destroy();
  58. },
  59. });
  60. }
  61. /**
  62. *删除楼盘
  63. *
  64. * @param {*} record
  65. */
  66. function deleteBuilding(record) {
  67. const { url, method } = apis.building.deleteBuilding
  68. const tempUrl = url.substring(0, url.lastIndexOf('id')).concat(record.buildingId)
  69. const modal = Modal.confirm();
  70. modal.update({
  71. content: '确定删除此楼盘?',
  72. okText: '确认',
  73. cancelText: '关闭',
  74. onOk: () => {
  75. request({ url: tempUrl, method }).then(() => {
  76. openNotificationWithIcon('success', '操作成功')
  77. props.onSuccess()
  78. }).catch(err => {
  79. openNotificationWithIcon('error', err.message)
  80. })
  81. modal.destroy();
  82. },
  83. onCancel: () => {
  84. modal.destroy();
  85. },
  86. });
  87. }
  88. return (
  89. <Card
  90. hoverable
  91. style={{ minWidth: '400px', borderRadius: '12px', margin: '10px', boxShadow: '0px 0px 16px 2px rgba(0,0,0,0.12)' }}
  92. cover={<img alt="example" src={ data.poster } style={{ borderRadius: '12px 12px 0 0', width: '100%', height: '14vw' }}></img>}
  93. bodyStyle={{ padding: '10px 20px' }}
  94. >
  95. <p className={Styles.cardText}>
  96. <span className={Styles.title}>楼盘编号</span>
  97. <span >:{ data.code }</span>
  98. <span className={Styles.ediText} onClick={() => toEdi(data)}>
  99. 编辑
  100. <Icon type="form" style={{ color: '#C0C4CC', marginLeft: '10px' }} />
  101. </span>
  102. </p>
  103. <p className={Styles.cardText}>
  104. <span className={Styles.title}>楼盘名称</span>
  105. <span >:{ data.name }</span>
  106. </p>
  107. <p className={Styles.cardItem}>
  108. <span className={Styles.title}>均价</span>
  109. <span >
  110. :约<span style={{ color: '#FF0707', fontSize: '20px' }}> { data.price } </span>元/m
  111. </span>
  112. </p>
  113. <p className={Styles.cardItem}>
  114. <span className={Styles.title}>项目地址</span>
  115. <span className={ Styles.address }>:{ data.address }</span>
  116. </p>
  117. <p className={Styles.cardItem}>
  118. <span className={Styles.title}>发布状态</span>
  119. <span >:{ data.status === 1 ? '已发布' : '未发布' }</span>
  120. </p>
  121. <p className={Styles.cardItem}>
  122. <span className={Styles.title}>录入时间</span>
  123. <span >:{ data.createDate }</span>
  124. </p>
  125. <p style={{ margin: '15px 0', position: 'relative', fontSize: '18px' }}>
  126. <span style={{ color: '#1990FF' }} onClick={() => pulicAndUnPulic(data)}>
  127. {/* 已发布的时候,需要显示取消发布的字样 */}
  128. { data.status === 1 ? '取消发布' : '发布' }
  129. <Icon type="close-circle" style={{ color: '#C0C4CC', marginLeft: '8px' }} />
  130. </span>
  131. <span style={{
  132. color: '#FF4A4A', position: 'absolute', right: '0',
  133. }} onClick={() => deleteBuilding(data)}>
  134. 删除
  135. <Icon type="rest" style={{ color: '#C0C4CC', marginLeft: '8px' }} />
  136. </span>
  137. </p>
  138. </Card>
  139. )
  140. }
  141. /**
  142. *
  143. *
  144. * @param {*} props
  145. * @returns
  146. */
  147. function body(props) {
  148. const { getFieldDecorator } = props.form
  149. // eslint-disable-next-line react-hooks/rules-of-hooks
  150. const [dataSource, setDataSource] = useState({ records: [] })
  151. // eslint-disable-next-line react-hooks/rules-of-hooks
  152. useEffect(() => {
  153. getList({ pageNum: 1, pageSize: 9 })
  154. }, [])
  155. function getList(params) {
  156. // 网路请求
  157. request({ ...apis.building.getList, params: { ...params } }).then(res => {
  158. setDataSource(res)
  159. }).catch(err => {
  160. // eslint-disable-next-line no-unused-expressions
  161. <Alert
  162. style={{
  163. marginBottom: 24,
  164. }}
  165. message={err}
  166. type="error"
  167. showIcon
  168. />
  169. })
  170. }
  171. // 提交事件
  172. function handleSubmit(e) {
  173. e.preventDefault();
  174. props.form.validateFields((err, values) => {
  175. if (!err) {
  176. // eslint-disable-next-line no-console
  177. console.log('提交数据: ', values)
  178. const { startDate } = values
  179. getList({ pageNum: 1, pageSize: 9, ...values })
  180. }
  181. });
  182. }
  183. // Change 事件
  184. function handleSelectChange(e) {
  185. // eslint-disable-next-line no-console
  186. console.log(e)
  187. }
  188. // 分页
  189. function onChange(pageNumber) {
  190. // eslint-disable-next-line react-hooks/rules-of-hooks
  191. getList({ pageNum: pageNumber, pageSize: 9 })
  192. }
  193. function getDate(value, dateString) {
  194. // moment(value).format('YYYY-MM-DD HH:mm:ss')
  195. console.log(value, dateString)
  196. }
  197. function toAdd() {
  198. router.push({ pathname: '/building/list/add' })
  199. }
  200. return (
  201. <>
  202. <Form layout="inline" onSubmit={e => handleSubmit(e, props)}>
  203. <Form.Item>
  204. {getFieldDecorator('code')(
  205. <Input
  206. prefix={<Icon type="text" style={{ color: 'rgba(0,0,0,.25)' }} />}
  207. placeholder="楼盘编号"
  208. />,
  209. )}
  210. </Form.Item>
  211. <Form.Item>
  212. {getFieldDecorator('name')(
  213. <Input
  214. prefix={<Icon type="text" style={{ color: 'rgba(0,0,0,.25)' }} />}
  215. type="password"
  216. placeholder="楼盘名称"
  217. />,
  218. )}
  219. </Form.Item>
  220. <Form.Item>
  221. {getFieldDecorator('startDate')(
  222. <DatePicker placeholder="开盘时间" format="YYYY-MM-DD" onChange={getDate} />,
  223. )}
  224. </Form.Item>
  225. <Form.Item>
  226. {getFieldDecorator('buildingStatus')(
  227. <Select style={{ width: '180px' }} placeholder="楼盘状态" onChange={handleSelectChange}>
  228. <Option value="1">发布</Option>
  229. <Option value="0">未发布</Option>
  230. </Select>,
  231. )}
  232. </Form.Item>
  233. <Form.Item>
  234. {getFieldDecorator('marketStatus')(
  235. <Select style={{ width: '180px' }} placeholder="销售状态" onChange={handleSelectChange}>
  236. <Option value="1">已销售</Option>
  237. <Option value="0">未销售</Option>
  238. </Select>,
  239. )}
  240. </Form.Item>
  241. <Form.Item>
  242. {getFieldDecorator('cityId')(
  243. <Select style={{ width: '180px' }} placeholder="城市" onChange={handleSelectChange}>
  244. <Option value="male">male</Option>
  245. <Option value="female">female</Option>
  246. </Select>,
  247. )}
  248. </Form.Item>
  249. <Form.Item>
  250. {getFieldDecorator('isMain')(
  251. <Select style={{ width: '180px' }} placeholder="首页推荐" onChange={handleSelectChange}>
  252. <Option value="1">首页推荐</Option>
  253. <Option value="0">首页未推荐</Option>
  254. </Select>,
  255. )}
  256. </Form.Item>
  257. <Form.Item>
  258. <Button type="primary" htmlType="submit">
  259. 搜索
  260. </Button>
  261. </Form.Item>
  262. </Form>
  263. <Button type="danger" className={Styles.addButton} onClick={() => toAdd()}>
  264. 新增楼盘
  265. </Button>
  266. {/* 卡片内容,显示楼盘项目 */}
  267. <Row style={{ padding: ' 0 10px' }}>
  268. {
  269. dataSource.records.map((item, _) => (
  270. <Col span={8}>
  271. <CartBody data={item} key={item.buildingId} onSuccess={getList}/>
  272. </Col>
  273. ))
  274. }
  275. </Row>
  276. {/* 分页 */}
  277. <div style={{ display: 'flex', justifyContent: 'flex-end', marginTop: '30px' }}>
  278. <Pagination showQuickJumper defaultCurrent={1} total={dataSource.total} onChange={onChange} />
  279. </div>
  280. </>
  281. );
  282. }
  283. const WrappedBody = Form.create({ name: 'body' })(body);
  284. export default WrappedBody