index.jsx 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import React from "react";
  2. import Taro from "@tarojs/taro";
  3. import { Popup, Button, Cell, Icon, Empty } from "@antmjs/vantui";
  4. import { ScrollView, View } from "@tarojs/components";
  5. import { getSysOrg } from "@/services/sysorg";
  6. import VABC from "@/components/VABC";
  7. import Tree from "@/components/Tree";
  8. import { arr2Tree } from "@/utils/array";
  9. const wrapperStyle = {
  10. width: "90vw",
  11. height: "100vh",
  12. paddingBottom: "env(safe-area-inset-bottom)",
  13. };
  14. export default function OrgTree(props) {
  15. const { show, onCancel, onChange } = props;
  16. const [dict, setDict] = React.useState([]);
  17. const [checked, setChecked] = React.useState();
  18. const onSubmit = () => {
  19. if (!checked) return;
  20. onChange(checked?.orgId, checked);
  21. };
  22. const onCheck = (e, it) => {
  23. // e.stopPropagation();
  24. // e.preventDefault();
  25. setChecked(it);
  26. };
  27. React.useEffect(() => {
  28. getSysOrg({
  29. pageSize: 500,
  30. isResponsible: 1,
  31. parentId: props.parentId,
  32. }).then((res) => {
  33. const [treeData] = arr2Tree(res.records || [], "orgPId", "orgId");
  34. console.log("-------treeData-------", treeData);
  35. setDict(treeData);
  36. });
  37. }, [props.parentId]);
  38. return (
  39. <Popup position="right" show={show} onClose={onCancel}>
  40. <VABC
  41. footer={
  42. <View style={{ padding: "8px 2em" }}>
  43. <Button block type="primary" disabled={!checked} onClick={onSubmit}>
  44. 确定
  45. </Button>
  46. </View>
  47. }
  48. style={wrapperStyle}
  49. >
  50. <ScrollView scrollY style={{ height: "100%" }}>
  51. {dict.length == 0 ? (
  52. <Empty description="暂无数据" />
  53. ) : (
  54. <Tree
  55. data={dict}
  56. renderTitle={(it) => (
  57. <Cell
  58. title={it.name}
  59. value={
  60. <View>
  61. {checked?.orgId == it.orgId ? (
  62. <Icon name="success" color="#1A7565" />
  63. ) : (
  64. <View style={{ width: "100%", minHeight: "10px" }} />
  65. )}
  66. </View>
  67. }
  68. renderIcon={
  69. it.children?.length > 0 ? (
  70. <Icon name="arrow" />
  71. ) : (
  72. <View style={{ minWidth: "16px" }} />
  73. )
  74. }
  75. onClick={(e) => onCheck(e, it)}
  76. />
  77. )}
  78. />
  79. )}
  80. </ScrollView>
  81. </VABC>
  82. </Popup>
  83. );
  84. }