知与行后台管理端

index.jsx 9.2KB

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