index.jsx 3.7 KB

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