index.jsx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. if(this.$cont.current){
  20. windowEventHandler('resize', ()=>{
  21. const height = getWindowInnerHeight()-206;
  22. this.$cont.current.style.height = height+"px";
  23. });
  24. }
  25. }
  26. genItems() {
  27. const Items = [];
  28. this.props.items.forEach((v,idx) => {
  29. Items.push(
  30. <TemplateItem
  31. {...v}
  32. key={v.id}
  33. idx={idx}
  34. checkItems={this.props.checkItems}
  35. allCheckShow={this.props.allCheckShow}
  36. handleContentClick={this.props.handleContentClick}
  37. handleTemplateDel={this.props.handleTemplateDel}
  38. handleTitleChange={this.props.handleTitleChange}
  39. />
  40. );
  41. });
  42. return Items;
  43. }
  44. getCheckIcon() {
  45. if (this.props.items.length == this.props.checkItems.length && this.props.checkItems.length != 0) {
  46. return check_right;
  47. } else {
  48. return check_circle;
  49. }
  50. }
  51. render() {
  52. const { allCheckShow, handleMangerTemplate, handleDelList, handleAllCheckbox, items,checkItems } = this.props;
  53. return (
  54. <div className={style.wrapper}>
  55. {
  56. items && items.length > 0 ? (allCheckShow ?
  57. <div className={style.wrapperTop}>
  58. <div className={style['check-wrap']} onClick={handleAllCheckbox}>
  59. <img className={`${style['fl-element']} ${style['check-box']}`} src={this.getCheckIcon()} />
  60. </div>
  61. <span onClick={handleAllCheckbox}>全选</span>
  62. <span className={`${style['fr-element']} ${style['done']}`} onClick={handleMangerTemplate}>完成</span>
  63. {
  64. checkItems.length>0?<span className={`${style['fr-element']} ${style['del-items']}`} onClick={handleDelList}>删除</span>:
  65. <span className={`${style['fr-element']} ${style['del-items-gray']}`}>删除</span>
  66. }
  67. </div> :
  68. <div className={style.wrapperTop}>
  69. <span className={`${style['fr-element']} ${style['manger']}`} onClick={handleMangerTemplate}>管理</span>
  70. </div>) : <div style={{height:'36px'}}></div>
  71. }
  72. <div className={style.tempLists} ref={this.$cont}>
  73. {
  74. this.genItems().length > 0?this.genItems():
  75. <Empty message={'还没有保存模板'}></Empty>
  76. }
  77. </div>
  78. </div>
  79. )
  80. }
  81. }
  82. export default TemplateItems;
  83. TemplateItems.propTypes = {
  84. items: PropTypes.arrayOf(PropTypes.object),
  85. handleContentClick: PropTypes.func,
  86. handleUpdate: PropTypes.func,
  87. handleTemplateDel: PropTypes.func,
  88. handleTitleChange: PropTypes.func
  89. };