index.jsx 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  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,getCalendarDate} 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 = getCalendarDate(info);
  128. this.setState({ dateTime: date, date: false })
  129. }
  130. handleSearchShow(e) {
  131. let tmpShow = this.state.show;
  132. this.setState({ show: !tmpShow, pageTop: getPageCoordinate(e).boxTop })
  133. // e.stopPropagation();
  134. if(tmpShow){
  135. this.props.setHighter(48)
  136. }else{
  137. setPosition(e,"#searchOption",this.props.setHighter)
  138. }
  139. }
  140. handleFillShow(e, idx) {
  141. let tmpShow = this.state.showFill;
  142. let baseList = store.getState().inspect.fillActive;
  143. this.setState({
  144. showFill: !tmpShow,
  145. currentIdx: idx,
  146. currentData: baseList,
  147. dateTime: baseList.time ? baseList.time : getCurrentDate(1)
  148. })
  149. // e.stopPropagation();
  150. }
  151. handleShowDate() {
  152. this.setState({
  153. date: !this.state.date
  154. })
  155. }
  156. changeActivePart(idx, val, clear) {
  157. let nums = this.state.num;
  158. let fillActive;
  159. if (nums == 0) {
  160. fillActive = this.props.fillActive;
  161. } else {
  162. fillActive = this.state.currentData;
  163. }
  164. ++nums;
  165. this.setState({ num: nums });
  166. let tempArr = deepClone(fillActive);
  167. if (clear) { //点击清空按钮,至清初输入的数字
  168. for (let i = 0; i < tempArr.details.length; i++) {
  169. tempArr.details[i].value = ''
  170. tempArr.show = false;
  171. }
  172. tempArr.time = getCurrentDate(1);
  173. this.setState({ currentData: tempArr })
  174. return;
  175. } else {
  176. let tempNumPlus = 0;
  177. for (let i = 0; i < tempArr.details.length; i++) {
  178. if (i == idx) {
  179. tempArr.details[i].value = val
  180. }
  181. if (tempArr.details[i].value != undefined && tempArr.details[i].value != '') {
  182. tempArr.show = true;
  183. } else {
  184. ++tempNumPlus;
  185. if (tempNumPlus == tempArr.details.length) {
  186. tempArr.show = false;
  187. }
  188. }
  189. }
  190. tempArr.time = this.state.dateTime;
  191. this.setState({ currentData: tempArr })
  192. }
  193. }
  194. getItemList() { //填写单展示
  195. let number = this.state.num;
  196. let fillActive;
  197. if (number == 0) {
  198. fillActive = this.props.fillActive;
  199. } else {
  200. fillActive = this.state.currentData;
  201. }
  202. return <ul className={styles.searchLis} ref={this.$ul}>
  203. {
  204. fillActive && fillActive.details && fillActive.details.map((item, idx) => {
  205. if (item.controlType == 1) {
  206. return (
  207. <li className={`${styles.itemPart} ${fillActive.details.length > 1 ? '' : styles.itemPartOne}`}>
  208. <span className={styles.itemPartL}>{item.name}</span>
  209. <span className={styles.itemPartT}>
  210. <select className={styles.itemPartR} onChange={(e) => {
  211. if (e.target.value == '请选择') {
  212. this.changeActivePart(idx, '')
  213. return;
  214. }
  215. this.changeActivePart(idx, e.target.value);
  216. }}
  217. >
  218. <option value="请选择">请选择</option>
  219. {
  220. (item.questionDetailList).map((val) => {
  221. return <option value={val.name}
  222. selected={val.name == item.value ? true : false}
  223. >{val.name}</option>
  224. })
  225. }
  226. </select>
  227. </span>
  228. </li>
  229. )
  230. } else if (item.controlType == 6) {
  231. return (
  232. <li className={`${styles.itemPart} ${fillActive.details.length > 1 ? '' : styles.itemPartOne}`}>
  233. <span className={styles.itemPartL} title={item.name}>{item.name}</span>
  234. <span className={styles.itemPartT}>
  235. <input type="text"
  236. placeholder="(填写)"
  237. value={item.value}
  238. onKeyUp={(e) => { this.changeActivePart(idx, e.target.value.trim()) }}
  239. />
  240. <p className={styles.unit} title={item.labelSuffix}>{item.labelSuffix}</p>
  241. </span>
  242. </li>
  243. )
  244. }
  245. })
  246. }
  247. </ul>
  248. }
  249. getSearchList(list) {//搜索列表
  250. const { handleSign } = this.props;
  251. const contStyle={
  252. opacity:'0.4',
  253. right:'0',
  254. top:'1px',
  255. zIndex:'15',
  256. width:'14px',
  257. background:'#f1f1f1'};
  258. const barStyle={background:'#777',width:'100%'};
  259. return <ScrollArea speed={0.8}
  260. horizontal={false}
  261. stopScrollPropagation={list.length>6?true:false}
  262. style={{height:'225px'}}
  263. className={styles["area"]}
  264. verticalContainerStyle={contStyle}
  265. verticalScrollbarStyle={barStyle}
  266. contentClassName="content">
  267. <ul className={styles.searchLiUl}>
  268. {
  269. list && list.map((item, idx) => {
  270. return <li key={idx}
  271. className={styles.searchLi}
  272. title={(item.name == item.retrievalName || !item.retrievalName) ? item.name : item.name + '(' + item.retrievalName + ')'}
  273. onClick={() => {
  274. this.props.setHighter(48)
  275. handleSign(item.questionId, idx, 'search');
  276. this.setState({ show: false })
  277. }}
  278. >
  279. {item.name}{(item.name == item.retrievalName || !item.retrievalName) ? null : '(' + item.retrievalName + ')'}
  280. </li>
  281. })
  282. }
  283. </ul></ScrollArea>;
  284. }
  285. getCommonList() {//常用列表
  286. const { handleSign, inspectList } = this.props;
  287. return <ul className={styles.searchLiUl}>
  288. {
  289. inspectList && inspectList.map((item, idx) => {
  290. return <li key={idx}
  291. className={styles.searchLi}
  292. title={item.name}
  293. onClick={() => {
  294. this.props.setHighter(48)
  295. handleSign(item.questionId, idx, 'common');
  296. this.setState({ show: false })
  297. }}
  298. >
  299. {item.name}
  300. </li>
  301. })
  302. }
  303. </ul>
  304. }
  305. showDetails(val) {
  306. let min = val.minValue, max = val.maxValue, value = val.value, dom = '';
  307. if (!isNaN(min) && !isNaN(max)) {//有最大值最小值
  308. if (isNaN(value)) {//输入的不是数据
  309. dom = getStatusImg(1, value, 1)
  310. } else if (value <= min) {//下降
  311. dom = getStatusImg(3, value, 1)
  312. } else if (value >= max) {//上升
  313. dom = getStatusImg(2, value, 1)
  314. } else {//正常
  315. dom = getStatusImg(0, value, 1)
  316. }
  317. } else if (isNaN(min) && !isNaN(max)) {//有最大值无最小值
  318. if (value >= max) {//上升
  319. dom = getStatusImg(2, value, 1)
  320. } else {//正常
  321. dom = getStatusImg(0, value, 1)
  322. }
  323. } else if (!isNaN(min) && isNaN(max)) {//有最小值无最大值
  324. if (value <= min) {//下降
  325. dom = getStatusImg(3, value, 1)
  326. } else {//正常
  327. dom = getStatusImg(0, value, 1)
  328. }
  329. } else {//无最大最小值
  330. dom = getStatusImg(1, value, 1)
  331. }
  332. if (val.questionDetailList.length > 0) {
  333. return val.questionDetailList.map((item) => {
  334. if (val.value == item.name) {
  335. return <td style={{ width: '20%' }} className={item.abnormal != '0' ? "red" : ''}>{val.value}</td>
  336. }
  337. })
  338. } else {
  339. // 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>
  340. return <td style={{ width: '20%' }}>{dom} {val.labelSuffix}</td>
  341. }
  342. }
  343. render() {
  344. const {setHighter,refreshScroller, getInfomation, handleChangeValue,inspectList, inspectVal, list, labelList, windowHeight, windowWidth,delPartItem, handleLabelSub, handleClear, handleConfirm, fillActive, getExcelDataList, handleCloseExcel, handlePush } = this.props;
  345. const { tmpId, tmpIdx, id, pageTop, impId } = this.state;
  346. const contStyle={
  347. opacity:'0.4',
  348. right:'0',
  349. top:'1px',
  350. zIndex:'15',
  351. width:'14px',
  352. background:'#f1f1f1'};
  353. const barStyle={background:'#777',width:'100%'};
  354. return (
  355. <div className={styles.wrapper}>
  356. <div className={styles.check}>
  357. {
  358. getExcelDataList.length > 0 && getExcelDataList.map((items, ind) => {
  359. return <div style={{ marginTop: '10px' }}>
  360. {
  361. items && items.lisExcelRes.length > 0 ? <ul className={styles.excelDataLists}>
  362. {/*<img className={styles.close} src={close} alt="关闭导入excel数据" onClick={() => { this.handleDelClick(2, id) }} />*/}
  363. <span className={styles.close} id="impClose" onClick={() => { this.handleDelClick(2, ind) }}></span>
  364. <DelToast show={impId == ind ? true : false}
  365. top={'22px'}
  366. right={'-34px'}
  367. name="该导入项"
  368. cancel={this.handleCancel}
  369. confirm={this.delConfirm} />
  370. {
  371. items.lisExcelRes.map((item, idx) => {
  372. return <SlideExcel
  373. items={items}
  374. item={item}
  375. idx={idx}
  376. dateTime={this.state.dateTime}
  377. getInfomation={getInfomation}
  378. ></SlideExcel>
  379. })
  380. }
  381. </ul> : null
  382. }
  383. </div>
  384. })
  385. }
  386. <ul className={styles.labelWrap} >
  387. {
  388. labelList && labelList.map((item, idx) => {
  389. return <SlideSelect
  390. item={item}
  391. idx={idx}
  392. listDom={this.$ul}
  393. windowWidth={windowWidth}
  394. refreshScroller={refreshScroller}
  395. showToast={idx == id ? true : false}
  396. showFill={this.state.showFill}
  397. handlePush={handlePush}
  398. fillActive={fillActive}
  399. handleLabelSub={handleLabelSub}
  400. date={this.state.date}
  401. dateTime={this.state.dateTime}
  402. currentIdx={this.state.currentIdx}
  403. currentData={this.state.currentData}
  404. showDetails={this.showDetails}
  405. handleShowDate={this.handleShowDate}
  406. handleChangeDate={this.handleChangeDate}
  407. changeShowFill={this.changeShowFill}
  408. handleFillShow={this.handleFillShow}
  409. getItemList={this.getItemList}
  410. changeActivePart={this.changeActivePart}
  411. handleDelClick={this.handleDelClick}
  412. handleDelConfirm={this.delConfirm}
  413. handleConfirm={handleConfirm}
  414. getInfomation={getInfomation}
  415. setHighter={setHighter}
  416. ></SlideSelect>
  417. })
  418. }
  419. </ul>
  420. </div>
  421. <div style={{ position: "relative", clear: "both", top: "5px" }}>
  422. <Add showText="添加化验项" handleClick={(e) => this.handleSearchShow(e)} id="searchWrap" />
  423. {this.state.show ? <SearchOption windowHeight={windowHeight} height={280} refreshScroller={refreshScroller} pageTop={pageTop} handleChangeValue={handleChangeValue} visible={true}>
  424. {list && list.length > 0 ? this.getSearchList(list) : (inspectVal == '' ? '' : <p style={{ padding: '5px 30px', color: '#bfbfbf' }}>暂无筛选项</p>)}
  425. {
  426. (list && list.length > 0) || (inspectVal != '') || (inspectList&&inspectList.length==0) ? '' : <div>
  427. <p style={{ padding: '5px 30px', color: '#bfbfbf' }}>常用化验项</p>
  428. <ScrollArea speed={0.8}
  429. horizontal={false}
  430. stopScrollPropagation={true}
  431. style={{height:'225px'}}
  432. className={styles["area"]}
  433. verticalContainerStyle={contStyle}
  434. verticalScrollbarStyle={barStyle}
  435. contentClassName="content">
  436. {
  437. this.getCommonList()
  438. }
  439. </ScrollArea>
  440. </div>
  441. }
  442. </SearchOption> : ''}
  443. </div>
  444. </div>
  445. )
  446. }
  447. }
  448. export default Inspect;