index.jsx 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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 delIcon from '@common/images/del_nor.png';
  7. import check_right from './TemplateItem/img/check-right.png';
  8. import Empty from '@components/Empty';
  9. import {windowEventHandler,getWindowInnerHeight} from '@utils/tools'
  10. class TemplateItems extends React.Component {
  11. constructor(props) {
  12. super(props);
  13. this.state = {
  14. msg:'还没有保存模板',
  15. val:''
  16. }
  17. this.$cont = React.createRef();
  18. this.$search = React.createRef();
  19. this.genItems = this.genItems.bind(this);
  20. this.templateSearch = this.templateSearch.bind(this);
  21. this.handleEnter = this.handleEnter.bind(this);
  22. this.handleChange = this.handleChange.bind(this);
  23. this.clear = this.clear.bind(this);
  24. }
  25. componentDidMount(){
  26. const height = getWindowInnerHeight()-195;
  27. this.$cont.current.style.height = height+"px";
  28. windowEventHandler('resize', ()=>{
  29. if(this.$cont.current){
  30. const height = getWindowInnerHeight()-195;
  31. this.$cont.current.style.height = height+"px";
  32. }
  33. });
  34. }
  35. genItems() {
  36. const Items = [];
  37. this.props.items.forEach((v,idx) => {
  38. Items.push(
  39. <TemplateItem
  40. {...v}
  41. key={v.id}
  42. idx={idx}
  43. checkItems={this.props.checkItems}
  44. allCheckShow={this.props.allCheckShow}
  45. handleContentClick={this.props.handleContentClick}
  46. handleTemplateDel={this.props.handleTemplateDel}
  47. handleTitleChange={this.props.handleTitleChange}
  48. />
  49. );
  50. });
  51. return Items;
  52. }
  53. getCheckIcon() {
  54. if (this.props.items.length == this.props.checkItems.length && this.props.checkItems.length != 0) {
  55. return check_right;
  56. } else {
  57. return check_circle;
  58. }
  59. }
  60. templateSearch(){
  61. const {templateSearch} = this.props
  62. templateSearch(this.$search.current.value)
  63. if(this.$search.current.value.trim()){
  64. this.setState({
  65. msg:'暂无模板信息'
  66. })
  67. }else{
  68. this.setState({
  69. msg:'还没有保存模板'
  70. })
  71. }
  72. }
  73. handleEnter(e){
  74. if(e.keyCode==13){
  75. this.templateSearch();
  76. }
  77. }
  78. handleChange(){
  79. const value = (this.$search.current.value).substring(0,30);
  80. // this.$search.current.value = value
  81. setTimeout(() => {
  82. this.setState({
  83. val: value
  84. });
  85. }, 30);
  86. // if (value === '') {
  87. // this.setState({
  88. // val: ''
  89. // });
  90. // }
  91. }
  92. clear(){
  93. this.$search.current.value = '';
  94. this.setState({
  95. val:''
  96. })
  97. this.$search.current.focus();
  98. }
  99. render() {
  100. const { allCheckShow, handleMangerTemplate,handleClickGetMore, handleDelList, handleAllCheckbox, items,checkItems,current,hasMore } = this.props;
  101. // console.log(allCheckShow,7877877)
  102. return (
  103. <div className={style.wrapper}>
  104. {
  105. items ? (allCheckShow ?
  106. <div className={style.wrapperTop}>
  107. <div className={style['check-wrap']} onClick={handleAllCheckbox}>
  108. <img className={`${style['fl-element']} ${style['check-box']}`} src={this.getCheckIcon()} />
  109. </div>
  110. <span onClick={handleAllCheckbox}>全选</span>
  111. <span className={`${style['fr-element']} ${style['done']}`} onClick={handleMangerTemplate}>完成</span>
  112. {
  113. checkItems.length>0?<span className={`${style['fr-element']} ${style['del-items']}`} onClick={handleDelList}>删除</span>:
  114. <span className={`${style['fr-element']} ${style['del-items-gray']}`}>删除</span>
  115. }
  116. </div> :
  117. <div className={style.wrapperTop}>
  118. <div className={style.templateSearch}>
  119. <input placeholder="模板搜索" maxLength="30" ref={this.$search} type="text" onInput={this.handleChange} onPropertyChange={this.handleChange} onKeyUp={this.handleEnter}/>
  120. {this.state.val?<img src={delIcon} alt="清空" onClick={this.clear}/>:''}
  121. <div className={style.search} onClick={this.templateSearch}>搜索</div>
  122. </div>
  123. {
  124. items.length > 0&&<span className={`${style['fr-element']} ${style['manger']}`} onClick={handleMangerTemplate}>管理</span>
  125. }
  126. </div>) : <div style={{height:'36px'}}></div>
  127. }
  128. <div className={style.tempLists} ref={this.$cont}>
  129. {
  130. this.genItems().length > 0?this.genItems(): <Empty message={this.state.msg}></Empty>
  131. }
  132. {/* {//注释掉的暂时没有分也功能
  133. hasMore?<p onClick={()=>handleClickGetMore(current)} className={style.loadMore}>点击查看更多</p>:null
  134. } */}
  135. </div>
  136. </div>
  137. )
  138. }
  139. }
  140. export default TemplateItems;
  141. TemplateItems.propTypes = {
  142. items: PropTypes.arrayOf(PropTypes.object),
  143. handleContentClick: PropTypes.func,
  144. handleUpdate: PropTypes.func,
  145. handleTemplateDel: PropTypes.func,
  146. handleTitleChange: PropTypes.func
  147. };