index.jsx 19 KB

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