index.jsx 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. windowEventHandler('resize', ()=>{
  19. if(this.$cont.current){
  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,handleClickGetMore, handleDelList, handleAllCheckbox, items,checkItems,current,hasMore } = this.props;
  52. // console.log(hasMore,current,7877877)
  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. {/* {//注释掉的暂时没有分也功能
  78. hasMore?<p onClick={()=>handleClickGetMore(current)} className={style.loadMore}>点击查看更多</p>:null
  79. } */}
  80. </div>
  81. </div>
  82. )
  83. }
  84. }
  85. export default TemplateItems;
  86. TemplateItems.propTypes = {
  87. items: PropTypes.arrayOf(PropTypes.object),
  88. handleContentClick: PropTypes.func,
  89. handleUpdate: PropTypes.func,
  90. handleTemplateDel: PropTypes.func,
  91. handleTitleChange: PropTypes.func
  92. };