index.jsx 7.7 KB

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