index.jsx 8.1 KB

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