SalesBatchGroup.jsx 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import React, { useState, useEffect } from 'react';
  2. import { Form, Select, Modal, Button, Table, Divider, Tag, Input } from 'antd';
  3. import { apis, fetch } from '../../utils/request';
  4. import Navigate from '@/components/Navigate';
  5. const { Search } = Input;
  6. const getGroupList = fetch(apis.house.taSalesBatch)
  7. export default props => {
  8. const {
  9. value,
  10. onChange,
  11. ...rest
  12. } = props;
  13. const [list, setList] = useState([]);
  14. const [visible, setVisible] = useState(false);
  15. const [group, setGroup] = useState({ groupId: undefined, groupName: '请选择销售批次' })
  16. const getGroupTitle = val => {
  17. return (list.filter(x => x.salesBatchId == val)[0] || {}).salesBatchName || '请选择销售批次'
  18. }
  19. const updateGroup = val => setGroup({ groupId: val, groupName: getGroupTitle(val) })
  20. const buildingId = props.buildingId()
  21. useEffect(() => {
  22. getGroupList({
  23. params: {
  24. buildingId,
  25. pageNum: 1,
  26. pageSize: 999,
  27. status: 1,
  28. },
  29. }).then(data => {
  30. setList(data.records || [])
  31. updateGroup(buildingId ? undefined : value);
  32. })
  33. }, [buildingId]);
  34. const searchGroup = (e) => {
  35. getGroupList({
  36. params: {
  37. buildingId,
  38. pageNum: 1,
  39. pageSize: 999,
  40. status: 1,
  41. salesBatchName: e
  42. }
  43. }).then((data) => {
  44. setList(data.records || [])
  45. updateGroup(buildingId ? undefined : value);
  46. // setAct(buildingId ? undefined : value);
  47. })
  48. }
  49. if (value !== group.groupId) {
  50. updateGroup(value);
  51. }
  52. const handleChange = val => {
  53. onChange(val)
  54. }
  55. const setData = val => {
  56. updateGroup(val)
  57. onChange(val)
  58. setVisible(false)
  59. }
  60. const columns = [
  61. {
  62. title: '标题',
  63. dataIndex: 'salesBatchName',
  64. key: 'salesBatchId',
  65. align: 'center',
  66. ellipsis: true,
  67. render: text => <a>{text}</a>,
  68. },
  69. {
  70. title: '操作',
  71. align: 'center',
  72. width: '20%',
  73. render: (text, record) => (
  74. <Navigate onClick={() => setData(record.salesBatchId)}>选择</Navigate>
  75. ),
  76. },
  77. ];
  78. return (
  79. <div>
  80. <div ><Navigate onClick={() => setVisible(true)}>{group.groupName}</Navigate></div>
  81. <Modal
  82. title="请选择"
  83. visible={visible}
  84. onCancel={() => setVisible(false)}
  85. footer={[]}
  86. >
  87. <Search
  88. placeholder="请输入标题"
  89. enterButton="搜索"
  90. size="large"
  91. onSearch={value => searchGroup(value)}
  92. style={{ marginBottom: '16px' }}
  93. />
  94. <Table rowKey={list => list.salesBatchId} columns={columns} dataSource={list} />
  95. </Modal>
  96. </div>
  97. );
  98. }