index.jsx 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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 Notify from '@commonComp/Notify';
  14. import store from '@store'
  15. import {checkItems} from '@store/actions/tabTemplate';
  16. import $ from 'jquery';
  17. class TemplateItem extends React.Component {
  18. constructor() {
  19. super();
  20. this.content = null;
  21. this.isAnimate = false;
  22. this.state = {
  23. isOpen: false,
  24. delHover: false,
  25. editHover: false,
  26. checkBox:false,
  27. bgColor:false
  28. };
  29. this.titleDOM = null;
  30. this.isConfirmClick = false;
  31. this.timer = null;
  32. }
  33. genContent() {
  34. const {preview} = this.props;
  35. this.title = '';
  36. let DesItems = [];
  37. for(var a in previewJson){
  38. DesItems.push(<DesItem preview={preview} des={a} />);
  39. }
  40. // if(previewJson){
  41. // console.log(previewJson,1000)
  42. // previewJson.forEach((v, i) => {
  43. // DesItems.push(<DesItem des={v} key={i} />);
  44. // this.title += `${v}\n`;
  45. // });
  46. // }
  47. return DesItems;
  48. }
  49. getArrow() {
  50. return this.state.isOpen ? arrow_down_icon : arrow_icon;
  51. }
  52. getContentStyle() {
  53. return {
  54. display: this.state.isOpen ? 'block' : 'none'
  55. }
  56. }
  57. handleContentClick(e,sex) {
  58. e.stopPropagation();
  59. let baseSex = store.getState().patInfo.message.sex
  60. if(sex != 3 && sex != baseSex){
  61. Notify.info('引用该模版可能显示有误');
  62. }
  63. this.props.handleContentClick(this.props.id);
  64. }
  65. handleTitleClick() {
  66. if (this.isAnimate) {
  67. return;
  68. }
  69. this.isAnimate = true;
  70. if (this.state.isOpen) {
  71. $(this.content).slideUp(() => {
  72. this.isAnimate = false;
  73. this.setState({
  74. isOpen: false
  75. });
  76. });
  77. // console.log($(this.content).parent().siblings().find('.content'))
  78. return;
  79. }
  80. $(this.content).slideDown(() => {
  81. this.isAnimate = false;
  82. this.setState({
  83. isOpen: true
  84. });
  85. });
  86. }
  87. handleCheckboxClick(e,id){ //点击复选框
  88. e.stopPropagation();
  89. let tempCheck = this.state.checkBox;
  90. this.setState({
  91. checkBox:!tempCheck
  92. })
  93. store.dispatch(checkItems(id))
  94. }
  95. getCheckIcon() {
  96. let tempCheckItems = this.props.checkItems;
  97. if(tempCheckItems.indexOf(this.props.id) != -1){
  98. return [check_right,'title-wrapper-bg']
  99. }else{
  100. return [check_circle,'']
  101. }
  102. }
  103. getBgcColor() {
  104. let tempCheckItems = this.props.checkItems;
  105. if(tempCheckItems.indexOf(this.props.id) != -1){
  106. return 'title-wrapper-bg'
  107. }else{
  108. return ''
  109. }
  110. }
  111. getDelIcon() {
  112. return this.state.delHover ? del_hover_icon : del_icon;
  113. }
  114. handleDelIconMouseEnter() {
  115. this.setState({
  116. delHover: true
  117. });
  118. }
  119. handleDelIconMouseLeave() {
  120. this.setState({
  121. delHover: false
  122. });
  123. }
  124. handleTemplateDel(e) {
  125. e.stopPropagation();
  126. this.props.handleTemplateDel(this.props.id);
  127. }
  128. getEditIcon() {
  129. return this.state.editHover ? editing_icon : edit_icon;
  130. }
  131. handleEditIconMouseEnter() {
  132. this.setState({
  133. editHover: true
  134. });
  135. }
  136. handleEditIconMouseLeave() {
  137. this.setState({
  138. editHover: false
  139. });
  140. }
  141. handleEditIconClick(e,name) {
  142. e.stopPropagation();
  143. let currId = this.props.id
  144. this.props.handleTitleChange(currId,name);
  145. }
  146. recoverTitle() {
  147. this.titleDOM.innerHTML = this.props.title;
  148. }
  149. render() {
  150. const { allCheckShow,id,name,preview,sex } = this.props;
  151. let previewJson = JSON.parse(preview);
  152. let sexStr = sex==2?' (女)':sex==1?' (男)':' (通用)';
  153. return (
  154. <div className={style.wrapper}>
  155. <div className={
  156. allCheckShow?
  157. `${style["title-wrapper"]} ${style["clearfix"]} ${style[this.getCheckIcon()[1]]}`:
  158. `${style["title-wrapper"]} ${style["clearfix"]}`}
  159. onClick={() => this.handleTitleClick()}
  160. >
  161. {
  162. allCheckShow?<div className={style['check-wrap']} onClick={(e)=>{this.handleCheckboxClick(e,id)}}>
  163. <img className={`${style['fl-element']} ${style['check-box']}`}
  164. src={this.getCheckIcon()[0]}
  165. /></div>:null
  166. }
  167. <span
  168. ref={(title) => this.titleDOM = title}
  169. className={style['title']}
  170. title={name+sexStr}
  171. >
  172. {name+sexStr}
  173. </span>
  174. <img className={style.arrow} src={this.getArrow()} />
  175. <img title={'删除模板'}
  176. className={style.del}
  177. style={{display:allCheckShow?'none':'block'}}
  178. src={this.getDelIcon()}
  179. onMouseEnter={() => this.handleDelIconMouseEnter()}
  180. onMouseLeave={() => this.handleDelIconMouseLeave()}
  181. onClick={(e) => this.handleTemplateDel(e)}
  182. />
  183. <span className={style.quote} onClick={(e) => this.handleContentClick(e,sex)}>引用</span>
  184. <img title={'修改模板标题'}
  185. className={style.edit}
  186. src={this.getEditIcon()}
  187. onMouseEnter={() => this.handleEditIconMouseEnter()}
  188. onMouseLeave={() => this.handleEditIconMouseLeave()}
  189. onClick={(e) => this.handleEditIconClick(e,name)}
  190. />
  191. </div>
  192. <div
  193. ref={(content) => this.content = content}
  194. className={style.content}
  195. title={this.title}
  196. style={this.getContentStyle()}
  197. >
  198. {
  199. previewJson?<DesItem preview={previewJson}></DesItem>:<p>暂无数据</p>
  200. }
  201. </div>
  202. </div>
  203. )
  204. }
  205. componentDidUpdate() {
  206. this.isAnimate = false;
  207. }
  208. componentWillUnmount() {
  209. clearTimeout(this.timer);
  210. }
  211. }
  212. export default TemplateItem;
  213. TemplateItem.propTypes = {
  214. id: PropTypes.string,
  215. title: PropTypes.string,
  216. content: PropTypes.arrayOf(PropTypes.string),
  217. handleContentClick: PropTypes.func,
  218. handleTemplateDel: PropTypes.func,
  219. handleTitleChange: PropTypes.func
  220. };