index.jsx 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. import React from 'react';
  2. import { ItemBox,ConfirmModal } from '@commonComp';
  3. import AddInspect from '../AddInspect';
  4. import styles from './index.less';
  5. import { getExcelList } from '@store/actions/inspect';
  6. import Notify from '@commonComp/Notify';
  7. import store from '@store';
  8. import $ from 'jquery';
  9. import { host } from '@utils/config.js';
  10. import {isIE} from '@utils/tools.js';
  11. (function ($) {
  12. var FileAPI = {
  13. // @default: "./dist/"
  14. staticPath: './dists/',
  15. // @default: FileAPI.staticPath + "FileAPI.flash.swf"
  16. flashUrl: './dists/FileAPI.flash.swf',
  17. // @default: FileAPI.staticPath + "FileAPI.flash.image.swf"
  18. flashImageUrl: './dists/FileAPI.flash.image.swf'
  19. };
  20. return FileAPI
  21. })($)
  22. import "./dists/FileAPI.js";
  23. const isLocal = window.location.hostname.indexOf('localhost')!=-1;
  24. const qhost = isLocal?host:'';
  25. const api = {
  26. upload: qhost+'/api/icss/lisExcelRes/lisExcelAnalysis'
  27. };
  28. class Inspect extends React.Component {
  29. constructor(props) {
  30. super(props);
  31. this.state = {
  32. val: '',
  33. visible:false,
  34. dom:[],
  35. isIE:isIE(),
  36. }
  37. this.handleImportExcel = this.handleImportExcel.bind(this)
  38. this.cancel = this.cancel.bind(this)
  39. this.getWarings = this.getWarings.bind(this)
  40. }
  41. componentDidMount(){
  42. $('iframe').bind( 'load', function(){} )
  43. const {fetchPushInfos} = this.props;
  44. // FileAPI.debug = true
  45. $.support.cors = true;
  46. const that = this;
  47. var choose = document.getElementById('choose');
  48. FileAPI.event.on(choose, 'change', function (evt){
  49. var files = FileAPI.getFiles(evt);
  50. var baseData = store.getState().patInfo.message;
  51. FileAPI.filterFiles(files, function (file, info){
  52. let name = file.name;
  53. // if( name.split('.')[1] == 'xlsx' || name.split('.')[1] == 'xls' ){
  54. // Notify.error('请选择正确的excel表格')
  55. // return;
  56. // }else{
  57. // alert(9)
  58. // return true;
  59. // }
  60. return true;
  61. },
  62. function (files, rejected){
  63. if( files.length ){
  64. console.log(files[0])
  65. FileAPI.upload({
  66. // url: '/api/icss/lisExcelRes/lisExcelAnalysis',
  67. url: api.upload,
  68. data:{ hospitalCode:baseData == '{}'? '' : baseData.hospitalCode },
  69. files: { uploadfile: files[0] },
  70. headers:{
  71. // 'Content-Type':'Content-Type: multipart/form-data'
  72. // 'Content-Type':'application/json;charset=UTF-8'
  73. // 'Content-type': "text/plain"
  74. // "Content-Type": 'multipart/form-data',
  75. // 'Accept':'application/json'
  76. },
  77. complete: function (err, xhr){
  78. if( !err ){
  79. let res = JSON.parse(xhr.response);
  80. let message = res.data.messages;
  81. store.dispatch(getExcelList(res.data));
  82. fetchPushInfos&&fetchPushInfos();
  83. if (message.length != 0) {
  84. that.setState({
  85. visible:true,
  86. dom:message
  87. })
  88. }
  89. $("#choose").val("");
  90. }else{
  91. Notify.error(res.msg)
  92. }
  93. }
  94. });
  95. }
  96. });
  97. });
  98. }
  99. handleImportExcel() {
  100. this.inputRef.click();
  101. }
  102. cancel(){
  103. this.setState({visible:false})
  104. }
  105. getStyle(){
  106. if(this.state.isIE){
  107. return styles.disabledBtn;
  108. }else{
  109. return styles.button;
  110. }
  111. }
  112. getWarings(lis){
  113. <ul>
  114. {
  115. lis.length>0 && lis.map((val)=>{
  116. return <li>
  117. {val}
  118. </li>
  119. })
  120. }
  121. </ul>
  122. }
  123. render() {
  124. const {fetchPushInfos, handleCloseExcel, handleChangeValue, labelListActive, list, handleSign, labelList, handleLabelSub, handleClear, handleConfirm, fillActive, changeActivePart, getExcelDataList,delPartItem } = this.props;
  125. return (
  126. <div className={styles.wrapper} >
  127. {/* 导入功能插件,ie8/9权限问题暂未解决,先隐藏 */}
  128. <div className={styles.top}>
  129. <span>化验结果数据</span>
  130. <div className={this.getStyle()} onClick={this.state.isIE?null:this.handleImportExcel}>
  131. <button disabled={this.state.isIE?true:false}>导入化验结果</button>
  132. <input type="file" name="uploadfile" id="choose" style={{ display: 'none' }} ref={(DOM) => this.inputRef = DOM} />
  133. </div>
  134. </div>
  135. <ItemBox
  136. className={styles.title}
  137. title={'化验'}
  138. editable={false}
  139. border={true}
  140. marginTop={'20px'}
  141. >
  142. <div style={{ padding: '10px', boxSizing: 'border-box' }} >
  143. <AddInspect
  144. handleSign={handleSign}
  145. handleChangeValue={handleChangeValue}
  146. list={list}
  147. handlePush={fetchPushInfos}
  148. labelList={labelList}
  149. handleLabelSub={handleLabelSub}
  150. fillActive={fillActive}
  151. handleClear={handleClear}
  152. handleConfirm={handleConfirm}
  153. changeActivePart={changeActivePart}
  154. getExcelDataList={getExcelDataList}
  155. handleCloseExcel={handleCloseExcel}
  156. labelListActive={labelListActive}
  157. delPartItem={delPartItem}
  158. >
  159. </AddInspect>
  160. </div>
  161. </ItemBox>
  162. <ConfirmModal visible={this.state.visible}
  163. okText='删除'
  164. cancelText='确定'
  165. width="450"
  166. noFooter= {true}
  167. close={this.cancel}>
  168. <ul className={styles.excelList}>
  169. {
  170. this.state.dom.length>0 && this.state.dom.map((val)=>{
  171. return <li className={styles.excelListWaring}>
  172. {val}
  173. </li>
  174. })
  175. }
  176. </ul>
  177. <div onClick={this.cancel} className={styles.confirmBtn}>确定</div>
  178. </ConfirmModal>
  179. </div>
  180. )
  181. }
  182. }
  183. export default Inspect;