index.jsx 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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,checkItemsAdmin } 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. delHover: false,
  22. editHover: false,
  23. checkBox: false,
  24. bgColor: false,
  25. };
  26. this.isConfirmClick = false;
  27. this.handleTitleClick = this.handleTitleClick.bind(this)
  28. this.getStyleFst = this.getStyleFst.bind(this)
  29. this.getStyleSec = this.getStyleSec.bind(this)
  30. }
  31. getArrow() {
  32. return this.state.isOpen ? arrow_down_icon : arrow_icon;
  33. }
  34. handleContentClick(e, sex) {
  35. e.stopPropagation();
  36. this.props.handleContentClick(this.props.id, sex);
  37. }
  38. handleCheckboxClick(e, id) { //点击复选框
  39. e.stopPropagation();
  40. let tempCheck = this.state.checkBox;
  41. let sign = this.props.admin;
  42. // this.setState({
  43. // checkBox: !tempCheck
  44. // })
  45. if(sign){
  46. store.dispatch(checkItemsAdmin(id))
  47. }else{
  48. store.dispatch(checkItems(id))
  49. }
  50. }
  51. getCheckIcon() {
  52. const {checkItemsAdmin,checkItems,admin,adminflg,id} = this.props
  53. if(admin||adminflg){
  54. if (checkItemsAdmin.indexOf(id) != -1) {
  55. return [check_right, 'title-wrapper-bg']
  56. } else {
  57. return [check_circle, '']
  58. }
  59. }
  60. if (checkItems.indexOf(id) != -1) {
  61. return [check_right, 'title-wrapper-bg']
  62. } else {
  63. return [check_circle, '']
  64. }
  65. }
  66. getBgcColor() {
  67. let tempCheckItems = this.props.checkItems;
  68. if (tempCheckItems.indexOf(this.props.id) != -1) {
  69. return 'title-wrapper-bg'
  70. } else {
  71. return ''
  72. }
  73. }
  74. getDelIcon() {
  75. return this.state.delHover ? del_hover_icon : del_icon;
  76. }
  77. handleDelIconMouseEnter() {
  78. this.setState({
  79. delHover: true
  80. });
  81. }
  82. handleDelIconMouseLeave() {
  83. this.setState({
  84. delHover: false
  85. });
  86. }
  87. handleTemplateDel(e) {
  88. e.stopPropagation();
  89. this.props.handleTemplateDel(this.props.id);
  90. }
  91. getEditIcon() {
  92. return this.state.editHover ? editing_icon : edit_icon;
  93. }
  94. handleEditIconMouseEnter() {
  95. this.setState({
  96. editHover: true
  97. });
  98. }
  99. handleEditIconMouseLeave() {
  100. this.setState({
  101. editHover: false
  102. });
  103. }
  104. handleEditIconClick(e, name,deptId) {
  105. e.stopPropagation();
  106. let currId = this.props.id
  107. this.props.handleTitleChange(currId, name,deptId);
  108. }
  109. handleTitleClick(e) {
  110. if (e.target.tagName == 'I') {
  111. let tmpDomLis = $(e.target).parent().parent().siblings()
  112. $(e.target).parent().next().slideToggle()
  113. if ($(e.target).parent().next().height() == 0) {
  114. $(e.target).next().attr('src', arrow_down_icon)
  115. } else {
  116. $(e.target).next().attr('src', arrow_icon)
  117. }
  118. for (let i = 0; i < tmpDomLis.length; i++) {
  119. let tmpDiv = tmpDomLis[i]
  120. $(tmpDiv).children().eq(1).slideUp()
  121. $(tmpDiv).children().eq(0).children('img').eq(0).attr('src', arrow_icon)
  122. }
  123. } else if ($(e.target).attr('src')) {
  124. let tmpDomLis = $(e.target).parent().parent().siblings()
  125. $(e.target).parent().next().slideToggle()
  126. if ($(e.target).parent().next().height() == 0) {
  127. $(e.target).attr('src', arrow_down_icon)
  128. } else {
  129. $(e.target).attr('src', arrow_icon)
  130. }
  131. for (let i = 0; i < tmpDomLis.length; i++) {
  132. let tmpDiv = tmpDomLis[i]
  133. $(tmpDiv).children().eq(1).slideUp()
  134. $(tmpDiv).children().eq(0).children('img').eq(0).attr('src', arrow_icon)
  135. }
  136. } else {
  137. let tmpDomLis = $(e.target).parent().siblings()
  138. $(e.target).next().slideToggle()
  139. if ($(e.target).next().height() == 0) {
  140. $(e.target).children('img').eq(0).attr('src', arrow_down_icon)
  141. } else {
  142. $(e.target).children('img').eq(0).attr('src', arrow_icon)
  143. }
  144. for (let i = 0; i < tmpDomLis.length; i++) {
  145. let tmpDiv = tmpDomLis[i]
  146. $(tmpDiv).children().eq(1).slideUp()
  147. $(tmpDiv).children().eq(0).children('img').eq(0).attr('src', arrow_icon)
  148. }
  149. }
  150. }
  151. getStyleFst() {
  152. const { allCheckShow, id, name, preview, sex,admin,checkItemsAdmin,allCheckShowAdmin,adminflg } = this.props;
  153. if(admin) {
  154. if(allCheckShowAdmin){
  155. return `${style["title-wrapper"]} ${style["clearfix"]} ${style[this.getCheckIcon()[1]]}`
  156. }
  157. return `${style["title-wrapper"]} ${style["clearfix"]}`
  158. }else{
  159. if(adminflg){
  160. if(allCheckShowAdmin){
  161. return `${style["title-wrapper"]} ${style["clearfix"]} ${style[this.getCheckIcon()[1]]}`
  162. }
  163. return `${style["title-wrapper"]} ${style["clearfix"]}`
  164. }
  165. if(allCheckShow){
  166. return `${style["title-wrapper"]} ${style["clearfix"]} ${style[this.getCheckIcon()[1]]}`
  167. }
  168. return `${style["title-wrapper"]} ${style["clearfix"]}`
  169. }
  170. }
  171. getStyleSec(){
  172. const { allCheckShow, id, name, preview, sex,admin,checkItemsAdmin,allCheckShowAdmin,adminflg } = this.props;
  173. if(admin) {
  174. if(allCheckShowAdmin){
  175. return <div className={style['check-wrap']} onClick={(e) => { this.handleCheckboxClick(e, id) }}>
  176. <img className={`${style['fl-element']} ${style['check-box']}`}
  177. src={this.getCheckIcon()[0]}
  178. /></div>
  179. }
  180. return null
  181. }else{
  182. if(adminflg){
  183. if(allCheckShowAdmin){
  184. return <div className={style['check-wrap']} onClick={(e) => { this.handleCheckboxClick(e, id) }}>
  185. <img className={`${style['fl-element']} ${style['check-box']}`}
  186. src={this.getCheckIcon()[0]}
  187. /></div>
  188. }
  189. return null
  190. }
  191. if(allCheckShow){
  192. return <div className={style['check-wrap']} onClick={(e) => { this.handleCheckboxClick(e, id) }}>
  193. <img className={`${style['fl-element']} ${style['check-box']}`}
  194. src={this.getCheckIcon()[0]}
  195. /></div>
  196. }
  197. return null
  198. }
  199. }
  200. render() {
  201. const { allCheckShow, id, name,hospitalDeptId, preview,conceptDeptName, sex,admin,checkItemsAdmin,allCheckShowAdmin,adminflg } = this.props;
  202. let previewJson = JSON.parse(preview);
  203. let sexStr = sex == 2 ? ' (女'+(conceptDeptName&&'-'+conceptDeptName)+')' : sex == 1 ? ' (男'+(conceptDeptName&&'-'+conceptDeptName)+')' : ' (通用'+(conceptDeptName&&'-'+conceptDeptName)+')';
  204. return (
  205. <div className={style.wrapper}>
  206. <div className={this.getStyleFst()}
  207. onClick={this.handleTitleClick}
  208. >
  209. {
  210. this.getStyleSec()
  211. }
  212. <i
  213. className={style['title']}
  214. title={name + sexStr}
  215. >
  216. {name + sexStr}
  217. </i>
  218. <img className={style.arrow} src={arrow_icon} />
  219. {!admin&&adminflg?null:<img title={'删除模板'}
  220. className={style.del}
  221. style={{ display: allCheckShow ? 'none' : 'block' }}
  222. src={this.getDelIcon()}
  223. onMouseEnter={() => this.handleDelIconMouseEnter()}
  224. onMouseLeave={() => this.handleDelIconMouseLeave()}
  225. onClick={(e) => this.handleTemplateDel(e)}
  226. />}
  227. <span className={style.quote} onClick={(e) => this.handleContentClick(e, sex)}>引用</span>
  228. {!admin&&adminflg?null:<img title={'修改模板标题'}
  229. className={style.edit}
  230. src={this.getEditIcon()}
  231. onMouseEnter={() => this.handleEditIconMouseEnter()}
  232. onMouseLeave={() => this.handleEditIconMouseLeave()}
  233. onClick={(e) => this.handleEditIconClick(e, name,hospitalDeptId)}
  234. />}
  235. </div>
  236. <div
  237. ref={(content) => this.content = content}
  238. className={style.content}
  239. title={this.title}
  240. >
  241. {
  242. previewJson ? <DesItem preview={previewJson}></DesItem> : <p>暂无数据</p>
  243. }
  244. </div>
  245. </div>
  246. )
  247. }
  248. }
  249. export default TemplateItem;
  250. TemplateItem.propTypes = {
  251. id: PropTypes.string,
  252. title: PropTypes.string,
  253. content: PropTypes.arrayOf(PropTypes.string),
  254. handleContentClick: PropTypes.func,
  255. handleTemplateDel: PropTypes.func,
  256. handleTitleChange: PropTypes.func
  257. };