index.jsx 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import React, { useState, useEffect } from 'react';
  2. import { Button, notification } from 'antd';
  3. import AuthButton from '@/components/AuthButton'
  4. import request from '@/utils/request';
  5. import apis from '@/services/apis';
  6. import Form from './Form';
  7. import List from './List';
  8. export default props => {
  9. const { history } = props;
  10. const { query } = history.location;
  11. const { id } = query;
  12. const [loading, setLoading] = useState(false);
  13. const [visible, setVisible] = useState(false);
  14. const [data, setData] = useState([]);
  15. const [panoramaList, setPanoramaList] = useState([]);
  16. useEffect(() => {
  17. console.log(props);
  18. getList();
  19. getPanoramaList();
  20. }, [id]);
  21. //获取户型列表
  22. function getPanoramaList(record) {
  23. // 网路请求
  24. request({ ...apis.paorama.panoramaApartList, params: { buildingId: id } })
  25. .then(res => {
  26. setPanoramaList(res);
  27. })
  28. .catch(err => {
  29. this.openNotificationWithIcon('error', err);
  30. });
  31. }
  32. function getList(params) {
  33. setLoading(true);
  34. // 网路请求
  35. request({
  36. ...apis.paorama.list,
  37. urlData: { id },
  38. params: { ...params, apartmentType: 'apart' },
  39. })
  40. .then(res => {
  41. setLoading(false);
  42. setData(res);
  43. })
  44. .catch(err => {
  45. setLoading(false);
  46. notification.error({
  47. message: err.message,
  48. description: '',
  49. });
  50. });
  51. }
  52. const onSuccess = () => {
  53. setVisible(false);
  54. getList();
  55. };
  56. function onDelete(record) {
  57. request({ ...apis.paorama.delete, urlData: { id: record.panoramaId } })
  58. .then(res => {
  59. notification.success({ message: '删除成功' });
  60. getList();
  61. })
  62. .catch(err => {
  63. notification.error({
  64. message: err.message,
  65. });
  66. });
  67. }
  68. return (
  69. <div>
  70. <div>
  71. <AuthButton name="building.panorama.add">
  72. <Button type="primary" onClick={() => setVisible(true)}>
  73. 新增全景
  74. </Button>
  75. </AuthButton>
  76. </div>
  77. <Form
  78. visible={visible}
  79. buildingId={id}
  80. panoramaList={panoramaList}
  81. onCancel={() => setVisible(false)}
  82. onSuccess={onSuccess}
  83. />
  84. <List data={data} loading={loading} onDelete={onDelete} />
  85. </div>
  86. );
  87. };