index.jsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. import React from 'react';
  2. import { ItemBox, ConfirmModal, WrapModalContainer } 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,getCurrentDate } from '@utils/tools.js';
  11. import { dragBox } from '@utils/drag';
  12. import WrapModalBody from '@containers/WrapModalBody';
  13. (function ($) {
  14. var FileAPI = {
  15. // @default: "./dist/"
  16. staticPath: './dists/',
  17. // @default: FileAPI.staticPath + "FileAPI.flash.swf"
  18. flashUrl: './dists/FileAPI.flash.swf',
  19. // @default: FileAPI.staticPath + "FileAPI.flash.image.swf"
  20. flashImageUrl: './dists/FileAPI.flash.image.swf'
  21. };
  22. return FileAPI
  23. })($)
  24. import "./dists/FileAPI.js";
  25. const isLocal = window.location.hostname.indexOf('localhost') != -1;
  26. const qhost = isLocal ? host + prefix : prefix;
  27. const api = {
  28. upload: qhost + '/lisExcelRes/lisExcelAnalysis'
  29. };
  30. let numFlg = 0;
  31. class Inspect extends React.Component {
  32. constructor(props) {
  33. super(props);
  34. this.state = {
  35. val: '',
  36. visible: false,
  37. dom: [],
  38. isIE: isIE(),
  39. ieVersion: null,
  40. height: '-1',
  41. hide: false,
  42. importLis:false
  43. }
  44. this.handleImportExcel = this.handleImportExcel.bind(this);
  45. this.cancel = this.cancel.bind(this);
  46. this.getWarings = this.getWarings.bind(this);
  47. this.checkSystemIpt = this.checkSystemIpt.bind(this);
  48. this.onClose = this.onClose.bind(this);
  49. this.handleBindFileApi = this.handleBindFileApi.bind(this);
  50. this.closeInIcss = this.closeInIcss.bind(this);
  51. this.showSlideImport = this.showSlideImport.bind(this);
  52. this.refreshScroller = this.refreshScroller.bind(this);
  53. }
  54. componentDidMount() {
  55. $(document).click((event) => {
  56. let searchWrap = $('#importInspectBtn')[0]; // 导入按钮按钮
  57. let searchOption = $('#importList')[0]; // 下拉列表
  58. if (searchOption&&$('#importList').css("display")=="block") {
  59. if(searchWrap != event.target){
  60. this.setState({ importLis: false });
  61. }
  62. }
  63. });
  64. }
  65. handleBindFileApi(){
  66. const {message} = this.props;
  67. var ua = navigator.userAgent;
  68. var _isIE = ua.indexOf("MSIE") > -1;
  69. if (_isIE) {
  70. let version = ua.match(/MSIE ([\d.]+)/)[1];
  71. this.setState({
  72. ieVersion: version
  73. })
  74. }
  75. $('iframe').bind('load', function () { })
  76. const { fetchPushInfos } = this.props;
  77. // FileAPI.debug = true
  78. $.support.cors = true;
  79. const that = this;
  80. var choose = document.getElementById('choose');
  81. FileAPI.event.on(choose, 'change', function (evt) {
  82. var files = FileAPI.getFiles(evt);
  83. FileAPI.filterFiles(files, function (file, info) {
  84. let name = file.name;
  85. // if( name.split('.')[1] == 'xlsx' || name.split('.')[1] == 'xls' ){
  86. // Notify.error('请选择正确的excel表格')
  87. // return false;
  88. // }else{
  89. // return true;
  90. // }
  91. return true;
  92. },
  93. function (files, rejected) {
  94. if (files.length) {
  95. //console.log(files[0])
  96. const securityCode = getUrlArgObject("code");
  97. const appKeyId = getUrlArgObject("appI");
  98. const appKeySecret = getUrlArgObject("appS");
  99. FileAPI.upload({
  100. // url: '/api/icss/lisExcelRes/lisExcelAnalysis',
  101. url: api.upload,
  102. data: { hospitalCode: message == '{}' ? '' : message.hospitalCode },
  103. files: { uploadfile: files[0] },
  104. headers: {
  105. appKeyId: appKeyId,
  106. appKeySecret: appKeySecret,
  107. securityCode: securityCode
  108. },
  109. complete: function (err, xhr) {
  110. if (!err) {
  111. let res = JSON.parse(xhr.response);
  112. if(res.code == 0){
  113. let message = res.data.messages;
  114. if(res.data.lisExcelRes){
  115. for(let i = 0;i < res.data.lisExcelRes.length;i++){
  116. let tmpLisExcelItem = res.data.lisExcelRes[i]
  117. if(tmpLisExcelItem.lisExcelItem){
  118. for(let j = 0;j < tmpLisExcelItem.lisExcelItem.length;j++){
  119. tmpLisExcelItem.lisExcelItem[j].time = tmpLisExcelItem.lisExcelItem[j].time||getCurrentDate(1)
  120. }
  121. }
  122. }
  123. }
  124. store.dispatch(getExcelList(res.data));
  125. fetchPushInfos && fetchPushInfos();
  126. if (message && message.length != 0) {
  127. that.setState({
  128. visible: true,
  129. dom: message,
  130. height: message.length
  131. })
  132. }
  133. }else{
  134. Notify.error(res.msg)
  135. }
  136. $("#choose").val("");
  137. } else {
  138. let res = JSON.parse(xhr.response);
  139. Notify.error(res.msg)
  140. $("#choose").val("");
  141. }
  142. }
  143. });
  144. }
  145. });
  146. });
  147. }
  148. handleImportExcel() {
  149. this.inputRef.click();
  150. }
  151. cancel() {
  152. this.setState({ visible: false })
  153. }
  154. getStyle() {
  155. const { ieVersion } = this.state;
  156. if (ieVersion && ieVersion <= 9) {
  157. return styles.disabledBtn;
  158. } else {
  159. return styles.button;
  160. }
  161. }
  162. getWarings(lis) {
  163. <ul>
  164. {
  165. lis.length > 0 && lis.map((val) => {
  166. return <li>
  167. {val}
  168. </li>
  169. })
  170. }
  171. </ul>
  172. }
  173. checkSystemIpt() {
  174. this.setState({
  175. hide: true
  176. })
  177. }
  178. onClose() {
  179. this.setState({
  180. hide: false
  181. })
  182. dragBox('previewWrapper', 'previewStatic', 'del')
  183. }
  184. closeInIcss(){
  185. this.setState({
  186. hide: false
  187. })
  188. }
  189. showSlideImport(){
  190. let flg = this.state.importLis
  191. this.setState({
  192. importLis:!flg
  193. })
  194. }
  195. refreshScroller(){
  196. //滚动条对象
  197. return this.context.scrollArea;
  198. /*this.context.scrollArea.refresh();
  199. this.context.scrollArea.scrollBottom();*/
  200. }
  201. render() {
  202. const {setHighter, fetchPushInfos,getInfomation, hospitalMsg, inspectVal, windowHeight, windowWidth, handleCloseExcel, handleChangeValue, labelListActive, list, handleSign, labelList, handleLabelSub, handleClear, handleConfirm, fillActive, changeActivePart, getExcelDataList, delPartItem, inspectList } = this.props;
  203. const { ieVersion, isIE, hide,importLis } = this.state;
  204. const { checkSystemIpt, onClose,handleBindFileApi,closeInIcss,showSlideImport } = this;
  205. if(JSON.stringify(hospitalMsg) != {} && document.getElementById("choose")){//动态绑定只绑定一次
  206. ++numFlg
  207. numFlg == 1?handleBindFileApi():null
  208. }
  209. return (
  210. <div className={styles.wrapper}>
  211. {/* 导入功能插件,ie8/9权限问题暂未解决,先隐藏 */}
  212. <div className={styles.top}>
  213. <span id="inspectResultData">化验结果数据</span>
  214. {/* <div className={this.getStyle()} onClick={ieVersion&&ieVersion<=9?null:this.handleImportExcel}> */}
  215. <div className={this.getStyle()} style={{ display: hospitalMsg.import_way_lis == 0 ? 'none' : 'block' }}>
  216. {/* <button disabled={ieVersion&&ieVersion>9?true:false}onClick={ieVersion && ieVersion <= 9 ? null : this.handleImportExcel}>导入化验结果</button>
  217. <input accept=".csv, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel" type="file" name="uploadfile" id="choose" style={{ display: 'none' }} ref={(DOM) => this.inputRef = DOM} /> */}
  218. {/* {0没有,1本地,2医院,3本地和医院} */}
  219. {
  220. hospitalMsg.import_way_lis == 1 ? <div className={styles.pushButton} disabled={ieVersion && ieVersion > 9 ? true : false} onClick={ieVersion && ieVersion <= 9 ? null : this.handleImportExcel}>
  221. <p className={styles.importInspectBtn}>导入化验结果</p>
  222. <input accept=".csv, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel" type="file" name="uploadfile" id="choose" style={{ display: 'none' }} ref={(DOM) => this.inputRef = DOM} />
  223. </div> : hospitalMsg.import_way_lis == 2 ? <div className={styles.pushButton} disabled={ieVersion && ieVersion > 9 ? true : false} onClick={checkSystemIpt}>
  224. <p className={styles.importInspectBtn}>导入化验结果</p>
  225. </div> : hospitalMsg.import_way_lis == 3 ? <div className={`${styles.pushButton} ${styles.importInspect}`} onClick={showSlideImport}>
  226. <p id="importInspectBtn" className={styles.importInspectBtn}>导入化验结果</p>
  227. {
  228. <ul className={styles.importSelect} style={{display:importLis?'block':'none'}} id="importList">
  229. <li className={styles.excelIpt}>
  230. <div onClick={ieVersion && ieVersion <= 9 ? null : this.handleImportExcel}>本地导入</div>
  231. <input accept=".csv, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel" type="file" name="uploadfile" id="choose" style={{ display: 'none' }} ref={(DOM) => this.inputRef = DOM} />
  232. </li>
  233. <li className={`${styles.excelIpt} ${styles.systemIpt}`} onClick={checkSystemIpt}>从设备导入</li>
  234. </ul>
  235. }
  236. </div> : null
  237. }
  238. {
  239. hide ? <WrapModalContainer title={'导入化验数据'} width={1000} height={570} onClose={onClose}>
  240. <WrapModalBody
  241. height={570}
  242. closeInIcss={closeInIcss}
  243. ></WrapModalBody>
  244. </WrapModalContainer> : null
  245. }
  246. </div>
  247. </div>
  248. <ItemBox
  249. className={styles.title}
  250. title={'化验'}
  251. editable={false}
  252. border={true}
  253. style={{marginRight:'0'}}
  254. marginTop={'20px'}
  255. >
  256. <div style={{ padding: '10px', boxSizing: 'border-box' }} >
  257. <AddInspect
  258. handleSign={handleSign}
  259. setHighter={setHighter}
  260. refreshScroller={this.refreshScroller}
  261. handleChangeValue={handleChangeValue}
  262. list={list}
  263. handlePush={fetchPushInfos}
  264. labelList={labelList}
  265. handleLabelSub={handleLabelSub}
  266. fillActive={fillActive}
  267. handleClear={handleClear}
  268. handleConfirm={handleConfirm}
  269. changeActivePart={changeActivePart}
  270. getExcelDataList={getExcelDataList}
  271. handleCloseExcel={handleCloseExcel}
  272. labelListActive={labelListActive}
  273. delPartItem={delPartItem}
  274. inspectList={inspectList}
  275. getInfomation={getInfomation}
  276. inspectVal={inspectVal}
  277. windowHeight={windowHeight}
  278. windowWidth={windowWidth}
  279. >
  280. </AddInspect>
  281. </div>
  282. </ItemBox>
  283. <ConfirmModal visible={this.state.visible}
  284. okText='删除'
  285. cancelText='确定'
  286. width="450"
  287. height={(this.state.height > 2 && this.state.height < 8) ? ((this.state.height * 30 + 120) + 'px') : this.state.height > 8 ? '350px' : '200px'}
  288. noFooter={true}
  289. close={this.cancel}>
  290. <ul className={styles.excelList}>
  291. {
  292. this.state.dom.length > 0 && this.state.dom.map((val) => {
  293. return <li className={styles.excelListWaring}>
  294. {val}
  295. </li>
  296. })
  297. }
  298. </ul>
  299. <div onClick={this.cancel} className={styles.confirmBtn}>确定</div>
  300. </ConfirmModal>
  301. </div>
  302. )
  303. }
  304. }
  305. Inspect.contextTypes = {
  306. scrollArea: React.PropTypes.object
  307. };
  308. export default Inspect;