index.jsx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import PropTypes from "prop-types"
  2. import React from "react"
  3. import style from "./index.less"
  4. import TemplateItem from './TemplateItem'
  5. import check_circle from './TemplateItem/img/check-circle.png';
  6. import check_right from './TemplateItem/img/check-right.png';
  7. import Empty from '@components/Empty';
  8. import {getWindowInnerHeight} from '@common/js/func';
  9. import {windowEventHandler} from '@utils/tools'
  10. class TemplateItems extends React.Component {
  11. constructor(props) {
  12. super(props);
  13. this.$cont = React.createRef();
  14. this.genItems = this.genItems.bind(this);
  15. }
  16. componentDidMount(){
  17. const height = getWindowInnerHeight()-206;
  18. this.$cont.current.style.height = height+"px";
  19. windowEventHandler('resize', ()=>{
  20. const height = getWindowInnerHeight()-206;
  21. this.$cont.current.style.height = height+"px";
  22. });
  23. }
  24. genItems() {
  25. const Items = [];
  26. this.props.items.forEach((v) => {
  27. Items.push(
  28. <TemplateItem
  29. {...v}
  30. key={v.id}
  31. checkItems={this.props.checkItems}
  32. allCheckShow={this.props.allCheckShow}
  33. handleContentClick={this.props.handleContentClick}
  34. handleTemplateDel={this.props.handleTemplateDel}
  35. handleTitleChange={this.props.handleTitleChange}
  36. />
  37. );
  38. });
  39. return Items;
  40. }
  41. getCheckIcon() {
  42. if (this.props.items.length == this.props.checkItems.length && this.props.checkItems.length != 0) {
  43. return check_right;
  44. } else {
  45. return check_circle;
  46. }
  47. }
  48. render() {
  49. const { allCheckShow, handleMangerTemplate, handleDelList, handleAllCheckbox, items,checkItems } = this.props;
  50. return (
  51. <div className={style.wrapper}>
  52. {
  53. items && items.length > 0 ? (allCheckShow ?
  54. <div className={style.wrapperTop}>
  55. <div className={style['check-wrap']} onClick={handleAllCheckbox}>
  56. <img className={`${style['fl-element']} ${style['check-box']}`} src={this.getCheckIcon()} />
  57. </div>
  58. <span onClick={handleAllCheckbox}>全选</span>
  59. <span className={`${style['fr-element']} ${style['done']}`} onClick={handleMangerTemplate}>完成</span>
  60. {
  61. checkItems.length>0?<span className={`${style['fr-element']} ${style['del-items']}`} onClick={handleDelList}>删除</span>:
  62. <span className={`${style['fr-element']} ${style['del-items-gray']}`}>删除</span>
  63. }
  64. </div> :
  65. <div className={style.wrapperTop}>
  66. <span className={`${style['fr-element']} ${style['manger']}`} onClick={handleMangerTemplate}>管理</span>
  67. </div>) : <div style={{height:'36px'}}></div>
  68. }
  69. <div className={style.tempLists} ref={this.$cont}>
  70. {
  71. this.genItems().length > 0?this.genItems():
  72. <Empty message={'还没有保存模板'}></Empty>
  73. }
  74. </div>
  75. </div>
  76. )
  77. }
  78. }
  79. export default TemplateItems;
  80. TemplateItems.propTypes = {
  81. items: PropTypes.arrayOf(PropTypes.object),
  82. handleContentClick: PropTypes.func,
  83. handleUpdate: PropTypes.func,
  84. handleTemplateDel: PropTypes.func,
  85. handleTitleChange: PropTypes.func
  86. };