知与行后台管理端

index.jsx 10.0KB

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