index.jsx 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  1. import React from 'react';
  2. import { SearchOption, InspectCommon, Calendar, Notify, ConfirmModal, Add, DelToast } from '@commonComp';
  3. import SlideExcel from './SlideExcel';
  4. import SlideSelect from './SlideSelect';
  5. import { deepClone, getPageCoordinate, getStatusImg ,getCurrentDate,setPosition} from '@utils/tools';
  6. import styles from './index.less';
  7. import ScrollArea from 'react-scrollbar';
  8. import store from '@store';
  9. import $ from 'jquery';
  10. class Inspect extends React.Component {
  11. constructor(props) {
  12. super(props);
  13. this.state = {
  14. show: false,
  15. showFill: false,
  16. date: false,
  17. currentIdx: '',
  18. dateTime: "",
  19. currentData: {},
  20. numPlus: 0, //判断是否所有的填写单都是空
  21. num: 0, //暂存数据,获取一次,不能每次都是新的数据
  22. type: null,
  23. id: null,
  24. pageTop: '',
  25. // tmpIds: [], //内层外层
  26. impId: null
  27. }
  28. this.$ul = React.createRef();
  29. this.handleChangeDate = this.handleChangeDate.bind(this)
  30. this.handleShowDate = this.handleShowDate.bind(this)
  31. this.getItemList = this.getItemList.bind(this)
  32. this.getSearchList = this.getSearchList.bind(this)
  33. this.getCommonList = this.getCommonList.bind(this)
  34. this.changeActivePart = this.changeActivePart.bind(this)
  35. this.showDetails = this.showDetails.bind(this)
  36. this.delConfirm = this.delConfirm.bind(this)
  37. this.handleCancel = this.handleCancel.bind(this)
  38. this.handleSearchShow = this.handleSearchShow.bind(this)
  39. this.changeShowFill = this.changeShowFill.bind(this)
  40. this.handleFillShow = this.handleFillShow.bind(this)
  41. this.handleDelClick = this.handleDelClick.bind(this)
  42. }
  43. delConfirm() {//弹窗确定
  44. const { delPartItem, handleCloseExcel, handlePush } = this.props;
  45. const { type, id, impId } = this.state;
  46. if (type == 1) {
  47. delPartItem(id)
  48. } else if (type == 2) {
  49. handleCloseExcel(impId)
  50. }
  51. this.setState({
  52. type: null,
  53. id: null,
  54. impId: null
  55. })
  56. Notify.success("删除成功");
  57. handlePush && handlePush(); //右侧推送
  58. }
  59. handleDelClick(type, idx) {
  60. if (type == 2) {
  61. this.setState({
  62. impId: idx,
  63. type: type,
  64. id: null
  65. })
  66. } else {
  67. this.setState({
  68. type: type,
  69. id: idx,
  70. impId: null
  71. })
  72. }
  73. }
  74. handleCancel() {
  75. this.setState({
  76. type: null,
  77. id: null,
  78. impId: null
  79. })
  80. }
  81. componentDidMount() {
  82. $(document).click((event) => {
  83. let searchWrap = document.getElementById("searchWrap"); // 搜索按钮
  84. let searchOption = document.getElementById("searchOption"); // 搜索列表
  85. let inspectFill = document.getElementById("inspectFill"); // 公共填写单
  86. let _del = $('#delBox')[0]; // 删除弹窗
  87. let _impClose = $('#impClose')[0]; // 导入删除按钮
  88. let _addClose = $('#addClose')[0]; // 添加删除按钮
  89. let _closeTil = $('#delTit')[0]; // 弹窗标题
  90. if (searchOption) {
  91. if (searchOption != event.target && searchWrap != event.target && searchWrap != event.target.parentNode && !$.contains(searchOption, event.target)) { // Mark 1
  92. if(this.state.show){
  93. this.props.setHighter(48)
  94. }
  95. this.setState({ show: false });
  96. }
  97. }
  98. if (inspectFill) {
  99. if ($(event.target).attr('id') != "getSureTime"&&event.target.getAttribute('data-flg') != 'current' && inspectFill != event.target && !$.contains(inspectFill, event.target)) { // Mark 1
  100. if(this.state.showFill){
  101. this.props.setHighter(48)
  102. }
  103. this.setState({ showFill: false, date: false });
  104. }
  105. }
  106. if (_del) {
  107. if (!event.target.isEqualNode(_impClose) && !event.target.isEqualNode(_addClose) && !event.target.isEqualNode(_del) && event.target.parentNode != _del && !event.target.isEqualNode(_closeTil)) {
  108. this.setState({
  109. id: null,
  110. impId: null
  111. })
  112. }
  113. }
  114. });
  115. // this.setState({ dateTime: getCurrentDate(1) })
  116. }
  117. componentWillReceiveProps(nextProps) {
  118. if (nextProps.fillActive.name != this.props.fillActive.name) {
  119. this.setState({ num: 0 })
  120. }
  121. }
  122. changeShowFill() {
  123. this.setState({ showFill: false })
  124. this.props.setHighter(48)
  125. }
  126. handleChangeDate(info) {
  127. // let date = info.year+'-'+info.month.toString().padStart(2,'0')+'-'+info.day.toString().padStart(2,'0')
  128. let date = info.year+'-'+info.month.toString().padStart(2,'0')+'-'+info.day.toString().padStart(2,'0')+' '+info.hour.toString().padStart(2,'0')+':'+info.minute.toString().padStart(2,'0')+':'+info.second.toString().padStart(2,'0');
  129. this.setState({ dateTime: date, date: false })
  130. }
  131. handleSearchShow(e) {
  132. let tmpShow = this.state.show;
  133. this.setState({ show: !tmpShow, pageTop: getPageCoordinate(e).boxTop })
  134. // e.stopPropagation();
  135. setPosition(e,"#searchOption",this.props.setHighter);
  136. }
  137. handleFillShow(e, idx) {
  138. let tmpShow = this.state.showFill;
  139. let baseList = store.getState().inspect.fillActive;
  140. this.setState({
  141. showFill: !tmpShow,
  142. currentIdx: idx,
  143. currentData: baseList,
  144. dateTime: baseList.time ? baseList.time : getCurrentDate(1)
  145. })
  146. e.stopPropagation();
  147. }
  148. handleShowDate() {
  149. this.setState({
  150. date: !this.state.date
  151. })
  152. }
  153. changeActivePart(idx, val, clear) {
  154. let nums = this.state.num;
  155. let fillActive;
  156. if (nums == 0) {
  157. fillActive = this.props.fillActive;
  158. } else {
  159. fillActive = this.state.currentData;
  160. }
  161. ++nums;
  162. this.setState({ num: nums });
  163. let tempArr = deepClone(fillActive);
  164. if (clear) { //点击清空按钮,至清初输入的数字
  165. for (let i = 0; i < tempArr.details.length; i++) {
  166. tempArr.details[i].value = ''
  167. tempArr.show = false;
  168. }
  169. tempArr.time = getCurrentDate(1);
  170. this.setState({ currentData: tempArr })
  171. return;
  172. } else {
  173. let tempNumPlus = 0;
  174. for (let i = 0; i < tempArr.details.length; i++) {
  175. if (i == idx) {
  176. tempArr.details[i].value = val
  177. }
  178. if (tempArr.details[i].value != undefined && tempArr.details[i].value != '') {
  179. tempArr.show = true;
  180. } else {
  181. ++tempNumPlus;
  182. if (tempNumPlus == tempArr.details.length) {
  183. tempArr.show = false;
  184. }
  185. }
  186. }
  187. tempArr.time = this.state.dateTime;
  188. this.setState({ currentData: tempArr })
  189. }
  190. }
  191. getItemList() { //填写单展示
  192. let number = this.state.num;
  193. let fillActive;
  194. if (number == 0) {
  195. fillActive = this.props.fillActive;
  196. } else {
  197. fillActive = this.state.currentData;
  198. }
  199. return <ul className={styles.searchLis} ref={this.$ul}>
  200. {
  201. fillActive && fillActive.details && fillActive.details.map((item, idx) => {
  202. if (item.controlType == 1) {
  203. return (
  204. <li className={`${styles.itemPart} ${fillActive.details.length > 1 ? '' : styles.itemPartOne}`}>
  205. <span className={styles.itemPartL}>{item.name}</span>
  206. <span className={styles.itemPartT}>
  207. <select className={styles.itemPartR} onChange={(e) => {
  208. if (e.target.value == '请选择') {
  209. this.changeActivePart(idx, '')
  210. return;
  211. }
  212. this.changeActivePart(idx, e.target.value);
  213. }}
  214. >
  215. <option value="请选择">请选择</option>
  216. {
  217. (item.questionDetailList).map((val) => {
  218. return <option value={val.name}
  219. selected={val.name == item.value ? true : false}
  220. >{val.name}</option>
  221. })
  222. }
  223. </select>
  224. </span>
  225. </li>
  226. )
  227. } else if (item.controlType == 6) {
  228. return (
  229. <li className={`${styles.itemPart} ${fillActive.details.length > 1 ? '' : styles.itemPartOne}`}>
  230. <span className={styles.itemPartL} title={item.name}>{item.name}</span>
  231. <span className={styles.itemPartT}>
  232. <input type="text"
  233. placeholder="(填写)"
  234. value={item.value}
  235. onKeyUp={(e) => { this.changeActivePart(idx, e.target.value.trim()) }}
  236. />
  237. <p className={styles.unit} title={item.labelSuffix}>{item.labelSuffix}</p>
  238. </span>
  239. </li>
  240. )
  241. }
  242. })
  243. }
  244. </ul>
  245. }
  246. getSearchList(list) {//搜索列表
  247. const { handleSign } = this.props;
  248. const contStyle={
  249. opacity:'0.4',
  250. right:'0',
  251. top:'1px',
  252. zIndex:'15',
  253. width:'14px',
  254. background:'#f1f1f1'};
  255. const barStyle={background:'#777',width:'100%'};
  256. return <ScrollArea speed={0.8}
  257. horizontal={false}
  258. stopScrollPropagation={list.length>6?true:false}
  259. style={{height:'225px'}}
  260. className={styles["area"]}
  261. verticalContainerStyle={contStyle}
  262. verticalScrollbarStyle={barStyle}
  263. contentClassName="content">
  264. <ul className={styles.searchLiUl}>
  265. {
  266. list && list.map((item, idx) => {
  267. return <li key={idx}
  268. className={styles.searchLi}
  269. title={(item.name == item.retrievalName || !item.retrievalName) ? item.name : item.name + '(' + item.retrievalName + ')'}
  270. onClick={() => {
  271. handleSign(item.questionId, idx, 'search');
  272. this.setState({ show: false })
  273. }}
  274. >
  275. {item.name}{(item.name == item.retrievalName || !item.retrievalName) ? null : '(' + item.retrievalName + ')'}
  276. </li>
  277. })
  278. }
  279. </ul></ScrollArea>;
  280. }
  281. getCommonList() {//常用列表
  282. const { handleSign, inspectList } = this.props;
  283. return <ul className={styles.searchLiUl}>
  284. {
  285. inspectList && inspectList.map((item, idx) => {
  286. return <li key={idx}
  287. className={styles.searchLi}
  288. title={item.name}
  289. onClick={() => {
  290. handleSign(item.questionId, idx, 'common');
  291. this.setState({ show: false })
  292. }}
  293. >
  294. {item.name}
  295. </li>
  296. })
  297. }
  298. </ul>
  299. }
  300. showDetails(val) {
  301. let min = val.minValue, max = val.maxValue, value = val.value, dom = '';
  302. if (!isNaN(min) && !isNaN(max)) {//有最大值最小值
  303. if (isNaN(value)) {//输入的不是数据
  304. dom = getStatusImg(1, value, 1)
  305. } else if (value <= min) {//下降
  306. dom = getStatusImg(3, value, 1)
  307. } else if (value >= max) {//上升
  308. dom = getStatusImg(2, value, 1)
  309. } else {//正常
  310. dom = getStatusImg(0, value, 1)
  311. }
  312. } else if (isNaN(min) && !isNaN(max)) {//有最大值无最小值
  313. if (value >= max) {//上升
  314. dom = getStatusImg(2, value, 1)
  315. } else {//正常
  316. dom = getStatusImg(0, value, 1)
  317. }
  318. } else if (!isNaN(min) && isNaN(max)) {//有最小值无最大值
  319. if (value <= min) {//下降
  320. dom = getStatusImg(3, value, 1)
  321. } else {//正常
  322. dom = getStatusImg(0, value, 1)
  323. }
  324. } else {//无最大最小值
  325. dom = getStatusImg(1, value, 1)
  326. }
  327. if (val.questionDetailList.length > 0) {
  328. return val.questionDetailList.map((item) => {
  329. if (val.value == item.name) {
  330. return <td style={{ width: '20%' }} className={item.abnormal != '0' ? "red" : ''}>{val.value}</td>
  331. }
  332. })
  333. } else {
  334. // return <td style={{ width: '20%' }}><span className={(val.value - 0).toString() == 'NaN' ? "red" : (val.maxValue || val.minValue) ? (val.value > val.maxValue || val.value < val.minValue ? "red" : '') : ''}>{val.value}</span> {val.labelSuffix}</td>
  335. return <td style={{ width: '20%' }}>{dom} {val.labelSuffix}</td>
  336. }
  337. }
  338. render() {
  339. const {setHighter,refreshScroller, getInfomation, handleChangeValue,inspectList, inspectVal, list, labelList, windowHeight, windowWidth,delPartItem, handleLabelSub, handleClear, handleConfirm, fillActive, getExcelDataList, handleCloseExcel, handlePush } = this.props;
  340. const { tmpId, tmpIdx, id, pageTop, impId } = this.state;
  341. const contStyle={
  342. opacity:'0.4',
  343. right:'0',
  344. top:'1px',
  345. zIndex:'15',
  346. width:'14px',
  347. background:'#f1f1f1'};
  348. const barStyle={background:'#777',width:'100%'};
  349. return (
  350. <div className={styles.wrapper}>
  351. <div className={styles.check}>
  352. {
  353. getExcelDataList.length > 0 && getExcelDataList.map((items, ind) => {
  354. return <div style={{ marginTop: '10px' }}>
  355. {
  356. items && items.lisExcelRes.length > 0 ? <ul className={styles.excelDataLists}>
  357. {/*<img className={styles.close} src={close} alt="关闭导入excel数据" onClick={() => { this.handleDelClick(2, id) }} />*/}
  358. <span className={styles.close} id="impClose" onClick={() => { this.handleDelClick(2, ind) }}></span>
  359. <DelToast show={impId == ind ? true : false}
  360. top={'22px'}
  361. right={'-34px'}
  362. name="该导入项"
  363. cancel={this.handleCancel}
  364. confirm={this.delConfirm} />
  365. {
  366. items.lisExcelRes.map((item, idx) => {
  367. return <SlideExcel
  368. items={items}
  369. item={item}
  370. idx={idx}
  371. dateTime={this.state.dateTime}
  372. getInfomation={getInfomation}
  373. ></SlideExcel>
  374. })
  375. }
  376. </ul> : null
  377. }
  378. </div>
  379. })
  380. }
  381. <ul className={styles.labelWrap} >
  382. {
  383. labelList && labelList.map((item, idx) => {
  384. return <SlideSelect
  385. item={item}
  386. idx={idx}
  387. listDom={this.$ul}
  388. windowWidth={windowWidth}
  389. refreshScroller={refreshScroller}
  390. showToast={idx == id ? true : false}
  391. showFill={this.state.showFill}
  392. handlePush={handlePush}
  393. fillActive={fillActive}
  394. handleLabelSub={handleLabelSub}
  395. date={this.state.date}
  396. dateTime={this.state.dateTime}
  397. currentIdx={this.state.currentIdx}
  398. currentData={this.state.currentData}
  399. showDetails={this.showDetails}
  400. handleShowDate={this.handleShowDate}
  401. handleChangeDate={this.handleChangeDate}
  402. changeShowFill={this.changeShowFill}
  403. handleFillShow={this.handleFillShow}
  404. getItemList={this.getItemList}
  405. changeActivePart={this.changeActivePart}
  406. handleDelClick={this.handleDelClick}
  407. handleDelConfirm={this.delConfirm}
  408. handleConfirm={handleConfirm}
  409. getInfomation={getInfomation}
  410. setHighter={setHighter}
  411. ></SlideSelect>
  412. })
  413. }
  414. </ul>
  415. </div>
  416. <div style={{ position: "relative", clear: "both", top: "5px" }}>
  417. <Add showText="添加化验项" handleClick={(e) => this.handleSearchShow(e)} id="searchWrap" />
  418. {this.state.show ? <SearchOption windowHeight={windowHeight} height={280} refreshScroller={refreshScroller} pageTop={pageTop} handleChangeValue={handleChangeValue} visible={true}>
  419. {list && list.length > 0 ? this.getSearchList(list) : (inspectVal == '' ? '' : <p style={{ padding: '5px 30px', color: '#bfbfbf' }}>暂无筛选项</p>)}
  420. {
  421. (list && list.length > 0) || (inspectVal != '') || (inspectList&&inspectList.length==0) ? '' : <div>
  422. <p style={{ padding: '5px 30px', color: '#bfbfbf' }}>常用化验项</p>
  423. <ScrollArea speed={0.8}
  424. horizontal={false}
  425. stopScrollPropagation={true}
  426. style={{height:'225px'}}
  427. className={styles["area"]}
  428. verticalContainerStyle={contStyle}
  429. verticalScrollbarStyle={barStyle}
  430. contentClassName="content">
  431. {
  432. this.getCommonList()
  433. }
  434. </ScrollArea>
  435. </div>
  436. }
  437. </SearchOption> : ''}
  438. </div>
  439. </div>
  440. )
  441. }
  442. }
  443. export default Inspect;