知与行后台管理端

imageSet.jsx 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. import React, { useState, useEffect } from 'react';
  2. import { Form, Icon, Input, Button, DatePicker, Select, Card, Row, Col, Pagination, Alert, Radio, Tag, Tooltip, Tabs, Table, notification } 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 ModalImage from './modalImage';
  9. const saleType = [
  10. {
  11. id: 1,
  12. name: '待定',
  13. },
  14. {
  15. id: 2,
  16. name: '售罄',
  17. },
  18. {
  19. id: 3,
  20. name: '在售',
  21. },
  22. ]
  23. /**
  24. *图片设置
  25. *
  26. * @param {*} props
  27. * @returns
  28. */
  29. function imageSet(props) {
  30. // eslint-disable-next-line react-hooks/rules-of-hooks
  31. const [data, setData] = useState([])
  32. // eslint-disable-next-line react-hooks/rules-of-hooks
  33. const [visibleData, setVisibleData] = useState({ visible: false, apartmentId: '', buildingId: '' })
  34. // eslint-disable-next-line react-hooks/rules-of-hooks
  35. useEffect(() => {
  36. getList()
  37. }, [])
  38. function openNotificationWithIcon(type, message) {
  39. notification[type]({
  40. message,
  41. description:
  42. '',
  43. });
  44. }
  45. function getList(params) {
  46. // 网路请求
  47. request({ ...apis.building.buildingApartment, urlData: { id: props.building.buildingId }, params: { ...params } }).then(res => {
  48. setData(res)
  49. }).catch(err => {
  50. openNotificationWithIcon('error', err.message)
  51. })
  52. }
  53. /**
  54. *回调事件
  55. *
  56. */
  57. function onModalChange() {
  58. getList()
  59. setVisibleData({ visible: false, apartmentId: '', buildingId: '' })
  60. }
  61. /**
  62. *打开编辑页
  63. *
  64. * @param {*} record
  65. */
  66. function showEdi(record) {
  67. setVisibleData({ visible: true, apartmentId: record === undefined ? '' : record.apartmentId, buildingId: props.building.buildingId })
  68. }
  69. /**
  70. * 删除
  71. *
  72. * @param {*} record
  73. */
  74. function deleteApartment(record) {
  75. // 网路请求
  76. request({ ...apis.building.buildingApartmentDelete, urlData: { id: record.apartmentId } }).then(res => {
  77. getList()
  78. openNotificationWithIcon('error', '操作成功')
  79. }).catch(err => {
  80. openNotificationWithIcon('error', err.message)
  81. })
  82. }
  83. const columns = [
  84. {
  85. title: '名称',
  86. dataIndex: 'apartmentName',
  87. key: 'apartmentName',
  88. },
  89. {
  90. title: '类型',
  91. dataIndex: 'apartmentType',
  92. key: 'apartmentType',
  93. render: (_, record) => <span>{ record.apartmentType === 'apart' ? '户型' : '相册' }</span>,
  94. },
  95. {
  96. title: '销售状态',
  97. dataIndex: 'marketStatus',
  98. key: 'marketStatus',
  99. render: (_, record) => <span>{ (saleType.filter(x => x.id == record.marketStatus)[0] || {}).name }</span>,
  100. },
  101. {
  102. title: '备注',
  103. dataIndex: 'remark',
  104. key: 'remark',
  105. },
  106. {
  107. title: '创建时间',
  108. dataIndex: 'createDate',
  109. key: 'createDate',
  110. render: (_, record) => <span>{ moment(record.createDate).format('YYYY-MM-DD') }</span>,
  111. },
  112. {
  113. title: '操作',
  114. dataIndex: 'apartmentId',
  115. key: 'apartmentId',
  116. render: (_, record) => (
  117. <>
  118. <Button type="link" style={{ color: 'red' }} onClick={() => showEdi(record)}>编辑</Button>
  119. <Button type="link" style={{ color: 'red' }} onClick={() => deleteApartment(record)}>删除</Button>
  120. </>
  121. ),
  122. },
  123. ]
  124. return (
  125. <>
  126. <Button type="primary" onClick={() => showEdi()}>新增图片库</Button>
  127. <Table dataSource={data} columns={columns} pagination={false} />
  128. {/* 编辑页 */}
  129. {/* onSuccess是子组件传递事件信息 */}
  130. <ModalImage visibleData={visibleData} key={1} onSuccess={() => onModalChange()}/>
  131. </>
  132. )
  133. }
  134. export default imageSet