index.jsx 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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. height:''
  17. }
  18. this.$cont = React.createRef();
  19. this.$conts = React.createRef();
  20. this.$search = React.createRef();
  21. this.genItems = this.genItems.bind(this);
  22. this.templateSearch = this.templateSearch.bind(this);
  23. this.handleEnter = this.handleEnter.bind(this);
  24. this.handleChange = this.handleChange.bind(this);
  25. this.clear = this.clear.bind(this);
  26. }
  27. componentDidMount(){
  28. const height = getWindowInnerHeight()-195;
  29. this.setState({
  30. height:height
  31. })
  32. windowEventHandler('resize', ()=>{
  33. if(this.$conts.current){
  34. const height = getWindowInnerHeight()-195;
  35. this.setState({
  36. height:height
  37. })
  38. }
  39. });
  40. }
  41. genItems(items,flg) {
  42. const Items = [];
  43. const {admin,adminItems,checkItemsAdmin} = this.props;
  44. items.forEach((v,idx) => {
  45. Items.push(
  46. <TemplateItem
  47. {...v}
  48. key={v.id}
  49. idx={idx}
  50. checkItems={this.props.checkItems}
  51. allCheckShow={this.props.allCheckShow}
  52. handleContentClick={this.props.handleContentClick}
  53. handleTemplateDel={this.props.handleTemplateDel}
  54. handleTitleChange={this.props.handleTitleChange}
  55. admin={this.props.admin}
  56. adminflg={flg}
  57. checkItemsAdmin={checkItemsAdmin}
  58. allCheckShowAdmin={this.props.allCheckShowAdmin}
  59. />
  60. );
  61. });
  62. return Items;
  63. }
  64. getCheckIcon() {
  65. const {admin,checkItems,items,checkItemsAdmin,adminItems} = this.props;
  66. if(admin){
  67. if (adminItems.length == checkItemsAdmin.length && checkItemsAdmin.length != 0) {
  68. return check_right;
  69. } else {
  70. return check_circle;
  71. }
  72. }
  73. if (items.length == checkItems.length && checkItems.length != 0) {
  74. return check_right;
  75. } else {
  76. return check_circle;
  77. }
  78. }
  79. templateSearch(){
  80. const {templateSearch} = this.props
  81. templateSearch(this.$search.current.value)
  82. if(this.$search.current.value.trim()){
  83. this.setState({
  84. msg:'暂无模板信息'
  85. })
  86. }else{
  87. this.setState({
  88. msg:'还没有保存模板'
  89. })
  90. }
  91. }
  92. handleEnter(e){
  93. if(e.keyCode==13){
  94. this.templateSearch();
  95. }
  96. }
  97. handleChange(){
  98. const value = (this.$search.current.value).substring(0,30);
  99. // this.$search.current.value = value
  100. setTimeout(() => {
  101. this.setState({
  102. val: value
  103. });
  104. }, 30);
  105. }
  106. clear(){
  107. this.$search.current.value = '';
  108. this.setState({
  109. val:''
  110. })
  111. this.$search.current.focus();
  112. }
  113. render() {
  114. const { checkItemsAdmin,handleAllCheckboxAdmin,handleMangerTemplateAdmin,allCheckShowAdmin,admin,adminItems,allCheckShow, handleMangerTemplate,handleClickGetMore, handleDelList, handleAllCheckbox, items,checkItems,current,hasMore } = this.props;
  115. const {height} = this.state
  116. return (
  117. <div className={style.wrapper} >
  118. {//管理员操作
  119. adminItems&&admin ? (allCheckShowAdmin ?
  120. <div className={style.wrapperTop}>
  121. <div className={style['check-wrap']} onClick={handleAllCheckboxAdmin} style={{paddingLeft:'10px'}}>
  122. <img className={`${style['fl-element']} ${style['check-box']}`} src={this.getCheckIcon()} />
  123. </div>
  124. <span onClick={handleAllCheckboxAdmin}>全选</span>
  125. <span className={`${style['fr-element']} ${style['done']}`} onClick={handleMangerTemplateAdmin}>完成</span>
  126. {
  127. checkItemsAdmin.length>0?<span className={`${style['fr-element']} ${style['del-items']}`} onClick={handleDelList}>删除</span>:
  128. <span className={`${style['fr-element']} ${style['del-items-gray']}`}>删除</span>
  129. }
  130. </div> :
  131. <div className={style.wrapperTop}>
  132. <div className={style.templateSearch}>
  133. <input placeholder="模板搜索" maxLength="30" ref={this.$search} type="text" onInput={this.handleChange} onPropertyChange={this.handleChange} onKeyUp={this.handleEnter}/>
  134. {this.state.val?<img src={delIcon} id='clearTemplateSearch' alt="清空" onClick={this.clear}/>:''}
  135. <div className={style.search} onClick={this.templateSearch}>搜索</div>
  136. </div>
  137. {
  138. adminItems.length > 0&&<span className={`${style['fr-element']} ${style['manger']}`} onClick={handleMangerTemplateAdmin}>管理</span>
  139. }
  140. </div>) : null
  141. }
  142. {//个人
  143. items&&!admin ?
  144. <div className={style.wrapperTop}>
  145. <div className={style.templateSearch}>
  146. <input placeholder="模板搜索" maxLength="30" ref={this.$search} type="text" onInput={this.handleChange} onPropertyChange={this.handleChange} onKeyUp={this.handleEnter}/>
  147. {this.state.val?<img src={delIcon} alt="清空" onClick={this.clear}/>:''}
  148. <div className={style.search} onClick={this.templateSearch}>搜索</div>
  149. </div>
  150. </div> : null
  151. }
  152. {
  153. <div className={style.comAdminWrp}>
  154. <div className={`${style.tempLists} ${style.tempListsP}`} ref={this.$cont} style={{display:admin?'none':'block',border:'1px solid #EAEDF1'}}>
  155. {//个人
  156. allCheckShow&&!admin ?<div className={`${style.wrapperTop} ${style.wrapperTopM} ${style.personalTmp}`}>
  157. <i></i>
  158. <i></i>
  159. <div className={style['check-wrap']} onClick={handleAllCheckbox}>
  160. <img className={`${style['fl-element']} ${style['check-box']}`} src={this.getCheckIcon()} />
  161. </div>
  162. <span onClick={handleAllCheckbox}>全选</span>
  163. <span className={`${style['fr-element']} ${style['done']}`} onClick={handleMangerTemplate}>完成</span>
  164. {
  165. checkItems.length>0?<span className={`${style['fr-element']} ${style['del-items']}`} onClick={handleDelList}>删除</span>:
  166. <span className={`${style['fr-element']} ${style['del-items-gray']}`}>删除</span>
  167. }
  168. </div>:null
  169. }
  170. {
  171. !allCheckShow&&<div className={`${style.personalTmp} clearfix`}>
  172. <span className={style.tip}>个人模板</span>
  173. <i></i>
  174. {
  175. items.length > 0&&<span className={`${style['fr-element']} ${style['manger']}`} onClick={handleMangerTemplate}>管理</span>
  176. }
  177. </div>
  178. }
  179. {
  180. <div style={{height:height/2-42+'px',overflow:'auto'}}>
  181. {this.genItems(items).length > 0?this.genItems(items): <Empty message={this.state.msg}></Empty>}
  182. </div>
  183. }
  184. </div>
  185. <div className={style.tempLists} ref={this.$conts} style={{border:admin?'0':'1px solid #EAEDF1'}}>
  186. {
  187. !admin?!allCheckShowAdmin&&<div className={`${style.personalTmp}`}>标准模板</div>:''
  188. }
  189. {
  190. <div style={{height:admin?height+'px':(height-20)/2-42+'px',overflow:'auto'}}>
  191. {this.genItems(adminItems,true).length > 0?this.genItems(adminItems,true): <Empty message={this.state.msg}></Empty>}
  192. </div>
  193. }
  194. </div>
  195. </div>
  196. }
  197. {/* <div className={style.tempLists} ref={this.$cont}>
  198. {
  199. this.genItems().length > 0?this.genItems(): <Empty message={this.state.msg}></Empty>
  200. }
  201. {//注释掉的暂时没有分也功能
  202. hasMore?<p onClick={()=>handleClickGetMore(current)} className={style.loadMore}>点击查看更多</p>:null
  203. }
  204. </div> */}
  205. </div>
  206. )
  207. }
  208. }
  209. export default TemplateItems;
  210. TemplateItems.propTypes = {
  211. items: PropTypes.arrayOf(PropTypes.object),
  212. handleContentClick: PropTypes.func,
  213. handleUpdate: PropTypes.func,
  214. handleTemplateDel: PropTypes.func,
  215. handleTitleChange: PropTypes.func
  216. };