index.jsx 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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).trim())
  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. this.templateSearch();
  113. }
  114. componentWillReceiveProps(next){
  115. //点清空恢复初始状态
  116. if(this.props.clearSearch!==next.clearSearch){
  117. this.clear();
  118. }
  119. }
  120. render() {
  121. const { checkItemsAdmin,handleAllCheckboxAdmin,handleMangerTemplateAdmin,allCheckShowAdmin,admin,adminItems,allCheckShow, handleMangerTemplate,handleClickGetMore, handleDelList, handleAllCheckbox, items,checkItems,current,hasMore } = this.props;
  122. const {height} = this.state
  123. return (
  124. <div className={style.wrapper} >
  125. {//管理员操作
  126. adminItems&&admin ? (allCheckShowAdmin ?
  127. <div className={style.wrapperTop}>
  128. <div className={style['check-wrap']} onClick={handleAllCheckboxAdmin} style={{paddingLeft:'10px'}}>
  129. <img className={`${style['fl-element']} ${style['check-box']}`} src={this.getCheckIcon()} />
  130. </div>
  131. <span onClick={handleAllCheckboxAdmin}>全选</span>
  132. <span className={`${style['fr-element']} ${style['done']}`} onClick={handleMangerTemplateAdmin}>完成</span>
  133. {
  134. checkItemsAdmin.length>0?<span className={`${style['fr-element']} ${style['del-items']}`} onClick={handleDelList}>删除</span>:
  135. <span className={`${style['fr-element']} ${style['del-items-gray']}`}>删除</span>
  136. }
  137. </div> :
  138. <div className={style.wrapperTop}>
  139. <div className={style.templateSearch}>
  140. <input placeholder="模板搜索" maxLength="30" ref={this.$search} type="text" onInput={this.handleChange} onPropertyChange={this.handleChange} onKeyUp={this.handleEnter}/>
  141. {this.state.val?<img src={delIcon} alt="清空" onClick={this.clear}/>:''}
  142. <div className={style.search} onClick={this.templateSearch}>搜索</div>
  143. </div>
  144. {
  145. adminItems.length > 0&&<span className={`${style['fr-element']} ${style['manger']}`} onClick={handleMangerTemplateAdmin}>管理</span>
  146. }
  147. </div>) : null
  148. }
  149. {//个人
  150. items&&!admin ?
  151. <div className={style.wrapperTop}>
  152. <div className={style.templateSearch}>
  153. <input placeholder="模板搜索" id='templateSearch' maxLength="30" ref={this.$search} type="text" onInput={this.handleChange} onPropertyChange={this.handleChange} onKeyUp={this.handleEnter}/>
  154. {this.state.val?<img src={delIcon} alt="清空" onClick={this.clear}/>:''}
  155. <div className={style.search} onClick={this.templateSearch}>搜索</div>
  156. </div>
  157. </div> : null
  158. }
  159. {
  160. <div className={style.comAdminWrp}>
  161. <div className={`${style.tempLists} ${style.tempListsP}`} ref={this.$cont} style={{display:admin?'none':'block',border:'1px solid #EAEDF1'}}>
  162. {//个人
  163. allCheckShow&&!admin ?<div className={`${style.wrapperTop} ${style.wrapperTopM} ${style.personalTmp}`}>
  164. <i></i>
  165. <i></i>
  166. <div className={style['check-wrap']} onClick={handleAllCheckbox}>
  167. <img className={`${style['fl-element']} ${style['check-box']}`} src={this.getCheckIcon()} />
  168. </div>
  169. <span onClick={handleAllCheckbox}>全选</span>
  170. <span className={`${style['fr-element']} ${style['done']}`} onClick={handleMangerTemplate}>完成</span>
  171. {
  172. checkItems.length>0?<span className={`${style['fr-element']} ${style['del-items']}`} onClick={handleDelList}>删除</span>:
  173. <span className={`${style['fr-element']} ${style['del-items-gray']}`}>删除</span>
  174. }
  175. </div>:null
  176. }
  177. {
  178. !allCheckShow&&<div className={`${style.personalTmp} clearfix`}>
  179. <span className={style.tip}>个人模板</span>
  180. <i></i>
  181. {
  182. items.length > 0&&<span className={`${style['fr-element']} ${style['manger']}`} onClick={handleMangerTemplate}>管理</span>
  183. }
  184. </div>
  185. }
  186. {
  187. <div style={{height:height/2-42+'px',overflow:'auto'}}>
  188. {this.genItems(items).length > 0?this.genItems(items): <Empty message={this.state.msg}></Empty>}
  189. </div>
  190. }
  191. </div>
  192. <div className={style.tempLists} ref={this.$conts} style={{border:admin?'0':'1px solid #EAEDF1'}}>
  193. {
  194. !admin?!allCheckShowAdmin&&<div className={`${style.personalTmp}`}>标准模板</div>:''
  195. }
  196. {
  197. <div style={{height:admin?height+'px':(height-20)/2-42+'px',overflow:'auto'}}>
  198. {this.genItems(adminItems,true).length > 0?this.genItems(adminItems,true): <Empty message={this.state.msg}></Empty>}
  199. </div>
  200. }
  201. </div>
  202. </div>
  203. }
  204. {/* <div className={style.tempLists} ref={this.$cont}>
  205. {
  206. this.genItems().length > 0?this.genItems(): <Empty message={this.state.msg}></Empty>
  207. }
  208. {//注释掉的暂时没有分也功能
  209. hasMore?<p onClick={()=>handleClickGetMore(current)} className={style.loadMore}>点击查看更多</p>:null
  210. }
  211. </div> */}
  212. </div>
  213. )
  214. }
  215. }
  216. export default TemplateItems;
  217. TemplateItems.propTypes = {
  218. items: PropTypes.arrayOf(PropTypes.object),
  219. handleContentClick: PropTypes.func,
  220. handleUpdate: PropTypes.func,
  221. handleTemplateDel: PropTypes.func,
  222. handleTitleChange: PropTypes.func
  223. };