index.jsx 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. import React, { Component } from 'react';
  2. import style from './index.less';
  3. import { Tab ,ConfirmModal,Notify } from '@commonComp';
  4. import { tabChange,allChecked,changeVisible,keepPushData,allCheckedShow} from '@store/actions/tabTemplate';
  5. import { initItemList,delItem,delBatchItem,changeTitleAsync,saveTemplateDetail } from '@store/async-actions/tabTemplate';
  6. import { CHANGE_TYPE } from "@store/types/typeConfig";
  7. import { connect } from "react-redux";
  8. import store from '@store';
  9. import {billing} from '@store/async-actions/pushMessage';
  10. import TemplateContainer from '@components/TemplateContainer';
  11. import TemplateItems from '@components/TemplateItems';
  12. import PushItemsContainer from '@containers/PushItemsContainer';
  13. import { pushAllDataList,getWindowInnerHeight } from '@utils/tools';
  14. import CopyRightContainer from "@containers/CopyRightContainer";
  15. import MedicalInfoContainer from '@containers/MedicalInfoContainer'
  16. class PushContainer extends Component {
  17. constructor(props) {
  18. super(props);
  19. this.state = {
  20. data: null,
  21. tabs: [{
  22. title: '辅助信息',
  23. disabled: true
  24. }, {
  25. title: '模板',
  26. },
  27. // {
  28. // title: '医学知识',
  29. // }
  30. ],
  31. visible:false,
  32. message:'', //提示的内容
  33. type:'', //1:删除模板 2:批量删除 3.修改标题 4.引用
  34. id:'', //单个删除
  35. obj:{}, //修改模板标题
  36. title:'', //修改后的标题
  37. okText:'确定', //确认按钮
  38. okBorderColor:'red',
  39. oKBg:'',
  40. okColor:'red',
  41. num:0, //计数
  42. }
  43. this.$cont = React.createRef();
  44. this.itemList = null;
  45. this.handleActiveClick = this.handleActiveClick.bind(this)
  46. this.handleContentClick = this.handleContentClick.bind(this)
  47. this.handleTemplateDel = this.handleTemplateDel.bind(this)
  48. this.handleTitleChange = this.handleTitleChange.bind(this)
  49. this.handleAllCheckbox=this.handleAllCheckbox.bind(this)
  50. this.handleMangerTemplate=this.handleMangerTemplate.bind(this)
  51. this.handleDelList=this.handleDelList.bind(this)
  52. this.makeSure=this.makeSure.bind(this)
  53. this.handleClose = this.handleClose.bind(this);
  54. }
  55. componentDidMount(){
  56. // const height = getWindowInnerHeight()-160;
  57. // this.$cont.current.style.height = height+"px";
  58. }
  59. /**
  60. *
  61. * @param {tab组件切换id} id
  62. */
  63. handleActiveClick(id) {
  64. if(id == '1'){
  65. store.dispatch(initItemList());
  66. }
  67. store.dispatch(tabChange(id))
  68. }
  69. /**
  70. * 引用模板id
  71. * @param {模板id} id
  72. */
  73. handleContentClick(id,sex) {
  74. let baseSex = store.getState().patInfo.message.sex
  75. this.setState({
  76. message:this.content(sex,baseSex),
  77. type:4,
  78. id:id,
  79. okText:'引用',
  80. okBorderColor:'#3B9ED0',
  81. okColor:'#fff',
  82. oKBg:'#3B9ED0'
  83. },()=>{
  84. store.dispatch(changeVisible(true))
  85. })
  86. }
  87. content(sex,baseSex){
  88. if(sex != 3 && sex != baseSex){
  89. return <p className={style['center']}>确认引用该模板?<p style={{fontSize:'12px',color:'#6b6969',marginTop:'10px'}}>引用该模版可能显示有误</p></p>
  90. }else{
  91. return <p className={style['center']}>确认引用该模板?</p>
  92. }
  93. }
  94. /**
  95. * 删除模板
  96. * @param {模板id} id
  97. */
  98. handleTemplateDel(id) {
  99. this.setState({
  100. message:this.delDiv(),
  101. type:1,
  102. id:id,
  103. okText:'删除',
  104. okBorderColor:'red',
  105. okColor:'red',
  106. oKBg:'#fff'
  107. },()=>{
  108. store.dispatch(changeVisible(true))
  109. })
  110. }
  111. delDiv(){
  112. return <p className={style['center']}>确认删除模板?</p>
  113. }
  114. onchange(value){
  115. this.setState({
  116. title: value
  117. },()=>{
  118. this.setState({
  119. message:this.changeTitle(),
  120. })
  121. })
  122. }
  123. keypress(event){
  124. let e = event?event:window.event;
  125. if(e.keyCode == 13) {
  126. this.makeSure()
  127. }
  128. }
  129. handleInput(e){
  130. let val = e.target.value
  131. if(e.target.value.length > 30){
  132. e.target.value = val.substring(0,30)
  133. this.onchange(val.substring(0,30))
  134. }else{
  135. this.onchange(e.target.value)
  136. }
  137. }
  138. changeTitle(){
  139. return <div className={style['box']}>
  140. <input className={style['ipt']}
  141. placeholder="请输入模板名称"
  142. type="text"
  143. value={this.state.title}
  144. maxLength='30'
  145. onInput={(e) => {
  146. this.handleInput(e)
  147. }}
  148. onPropertyChange={(e) => { // 兼容ie
  149. this.handleInput(e)
  150. }}
  151. onKeyPress={e=>this.keypress(e)}
  152. />
  153. <div className={style['line']}></div>
  154. </div>
  155. }
  156. /**
  157. * 改变模板标题
  158. * @param {模板id和模板title} obj
  159. */
  160. handleTitleChange(id,text) {
  161. store.dispatch(changeVisible(true))
  162. this.setState({
  163. type:3,
  164. currId:id,
  165. title:text,
  166. text:text,
  167. okText:'保存',
  168. okBorderColor:'#3B9ED0',
  169. okColor:'#fff',
  170. oKBg:'#3B9ED0'
  171. },()=>{
  172. this.setState({
  173. message:this.changeTitle(),
  174. })
  175. })
  176. }
  177. handleAllCheckbox(){ //全.反选
  178. let tmpFlg = this.props.allChecked;
  179. if(this.props.checkItems.length < this.props.items.length && this.props.allChecked){
  180. tmpFlg = false;
  181. }else if(this.props.checkItems.length == this.props.items.length && !this.props.allChecked){
  182. tmpFlg = true;
  183. } //两种特殊情况处理
  184. store.dispatch(allChecked(!tmpFlg))
  185. }
  186. handleMangerTemplate(){ //管理
  187. let tmpFlg = this.props.allCheckShow;
  188. store.dispatch(allChecked(false))
  189. store.dispatch(allCheckedShow(!tmpFlg))
  190. }
  191. handleDelList(){ //批量删除
  192. this.setState({
  193. type:2,
  194. message:this.delDiv(),
  195. okText:'删除',
  196. okBorderColor:'red',
  197. okColor:'red',
  198. oKBg:'#fff'
  199. })
  200. store.dispatch(changeVisible(true))
  201. }
  202. makeSure(){
  203. if(this.state.type == 1) {
  204. store.dispatch(delItem(this.state.id))
  205. store.dispatch(changeVisible(false))
  206. }else if(this.state.type == 2){
  207. store.dispatch(delBatchItem(this.props.checkItems))
  208. store.dispatch(changeVisible(false))
  209. }else if(this.state.type == 3){
  210. if(this.state.title == this.state.text){
  211. store.dispatch(changeVisible(false))
  212. Notify.success('标题修改成功');
  213. return;
  214. }
  215. let tempObj = {
  216. id:this.state.currId,
  217. title:this.state.title
  218. }
  219. store.dispatch(changeTitleAsync(tempObj))
  220. }else if(this.state.type == 4){ //模板引入
  221. const {items} = this.props;
  222. items && items.map((part)=>{
  223. if(this.state.id == part.id){
  224. let typeConfig = part.type;
  225. store.dispatch(keepPushData(part,'part')) //引用数据的存储,用于保存模板是判断数据是否变化
  226. pushAllDataList(typeConfig,'push',part,'template') //引用
  227. store.dispatch(billing())
  228. }
  229. })
  230. store.dispatch(changeVisible(false))
  231. }
  232. }
  233. handleClose(){
  234. store.dispatch(changeVisible(false));
  235. }
  236. render() {
  237. const {activeId,checkItems,visible,showMsg,items,allCheckShow} = this.props;
  238. return <div className={style["container"]} ref={this.$cont} >
  239. <Tab tabs={this.state.tabs}
  240. activeId={activeId}
  241. handleActiveClick={this.handleActiveClick}
  242. >
  243. <TemplateContainer activeId={activeId}>
  244. <PushItemsContainer></PushItemsContainer>
  245. <TemplateItems
  246. items={items}
  247. checkItems={checkItems}
  248. allCheckShow={allCheckShow}
  249. handleContentClick={this.handleContentClick}
  250. handleTemplateDel={this.handleTemplateDel}
  251. handleTitleChange={this.handleTitleChange}
  252. handleDelList={this.handleDelList}
  253. handleMangerTemplate={this.handleMangerTemplate}
  254. handleAllCheckbox={this.handleAllCheckbox}
  255. ></TemplateItems>
  256. {/* <MedicalInfoContainer></MedicalInfoContainer> */}
  257. </TemplateContainer>
  258. </Tab>
  259. <ConfirmModal
  260. visible={visible}
  261. confirm={this.makeSure}
  262. close={this.handleClose}
  263. cancel={this.handleClose}
  264. okText={this.state.okText}
  265. okBorderColor={this.state.okBorderColor}
  266. okColor={this.state.okColor}
  267. oKBg={this.state.oKBg}
  268. >
  269. {this.state.message}
  270. </ConfirmModal>
  271. <CopyRightContainer />
  272. </div>
  273. }
  274. }
  275. const mapStateToProps = (state) => {
  276. return {
  277. items: state.tabTemplate.items,
  278. activeId:state.tabTemplate.activeId,
  279. checkItems:state.tabTemplate.checkItems,
  280. allChecked:state.tabTemplate.allChecked,
  281. visible:state.tabTemplate.visible,
  282. showMsg:state.tabTemplate.showMsg,
  283. allCheckShow:state.tabTemplate.allCheckShow,
  284. }
  285. }
  286. export default connect(mapStateToProps, null)(PushContainer);