index.jsx 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. import React from 'react';
  2. import { SearchOption, InspectCommon, Calendar ,Notify,ConfirmModal,Add} from '@commonComp';
  3. import { deepClone,normalVal } 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.showDetails = this.showDetails.bind(this)
  34. this.delConfirm = this.delConfirm.bind(this)
  35. this.handleCancel = this.handleCancel.bind(this)
  36. this.handleSearchShow = this.handleSearchShow.bind(this)
  37. }
  38. delConfirm(){//弹窗确定
  39. const{delPartItem,handleCloseExcel,handlePush} = this.props;
  40. const{type,id} = this.state;
  41. if(type==1){
  42. delPartItem(id)
  43. }else if(type==2){
  44. handleCloseExcel(id)
  45. }
  46. this.setState({
  47. visible:false,
  48. type:null,
  49. id:null,
  50. })
  51. Notify.success("删除成功");
  52. handlePush&&handlePush(); //右侧推送
  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 ,date: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. dateTime:baseList.time?baseList.time:this.getCurrentDate()
  117. })
  118. e.stopPropagation();
  119. }
  120. handleShowDate(){
  121. this.setState({
  122. date:!this.state.date
  123. })
  124. }
  125. getCurrentDate(){
  126. let myDate = new Date();
  127. let year = myDate.getFullYear(); //获取完整的年份(4位,1970-????)
  128. let mon = myDate.getMonth()-0+1; //获取当前月份(0-11,0代表1月)
  129. let day = myDate.getDate(); //获取当前日(1-31)
  130. let date = year+'-'+(mon<10?'0'+mon:mon)+'-'+(day<10?'0'+day:day);
  131. this.setState({dateTime:date})
  132. return date;
  133. }
  134. changeActivePart(idx,val){
  135. let nums = this.state.num;
  136. let fillActive;
  137. if(nums == 0){
  138. fillActive = this.props.fillActive;
  139. }else{
  140. fillActive = this.state.currentData;
  141. }
  142. ++nums;
  143. this.setState({num:nums});
  144. let tempArr = deepClone(fillActive);
  145. let tempNumPlus = 0;
  146. for (let i = 0; i < tempArr.details.length; i++) {
  147. if (i == idx) {
  148. tempArr.details[i].value = val
  149. }
  150. if(tempArr.details[i].value != undefined && tempArr.details[i].value != ''){
  151. tempArr.show = true;
  152. }else{
  153. ++tempNumPlus;
  154. if(tempNumPlus == tempArr.details.length){
  155. tempArr.show = false;
  156. }
  157. }
  158. }
  159. tempArr.time = this.state.dateTime;
  160. this.setState({currentData:tempArr})
  161. }
  162. getItemList(){ //填写单展示
  163. let number = this.state.num;
  164. let fillActive;
  165. if(number == 0){
  166. fillActive = this.props.fillActive;
  167. }else{
  168. fillActive = this.state.currentData;
  169. }
  170. return <ul className={styles.searchLis}>
  171. {
  172. fillActive && fillActive.details && fillActive.details.map((item,idx) => {
  173. if(item.controlType == 1){
  174. return (
  175. <li className={`${styles.itemPart} ${fillActive.details.length>1?'':styles.itemPartOne}`}>
  176. <span className={styles.itemPartL}>{item.name}</span>
  177. <select className={styles.itemPartR} onChange={(e)=>{
  178. if(e.target.value == '请选择') {
  179. this.changeActivePart(idx,'')
  180. return;
  181. }
  182. this.changeActivePart(idx,e.target.value);
  183. }}
  184. >
  185. <option value="请选择">请选择</option>
  186. {
  187. (item.questionDetailList).map((val)=>{
  188. return <option value={val.name}
  189. selected={val.name == item.value?true:false}
  190. >{val.name}</option>
  191. })
  192. }
  193. </select>
  194. </li>
  195. )
  196. }else if(item.controlType == 6){
  197. return (
  198. <li className={`${styles.itemPart} ${fillActive.details.length>1?'':styles.itemPartOne}`}>
  199. <span className={styles.itemPartL} title={item.name}>{item.name}</span>
  200. <span className={styles.itemPartT}>
  201. <input type="text"
  202. placeholder="(填写)"
  203. value={item.value}
  204. onKeyUp={(e)=>{this.changeActivePart(idx,e.target.value.trim())}}
  205. />
  206. <p className={styles.unit}>{item.labelSuffix}</p>
  207. </span>
  208. </li>
  209. )
  210. }
  211. })
  212. }
  213. </ul>
  214. }
  215. getSearchList(list){ //搜索列表
  216. const {handleSign} = this.props;
  217. return <ul>
  218. {
  219. list && list.map((item,idx) => {
  220. return <li key={idx}
  221. className={styles.searchLi}
  222. title={item.name}
  223. onClick={() => {
  224. handleSign(item.questionId,idx);
  225. this.setState({ show: false })
  226. }}
  227. >
  228. {item.name}{item.name == item.retrievalName?null:'('+item.retrievalName+')'}
  229. </li>
  230. })
  231. }
  232. </ul>
  233. }
  234. showDetails(val){
  235. if(val.questionDetailList.length > 0){
  236. return val.questionDetailList.map((item)=>{
  237. if(val.value == item.name){
  238. return <td style={{width:'20%'}} className={item.abnormal != '0' ?"red":'' }>{val.value}</td>
  239. }
  240. })
  241. }else{
  242. return <td style={{width:'20%'}}><span className={(val.value - 0).toString() == 'NaN'?"red":(val.maxValue || val.minValue) ? (val.value > val.maxValue || val.value < val.minValue?"red":''):''}>{val.value}</span> { val.labelSuffix}</td>
  243. }
  244. }
  245. render() {
  246. const { handleChangeValue, list, labelList,delPartItem, handleLabelSub, handleClear, handleConfirm, fillActive,getExcelDataList,handleCloseExcel,handlePush } = this.props;
  247. const {toastText,visible} = this.state;
  248. return (
  249. <div className={styles.wrapper}>
  250. <div className={styles.check}>
  251. {
  252. getExcelDataList.length > 0 && getExcelDataList.map((items,id)=>{
  253. return <div style={{marginTop:'10px'}}>
  254. {
  255. items && items.lisExcelRes.length > 0 ? <ul className={styles.excelDataLists}>
  256. <img className={styles.close} src={close} alt="关闭导入excel数据" onClick={()=>{this.handleDelClick(2,id)}}/>
  257. {
  258. items.lisExcelRes.map((item,idx)=>{
  259. return <li className={styles.excelDataLis} style={{border:items.lisExcelRes.length-1 == idx? 0:''}}>
  260. <span className={styles.excelDataTitle}>
  261. {item.menus}
  262. </span>
  263. <table>
  264. {
  265. item.lisExcelItem && item.lisExcelItem.map((value)=>{
  266. return <tr>
  267. <td style={{width:'30%'}}>{value.itemName}</td>
  268. <td style={{width:'20%'}}><span className={value.type == 1?'red':null}>{value.value}</span> {value.unit}</td>
  269. <td style={{width:'25%'}}>
  270. {normalVal(value.min,value.max)}
  271. </td>
  272. <td style={{width:'25%'}}>{value.time == ''?('导入时间: '+this.state.dateTime):'化验时间: '+value.time}</td>
  273. </tr>
  274. })
  275. }
  276. </table>
  277. </li>
  278. })
  279. }
  280. </ul>:null
  281. }
  282. </div>
  283. })
  284. }
  285. <ul className={styles.labelWrap} >
  286. {
  287. labelList && labelList.map((item,idx) => {
  288. return <li key={item.questionId}>
  289. {
  290. // 标签,血常规。。
  291. item.show ?
  292. <p className={styles.staticTagActive}>
  293. <span data-flg="current" style={{color:"#333"}} onClick={(e) => { handleLabelSub(e, item.questionId,idx); this.handleFillShow(e,idx) }}>{item.name}</span>
  294. </p>:
  295. <p>
  296. <i data-flg="current" onClick={(e) => { handleLabelSub(e,item.questionId,idx); this.handleFillShow(e,idx) }}>{item.name}</i>
  297. </p>
  298. }
  299. {
  300. item.show ?
  301. <table className={styles.table}>
  302. {
  303. item.details.map((val)=>{
  304. if(val.value && val.value != ''){
  305. return <tr>
  306. <td style={{width:'30%'}}>{val.name}</td>
  307. {this.showDetails(val)}
  308. <td style={{width:'25%'}}>
  309. {normalVal(val.minValue,val.maxValue)}
  310. </td>
  311. <td style={{width:'25%'}}>{'化验时间:'+item.time}</td>
  312. </tr>
  313. }
  314. })
  315. }
  316. </table>:null
  317. }
  318. <div className={styles.searchResult}>
  319. {
  320. this.state.showFill && fillActive.id == item.id && idx == this.state.currentIdx ?
  321. <InspectCommon
  322. showFill={this.state.showFill}
  323. handleClear={(e)=>{
  324. handleClear(e,idx)
  325. this.setState({
  326. currentData:fillActive
  327. })
  328. }}
  329. handleConfirm={(e)=>{
  330. // handleConfirm(e,idx,this.state.dateTime,fillActive);
  331. if(JSON.stringify(this.state.currentData) == '{}'){
  332. handleConfirm(e,idx,this.state.dateTime,fillActive);
  333. }else{
  334. handleConfirm(e,idx,this.state.dateTime,this.state.currentData);
  335. }
  336. this.setState({showFill:false})
  337. handlePush&&handlePush(); //右侧推送
  338. }}
  339. >
  340. <div className={styles.searchResultT}>
  341. <img style={{"position":"absolute","top":"8px","right":"8px"}} src={date1} alt="" onClick={this.handleShowDate}/>
  342. <p style={{position:"absolute",right:"38px",top:"4px",lineHeight:"28px"}}>
  343. {
  344. this.state.dateTime
  345. }
  346. </p>
  347. <div style={{display:this.state.date?"block":"none",position:"relative"}}>
  348. {/* 日期组件 */}
  349. <Calendar isShow={true} handleChange={this.handleChangeDate}></Calendar>
  350. </div>
  351. </div>
  352. {/* 填写单内容显示 */}
  353. { this.getItemList(idx) }
  354. </InspectCommon>
  355. : null
  356. }
  357. </div>
  358. <img className={styles.partDel} src={close} alt="删除项" onClick={()=>{this.handleDelClick(1,idx)}}/>
  359. </li>
  360. })
  361. }
  362. </ul>
  363. </div>
  364. <div style={{position:"relative"}}>
  365. <Add showText="添加化验项" handleClick={(e) => this.handleSearchShow(e)} id="searchWrap"/>
  366. {this.state.show?<SearchOption handleChangeValue={handleChangeValue} visible={true}>
  367. {this.getSearchList(list)}
  368. </SearchOption>:''}
  369. </div>
  370. <ConfirmModal
  371. visible={visible}
  372. confirm={this.delConfirm}
  373. close={this.handleCancel}
  374. cancel={this.handleCancel}
  375. okText="删除"
  376. cancelText='取消'
  377. okBorderColor={'#3B9ED0'}
  378. okColor={'#fff'}
  379. oKBg={'#3B9ED0'}
  380. >
  381. <p className={styles['center']}>{toastText}</p>
  382. </ConfirmModal>
  383. </div>
  384. )
  385. }
  386. }
  387. export default Inspect;