|
| 1 | +import React, { useState } from "react"; |
| 2 | +import PropTypes from "prop-types"; |
| 3 | +import styled from "styled-components"; |
| 4 | +// import config from '../../../../config'; |
| 5 | +// import req from '../../../../req'; |
| 6 | +import foldIcon from "../../../img/[email protected]"; |
| 7 | +import unfoldIcon from "../../../img/[email protected]"; |
| 8 | +import editIcon from "../../../img/[email protected]"; |
| 9 | +import deleteIcon from "../../../img/[email protected]"; |
| 10 | +import chooseIcon from "../../../img/[email protected]"; |
| 11 | + |
| 12 | +const StyledItem = styled.div` |
| 13 | + height: 50px; |
| 14 | + .icon { |
| 15 | + width: 30px; |
| 16 | + height: 30px; |
| 17 | + } |
| 18 | + .content { |
| 19 | + text-align: right; |
| 20 | + overflow: hidden; |
| 21 | + border-bottom: 1px solid #e6e6e6; |
| 22 | + } |
| 23 | + .name, |
| 24 | + .count { |
| 25 | + font-size: 16px; |
| 26 | + color: rgba(33, 39, 50, 0.85); |
| 27 | + } |
| 28 | + .name { |
| 29 | + white-space: nowrap; |
| 30 | + word-break: break-all; |
| 31 | + overflow: hidden; |
| 32 | + text-overflow: ellipsis; |
| 33 | + } |
| 34 | + .count { |
| 35 | + margin-left: 4px; |
| 36 | + } |
| 37 | + .choose_icon, |
| 38 | + .edit_icon, |
| 39 | + .delete_icon { |
| 40 | + width: 40px; |
| 41 | + height: 40px; |
| 42 | + } |
| 43 | +`; |
| 44 | + |
| 45 | +function Page({ hasDelete, info, selectList, departmentCountMap, space, isLast }) { |
| 46 | + console.log("isLast", isLast, info); |
| 47 | + const [showAll, setShowAll] = useState(false); |
| 48 | + return ( |
| 49 | + <> |
| 50 | + <StyledItem data-flex="main:left cross:center" style={{ paddingLeft: space * 28 }}> |
| 51 | + {showAll ? ( |
| 52 | + <img className="icon" src={unfoldIcon} alt="" data-flex-box="0" onClick={() => setShowAll(!showAll)} /> |
| 53 | + ) : ( |
| 54 | + <img src={foldIcon} className="icon" data-flex-box="0" alt="" onClick={() => setShowAll(!showAll)} /> |
| 55 | + )} |
| 56 | + <div |
| 57 | + className="content" |
| 58 | + data-flex-box="1" |
| 59 | + data-flex="main:left cross:center" |
| 60 | + style={{ |
| 61 | + borderBottomColor: isLast && (!info.childDepartment.length || !showAll) ? "transparent" : "#e6e6e6", |
| 62 | + }} |
| 63 | + > |
| 64 | + <div className="name">{info.departmentName}</div> |
| 65 | + {!!departmentCountMap[info.departmentId] && ( |
| 66 | + <div className="count">{departmentCountMap[info.departmentId]}</div> |
| 67 | + )} |
| 68 | + <div data-flex-box="1" style={{ marginLeft: 20 }} /> |
| 69 | + {hasDelete ? ( |
| 70 | + <> |
| 71 | + <img className="edit_icon" src={editIcon} data-flex-box="0" alt="" /> |
| 72 | + <img className="delete_icon" src={deleteIcon} data-flex-box="0" alt="" /> |
| 73 | + </> |
| 74 | + ) : ( |
| 75 | + selectList.includes(info.departmentId) && ( |
| 76 | + <img className="check_icon" src={chooseIcon} data-flex-box="0" alt="" /> |
| 77 | + ) |
| 78 | + )} |
| 79 | + </div> |
| 80 | + </StyledItem> |
| 81 | + {showAll && |
| 82 | + info.childDepartment.map((item, index) => ( |
| 83 | + <Page |
| 84 | + hasDelete={hasDelete} |
| 85 | + info={item} |
| 86 | + space={space + 1} |
| 87 | + key={item.departmentId} |
| 88 | + selectList={selectList} |
| 89 | + isLast={index === info.childDepartment.length - 1} |
| 90 | + departmentCountMap={departmentCountMap} |
| 91 | + /> |
| 92 | + ))} |
| 93 | + </> |
| 94 | + ); |
| 95 | +} |
| 96 | +Page.propTypes = { |
| 97 | + hasDelete: PropTypes.bool, |
| 98 | + info: PropTypes.object.isRequired, |
| 99 | + selectList: PropTypes.array, |
| 100 | + departmentCountMap: PropTypes.object, |
| 101 | + space: PropTypes.number, |
| 102 | + isLast: PropTypes.bool, |
| 103 | +}; |
| 104 | +Page.defaultProps = { |
| 105 | + hasDelete: false, |
| 106 | + isLast: false, |
| 107 | + selectList: [], |
| 108 | + departmentCountMap: {}, |
| 109 | + space: 0, |
| 110 | +}; |
| 111 | + |
| 112 | +export default Page; |
0 commit comments