index.jsx 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. import PropTypes from "prop-types";
  2. import React from "react";
  3. import style from "./index.less";
  4. import DesItem from './DesItem';
  5. import arrow_icon from './img/arrow.png';
  6. import arrow_down_icon from './img/arrow-down.png';
  7. import del_icon from './img/delete.png';
  8. import del_hover_icon from './img/delete_blue.png';
  9. import edit_icon from './img/edit_grey.png';
  10. import editing_icon from './img/edit_blue.png';
  11. import check_circle from './img/check-circle.png';
  12. import check_right from './img/check-right.png';
  13. import store from '@store'
  14. import {checkItems} from '@store/actions/tabTemplate';
  15. import $ from 'jquery';
  16. class TemplateItem extends React.Component {
  17. constructor() {
  18. super();
  19. this.content = null;
  20. this.state = {
  21. isOpen: false,
  22. delHover: false,
  23. editHover: false,
  24. checkBox:false,
  25. bgColor:false,
  26. };
  27. this.titleDOM = null;
  28. this.isConfirmClick = false;
  29. this.timer = null;
  30. this.handleTitleClick = this.handleTitleClick.bind(this)
  31. }
  32. getArrow() {
  33. return this.state.isOpen ? arrow_down_icon : arrow_icon;
  34. }
  35. handleContentClick(e,sex) {
  36. e.stopPropagation();
  37. this.props.handleContentClick(this.props.id,sex);
  38. }
  39. handleCheckboxClick(e,id){ //点击复选框
  40. e.stopPropagation();
  41. let tempCheck = this.state.checkBox;
  42. this.setState({
  43. checkBox:!tempCheck
  44. })
  45. store.dispatch(checkItems(id))
  46. }
  47. getCheckIcon() {
  48. let tempCheckItems = this.props.checkItems;
  49. if(tempCheckItems.indexOf(this.props.id) != -1){
  50. return [check_right,'title-wrapper-bg']
  51. }else{
  52. return [check_circle,'']
  53. }
  54. }
  55. getBgcColor() {
  56. let tempCheckItems = this.props.checkItems;
  57. if(tempCheckItems.indexOf(this.props.id) != -1){
  58. return 'title-wrapper-bg'
  59. }else{
  60. return ''
  61. }
  62. }
  63. getDelIcon() {
  64. return this.state.delHover ? del_hover_icon : del_icon;
  65. }
  66. handleDelIconMouseEnter() {
  67. this.setState({
  68. delHover: true
  69. });
  70. }
  71. handleDelIconMouseLeave() {
  72. this.setState({
  73. delHover: false
  74. });
  75. }
  76. handleTemplateDel(e) {
  77. e.stopPropagation();
  78. this.props.handleTemplateDel(this.props.id);
  79. }
  80. getEditIcon() {
  81. return this.state.editHover ? editing_icon : edit_icon;
  82. }
  83. handleEditIconMouseEnter() {
  84. this.setState({
  85. editHover: true
  86. });
  87. }
  88. handleEditIconMouseLeave() {
  89. this.setState({
  90. editHover: false
  91. });
  92. }
  93. handleEditIconClick(e,name) {
  94. e.stopPropagation();
  95. let currId = this.props.id
  96. this.props.handleTitleChange(currId,name);
  97. }
  98. recoverTitle() {
  99. this.titleDOM.innerHTML = this.props.title;
  100. }
  101. handleTitleClick(e) {
  102. $(e.target).next().slideToggle()
  103. let tmpDomLis = $(e.target).parent().siblings()
  104. for(let i = 0;i < tmpDomLis.length;i++){
  105. let tmpDiv = tmpDomLis[i]
  106. $(tmpDiv).children().eq(1).slideUp()
  107. }
  108. }
  109. render() {
  110. const { allCheckShow,id,name,preview,sex } = this.props;
  111. let previewJson = JSON.parse(preview);
  112. let sexStr = sex==2?' (女)':sex==1?' (男)':' (通用)';
  113. return (
  114. <div className={style.wrapper}>
  115. <div className={
  116. allCheckShow?
  117. `${style["title-wrapper"]} ${style["clearfix"]} ${style[this.getCheckIcon()[1]]}`:
  118. `${style["title-wrapper"]} ${style["clearfix"]}`}
  119. onClick={this.handleTitleClick}
  120. >
  121. {
  122. allCheckShow?<div className={style['check-wrap']} onClick={(e)=>{this.handleCheckboxClick(e,id)}}>
  123. <img className={`${style['fl-element']} ${style['check-box']}`}
  124. src={this.getCheckIcon()[0]}
  125. /></div>:null
  126. }
  127. <span
  128. ref={(title) => this.titleDOM = title}
  129. className={style['title']}
  130. title={name+sexStr}
  131. >
  132. {name+sexStr}
  133. </span>
  134. <img className={style.arrow} src={this.getArrow()} />
  135. <img title={'删除模板'}
  136. className={style.del}
  137. style={{display:allCheckShow?'none':'block'}}
  138. src={this.getDelIcon()}
  139. onMouseEnter={() => this.handleDelIconMouseEnter()}
  140. onMouseLeave={() => this.handleDelIconMouseLeave()}
  141. onClick={(e) => this.handleTemplateDel(e)}
  142. />
  143. <span className={style.quote} onClick={(e) => this.handleContentClick(e,sex)}>引用</span>
  144. <img title={'修改模板标题'}
  145. className={style.edit}
  146. src={this.getEditIcon()}
  147. onMouseEnter={() => this.handleEditIconMouseEnter()}
  148. onMouseLeave={() => this.handleEditIconMouseLeave()}
  149. onClick={(e) => this.handleEditIconClick(e,name)}
  150. />
  151. </div>
  152. <div
  153. ref={(content) => this.content = content}
  154. className={style.content}
  155. title={this.title}
  156. >
  157. {
  158. previewJson?<DesItem preview={previewJson}></DesItem>:<p>暂无数据</p>
  159. }
  160. </div>
  161. </div>
  162. )
  163. }
  164. componentWillUnmount() {
  165. clearTimeout(this.timer);
  166. }
  167. }
  168. export default TemplateItem;
  169. TemplateItem.propTypes = {
  170. id: PropTypes.string,
  171. title: PropTypes.string,
  172. content: PropTypes.arrayOf(PropTypes.string),
  173. handleContentClick: PropTypes.func,
  174. handleTemplateDel: PropTypes.func,
  175. handleTitleChange: PropTypes.func
  176. };