index.jsx 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. import React from 'react';
  2. import { SearchOption, InspectCommon, Calendar ,Notify,ConfirmModal,Add} from '@commonComp';
  3. import { deepClone } from '@utils/tools';
  4. import styles from './index.less';
  5. import date1 from './img/date1.png';
  6. import date2 from './img/date2.png';
  7. import close from './img/close.png';
  8. import store from '@store';
  9. import $ from 'jquery';
  10. class Inspect extends React.Component {
  11. constructor(props) {
  12. super(props);
  13. this.state = {
  14. show: false,
  15. showFill: false,
  16. date: false,
  17. currentIdx: '',
  18. dateTime:"",
  19. currentData:{},
  20. numPlus:0, //判断是否所有的填写单都是空
  21. num:0, //暂存数据,获取一次,不能每次都是新的数据
  22. toastText:'',
  23. visible:false,
  24. type:null,
  25. id:null
  26. }
  27. this.handleChangeDate = this.handleChangeDate.bind(this)
  28. this.handleShowDate = this.handleShowDate.bind(this)
  29. this.getCurrentDate = this.getCurrentDate.bind(this)
  30. this.getItemList = this.getItemList.bind(this)
  31. this.getSearchList = this.getSearchList.bind(this)
  32. this.changeActivePart = this.changeActivePart.bind(this)
  33. this.normalVal = this.normalVal.bind(this)
  34. this.showDetails = this.showDetails.bind(this)
  35. this.delConfirm = this.delConfirm.bind(this)
  36. this.handleCancel = this.handleCancel.bind(this)
  37. this.handleSearchShow = this.handleSearchShow.bind(this)
  38. }
  39. delConfirm(){//弹窗确定
  40. const{delPartItem,handleCloseExcel,handlePush} = this.props;
  41. const{type,id} = this.state;
  42. if(type==1){
  43. delPartItem(id)
  44. }else if(type==2){
  45. handleCloseExcel(id)
  46. }
  47. this.setState({
  48. visible:false,
  49. type:null,
  50. id:null,
  51. })
  52. Notify.success("删除成功");
  53. handlePush&&handlePush(); //右侧推送
  54. }
  55. handleDelClick(type,idx){
  56. this.setState({
  57. type:type,
  58. id:idx,
  59. visible:true
  60. })
  61. if(type==1){//单项
  62. this.setState({
  63. toastText:'是否删除该化验项?'
  64. })
  65. }else if(type==2){//导入项
  66. this.setState({
  67. toastText:'是否删除导入项?'
  68. })
  69. }
  70. }
  71. handleCancel(){
  72. this.setState({
  73. visible:false,
  74. type:null,
  75. id:null,
  76. })
  77. }
  78. componentDidMount() {
  79. $(document).click((event) => {
  80. let searchWrap = $('#searchWrap')[0]; // 搜索按钮
  81. let searchOption = $('#searchOption')[0]; // 搜索列表
  82. let inspectFill = $('#inspectFill')[0]; // 公共填写单
  83. if(searchOption){
  84. if ( searchOption != event.target && searchWrap != event.target && searchWrap != event.target.parentNode && !$.contains(searchOption, event.target)) { // Mark 1
  85. this.setState({ show: false });
  86. }
  87. }
  88. if(inspectFill){
  89. if ( event.target.getAttribute('data-flg') != 'current' && inspectFill != event.target && !$.contains(inspectFill, event.target)) { // Mark 1
  90. this.setState({ showFill: false });
  91. }
  92. }
  93. });
  94. this.getCurrentDate();
  95. }
  96. componentWillReceiveProps(nextProps){
  97. if(nextProps.fillActive.name != this.props.fillActive.name){
  98. this.setState({num:0})
  99. }
  100. }
  101. handleChangeDate(info) {
  102. let date = info.year+'-'+(info.month<10?'0'+info.month:info.month)+'-'+(info.day<10?'0'+info.day:info.day);
  103. this.setState({dateTime:date,date:false})
  104. }
  105. handleSearchShow(e) {
  106. let tmpShow = this.state.show;
  107. this.setState({ show: !tmpShow })
  108. // e.stopPropagation();
  109. }
  110. handleFillShow(e,idx) {
  111. let tmpShow = this.state.showFill;
  112. let baseList = store.getState().inspect.fillActive;
  113. this.setState({
  114. showFill: !tmpShow,
  115. currentIdx:idx,
  116. currentData:baseList,
  117. dateTime:baseList.time?baseList.time:this.getCurrentDate()
  118. })
  119. e.stopPropagation();
  120. }
  121. handleShowDate(){
  122. this.setState({
  123. date:!this.state.date
  124. })
  125. }
  126. getCurrentDate(){
  127. let myDate = new Date();
  128. let year = myDate.getFullYear(); //获取完整的年份(4位,1970-????)
  129. let mon = myDate.getMonth()-0+1; //获取当前月份(0-11,0代表1月)
  130. let day = myDate.getDate(); //获取当前日(1-31)
  131. let date = year+'-'+(mon<10?'0'+mon:mon)+'-'+(day<10?'0'+day:day);
  132. this.setState({dateTime:date})
  133. return date;
  134. }
  135. changeActivePart(idx,val){
  136. let nums = this.state.num;
  137. let fillActive;
  138. if(nums == 0){
  139. fillActive = this.props.fillActive;
  140. }else{
  141. fillActive = this.state.currentData;
  142. }
  143. ++nums;
  144. this.setState({num:nums});
  145. let tempArr = deepClone(fillActive);
  146. let tempNumPlus = 0;
  147. for (let i = 0; i < tempArr.details.length; i++) {
  148. if (i == idx) {
  149. tempArr.details[i].value = val
  150. }
  151. if(tempArr.details[i].value != undefined && tempArr.details[i].value != ''){
  152. tempArr.show = true;
  153. }else{
  154. ++tempNumPlus;
  155. if(tempNumPlus == tempArr.details.length){
  156. tempArr.show = false;
  157. }
  158. }
  159. }
  160. tempArr.time = this.state.dateTime;
  161. this.setState({currentData:tempArr})
  162. }
  163. getItemList(){ //填写单展示
  164. let number = this.state.num;
  165. let fillActive;
  166. if(number == 0){
  167. fillActive = this.props.fillActive;
  168. }else{
  169. fillActive = this.state.currentData;
  170. }
  171. return <ul className={styles.searchLis}>
  172. {
  173. fillActive && fillActive.details && fillActive.details.map((item,idx) => {
  174. if(item.controlType == 1){
  175. return (
  176. <li className={`${styles.itemPart} ${fillActive.details.length>1?'':styles.itemPartOne}`}>
  177. <span className={styles.itemPartL}>{item.name}</span>
  178. <select className={styles.itemPartR} onChange={(e)=>{
  179. if(e.target.value == '请选择') {
  180. this.changeActivePart(idx,'')
  181. return;
  182. }
  183. this.changeActivePart(idx,e.target.value);
  184. }}
  185. >
  186. <option value="请选择">请选择</option>
  187. {
  188. (item.questionDetailList).map((val)=>{
  189. return <option value={val.name}
  190. selected={val.name == item.value?true:false}
  191. >{val.name}</option>
  192. })
  193. }
  194. </select>
  195. </li>
  196. )
  197. }else if(item.controlType == 6){
  198. return (
  199. <li className={`${styles.itemPart} ${fillActive.details.length>1?'':styles.itemPartOne}`}>
  200. <span className={styles.itemPartL}>{item.name}</span>
  201. <span className={styles.itemPartT}>
  202. <input type="text"
  203. placeholder="(填写)"
  204. value={item.value}
  205. onKeyUp={(e)=>{this.changeActivePart(idx,e.target.value.trim())}}
  206. />
  207. <p className={styles.unit}>{item.labelSuffix}</p>
  208. </span>
  209. </li>
  210. )
  211. }
  212. })
  213. }
  214. </ul>
  215. }
  216. getSearchList(list){ //搜索列表
  217. const {handleSign} = this.props;
  218. return <ul>
  219. {
  220. list && list.map((item,idx) => {
  221. return <li key={idx}
  222. className={styles.searchLi}
  223. title={item.name}
  224. onClick={() => {
  225. handleSign(item.questionId,idx);
  226. this.setState({ show: false })
  227. }}
  228. >
  229. {item.name}{item.name == item.retrievalName?null:'('+item.retrievalName+')'}
  230. </li>
  231. })
  232. }
  233. </ul>
  234. }
  235. normalVal(min,max){
  236. if((min-0) && (max-0)){
  237. return `正常值: (${min}~${max})`
  238. }else if((min-0) && !(max-0)){
  239. return `正常值: (>=${min})`
  240. }else if(!(min-0) && (max-0)){
  241. if(min == '' || min == null){
  242. return `正常值: (<=${max})`
  243. }else{
  244. return `正常值: (${min}~${max})`
  245. }
  246. }else{
  247. return null;
  248. }
  249. }
  250. showDetails(val){
  251. if(val.questionDetailList.length > 0){
  252. return val.questionDetailList.map((item)=>{
  253. if(val.value == item.name){
  254. return <td className={item.abnormal != '0' ?"red":'' }>{val.value}</td>
  255. }
  256. })
  257. }else{
  258. return <td><span className={val.value > val.maxValue || val.value < val.minValue?"red":''}>{val.value}</span> { val.labelSuffix}</td>
  259. }
  260. }
  261. render() {
  262. const { handleChangeValue, list, labelList,delPartItem, handleLabelSub, handleClear, handleConfirm, fillActive,getExcelDataList,handleCloseExcel,handlePush } = this.props;
  263. const {toastText,visible} = this.state;
  264. return (
  265. <div className={styles.wrapper}>
  266. <div className={styles.check}>
  267. {
  268. getExcelDataList.length > 0 && getExcelDataList.map((items,id)=>{
  269. return <div style={{marginTop:'10px'}}>
  270. {
  271. items && items.lisExcelRes.length > 0 ? <ul className={styles.excelDataLists}>
  272. <img className={styles.close} src={close} alt="关闭导入excel数据" onClick={()=>{this.handleDelClick(2,id)}}/>
  273. {
  274. items.lisExcelRes.map((item,idx)=>{
  275. return <li className={styles.excelDataLis} style={{border:items.lisExcelRes.length-1 == idx? 0:''}}>
  276. <span className={styles.excelDataTitle}>
  277. {item.menus}
  278. </span>
  279. <table>
  280. {
  281. item.lisExcelItem && item.lisExcelItem.map((value)=>{
  282. return <tr>
  283. <td>{value.itemName}</td>
  284. <td><span className={value.type == 1?'red':null}>{value.value}</span> {value.unit}</td>
  285. <td>
  286. {this.normalVal(value.min,value.max)}
  287. </td>
  288. <td>{value.time == ''?('导入时间: '+this.state.dateTime):'化验时间: '+value.time}</td>
  289. </tr>
  290. })
  291. }
  292. </table>
  293. </li>
  294. })
  295. }
  296. </ul>:null
  297. }
  298. </div>
  299. })
  300. }
  301. <ul className={styles.labelWrap} >
  302. {
  303. labelList && labelList.map((item,idx) => {
  304. return <li key={item.questionId}>
  305. {
  306. // 标签,血常规。。
  307. item.show ?
  308. <p className={styles.staticTagActive}>
  309. <span data-flg="current" style={{color:"#333"}} onClick={(e) => { handleLabelSub(e, item.questionId,idx); this.handleFillShow(e,idx) }}>{item.name}</span>
  310. </p>:
  311. <p>
  312. <i data-flg="current" onClick={(e) => { handleLabelSub(e,item.questionId,idx); this.handleFillShow(e,idx) }}>{item.name}</i>
  313. </p>
  314. }
  315. {
  316. item.show ?
  317. <table className={styles.table}>
  318. {
  319. item.details.map((val)=>{
  320. if(val.value && val.value != ''){
  321. return <tr>
  322. <td>{val.name}</td>
  323. {this.showDetails(val)}
  324. <td>
  325. {this.normalVal(val.minValue,val.maxValue)}
  326. </td>
  327. <td>{'化验时间:'+item.time}</td>
  328. </tr>
  329. }
  330. })
  331. }
  332. </table>:null
  333. }
  334. <div className={styles.searchResult}>
  335. {
  336. this.state.showFill && fillActive.id == item.id && idx == this.state.currentIdx ?
  337. <InspectCommon
  338. showFill={this.state.showFill}
  339. handleClear={(e)=>{
  340. handleClear(e,idx)
  341. this.setState({
  342. showFill:false
  343. })
  344. }}
  345. handleConfirm={(e)=>{
  346. // handleConfirm(e,idx,this.state.dateTime,fillActive);
  347. if(JSON.stringify(this.state.currentData) == '{}'){
  348. handleConfirm(e,idx,this.state.dateTime,fillActive);
  349. }else{
  350. handleConfirm(e,idx,this.state.dateTime,this.state.currentData);
  351. }
  352. this.setState({showFill:false})
  353. handlePush&&handlePush(); //右侧推送
  354. }}
  355. >
  356. <div className={styles.searchResultT}>
  357. <img style={{"position":"absolute","top":"8px","right":"8px"}} src={date1} alt="" onClick={this.handleShowDate}/>
  358. <p style={{position:"absolute",right:"38px",top:"4px",lineHeight:"28px"}}>
  359. {
  360. this.state.dateTime
  361. }
  362. </p>
  363. <div style={{display:this.state.date?"block":"none",position:"relative"}}>
  364. {/* 日期组件 */}
  365. <Calendar isShow={true} handleChange={this.handleChangeDate}></Calendar>
  366. </div>
  367. </div>
  368. {/* 填写单内容显示 */}
  369. { this.getItemList(idx) }
  370. </InspectCommon>
  371. : null
  372. }
  373. </div>
  374. <img className={styles.partDel} src={close} alt="删除项" onClick={()=>{this.handleDelClick(1,idx)}}/>
  375. </li>
  376. })
  377. }
  378. </ul>
  379. </div>
  380. <div style={{position:"relative"}}>
  381. <Add showText="添加化验项" handleClick={(e) => this.handleSearchShow(e)} id="searchWrap"/>
  382. {this.state.show?<SearchOption handleChangeValue={handleChangeValue} visible={true}>
  383. {this.getSearchList(list)}
  384. </SearchOption>:''}
  385. </div>
  386. <ConfirmModal
  387. visible={visible}
  388. confirm={()=>{this.delConfirm()}}
  389. close={this.handleCancel}
  390. cancel={this.handleCancel}
  391. okText="删除"
  392. cancelText='取消'
  393. okBorderColor={'#3B9ED0'}
  394. okColor={'#fff'}
  395. oKBg={'#3B9ED0'}
  396. >
  397. <p className={styles['center']}>{toastText}</p>
  398. </ConfirmModal>
  399. </div>
  400. )
  401. }
  402. }
  403. export default Inspect;