index.jsx 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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,prefix } from '@utils/config.js';
  10. import {isIE,getUrlArgObject} 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+prefix:prefix;
  25. const api = {
  26. upload: qhost+'/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. const securityCode = getUrlArgObject("code");
  76. const appKeyId = getUrlArgObject("appI");
  77. const appKeySecret = getUrlArgObject("appS");
  78. FileAPI.upload({
  79. // url: '/api/icss/lisExcelRes/lisExcelAnalysis',
  80. url: api.upload,
  81. data:{ hospitalCode:baseData == '{}'? '' : baseData.hospitalCode },
  82. files: { uploadfile: files[0] },
  83. headers:{
  84. appKeyId:appKeyId,
  85. appKeySecret:appKeySecret,
  86. securityCode:securityCode
  87. // 'Content-Type':'Content-Type: multipart/form-data'
  88. // 'Content-Type':'application/json;charset=UTF-8'
  89. // 'Content-type': "text/plain"
  90. // "Content-Type": 'multipart/form-data',
  91. // 'Accept':'application/json'
  92. },
  93. complete: function (err, xhr){
  94. if( !err ){
  95. let res = JSON.parse(xhr.response);
  96. let message = res.data.messages;
  97. store.dispatch(getExcelList(res.data));
  98. fetchPushInfos&&fetchPushInfos();
  99. if (message&&message.length != 0) {
  100. that.setState({
  101. visible:true,
  102. dom:message,
  103. height:message.length
  104. })
  105. }
  106. $("#choose").val("");
  107. }else{
  108. let res = JSON.parse(xhr.response);
  109. Notify.error(res.msg)
  110. }
  111. }
  112. });
  113. }
  114. });
  115. });
  116. }
  117. handleImportExcel() {
  118. this.inputRef.click();
  119. }
  120. cancel(){
  121. this.setState({visible:false})
  122. }
  123. getStyle(){
  124. const {ieVersion} = this.state;
  125. if(ieVersion&&ieVersion<=9){
  126. return styles.disabledBtn;
  127. }else{
  128. return styles.button;
  129. }
  130. }
  131. getWarings(lis){
  132. <ul>
  133. {
  134. lis.length>0 && lis.map((val)=>{
  135. return <li>
  136. {val}
  137. </li>
  138. })
  139. }
  140. </ul>
  141. }
  142. render() {
  143. const {fetchPushInfos,getInfomation,inspectVal, handleCloseExcel, handleChangeValue, labelListActive, list, handleSign, labelList, handleLabelSub, handleClear, handleConfirm, fillActive, changeActivePart, getExcelDataList,delPartItem,inspectList } = this.props;
  144. const {ieVersion,isIE} = this.state;
  145. return (
  146. <div className={styles.wrapper} >
  147. {/* 导入功能插件,ie8/9权限问题暂未解决,先隐藏 */}
  148. <div className={styles.top}>
  149. <span id="inspectResultData">化验结果数据</span>
  150. <div className={this.getStyle()} onClick={ieVersion&&ieVersion<=9?null:this.handleImportExcel}>
  151. {/* <button disabled={ieVersion&&ieVersion>9?true:false}>导入化验结果</button>*/}
  152. <div className={styles.pushButton}>导入化验结果</div>
  153. <input type="file" name="uploadfile" id="choose" style={{ display: 'none' }} ref={(DOM) => this.inputRef = DOM} />
  154. </div>
  155. </div>
  156. <ItemBox
  157. className={styles.title}
  158. title={'化验'}
  159. editable={false}
  160. border={true}
  161. marginTop={'20px'}
  162. >
  163. <div style={{ padding: '10px', boxSizing: 'border-box' }} >
  164. <AddInspect
  165. handleSign={handleSign}
  166. handleChangeValue={handleChangeValue}
  167. list={list}
  168. handlePush={fetchPushInfos}
  169. labelList={labelList}
  170. handleLabelSub={handleLabelSub}
  171. fillActive={fillActive}
  172. handleClear={handleClear}
  173. handleConfirm={handleConfirm}
  174. changeActivePart={changeActivePart}
  175. getExcelDataList={getExcelDataList}
  176. handleCloseExcel={handleCloseExcel}
  177. labelListActive={labelListActive}
  178. delPartItem={delPartItem}
  179. inspectList={inspectList}
  180. getInfomation={getInfomation}
  181. inspectVal={inspectVal}
  182. >
  183. </AddInspect>
  184. </div>
  185. </ItemBox>
  186. <ConfirmModal visible={this.state.visible}
  187. okText='删除'
  188. cancelText='确定'
  189. width="450"
  190. height={(this.state.height > 2 && this.state.height < 8)?((this.state.height * 30 + 120)+'px') : this.state.height > 8 ? '350px' : '200px'}
  191. noFooter= {true}
  192. close={this.cancel}>
  193. <ul className={styles.excelList}>
  194. {
  195. this.state.dom.length>0 && this.state.dom.map((val)=>{
  196. return <li className={styles.excelListWaring}>
  197. {val}
  198. </li>
  199. })
  200. }
  201. </ul>
  202. <div onClick={this.cancel} className={styles.confirmBtn}>确定</div>
  203. </ConfirmModal>
  204. </div>
  205. )
  206. }
  207. }
  208. export default Inspect;