index.jsx 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  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(0)
  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(0)
  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(0)
  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. return <ul className={styles.searchLiUl}>
  249. {
  250. list && list.map((item, idx) => {
  251. return <li key={idx}
  252. className={styles.searchLi}
  253. title={(item.name == item.retrievalName || !item.retrievalName) ? item.name : item.name + '(' + item.retrievalName + ')'}
  254. onClick={() => {
  255. handleSign(item.questionId, idx, 'search');
  256. this.setState({ show: false })
  257. }}
  258. >
  259. {item.name}{(item.name == item.retrievalName || !item.retrievalName) ? null : '(' + item.retrievalName + ')'}
  260. </li>
  261. })
  262. }
  263. </ul>
  264. }
  265. getCommonList() {//常用列表
  266. const { handleSign, inspectList } = this.props;
  267. return <ul className={styles.searchLiUl}>
  268. {
  269. inspectList && inspectList.map((item, idx) => {
  270. return <li key={idx}
  271. className={styles.searchLi}
  272. title={item.name}
  273. onClick={() => {
  274. handleSign(item.questionId, idx, 'common');
  275. this.setState({ show: false })
  276. }}
  277. >
  278. {item.name}
  279. </li>
  280. })
  281. }
  282. </ul>
  283. }
  284. showDetails(val) {
  285. let min = val.minValue, max = val.maxValue, value = val.value, dom = '';
  286. if (!isNaN(min) && !isNaN(max)) {//有最大值最小值
  287. if (isNaN(value)) {//输入的不是数据
  288. dom = getStatusImg(1, value, 1)
  289. } else if (value <= min) {//下降
  290. dom = getStatusImg(3, value, 1)
  291. } else if (value >= max) {//上升
  292. dom = getStatusImg(2, value, 1)
  293. } else {//正常
  294. dom = getStatusImg(0, value, 1)
  295. }
  296. } else if (isNaN(min) && !isNaN(max)) {//有最大值无最小值
  297. if (value >= max) {//上升
  298. dom = getStatusImg(2, value, 1)
  299. } else {//正常
  300. dom = getStatusImg(0, value, 1)
  301. }
  302. } else if (!isNaN(min) && isNaN(max)) {//有最小值无最大值
  303. if (value <= min) {//下降
  304. dom = getStatusImg(3, value, 1)
  305. } else {//正常
  306. dom = getStatusImg(0, value, 1)
  307. }
  308. } else {//无最大最小值
  309. dom = getStatusImg(1, value, 1)
  310. }
  311. if (val.questionDetailList.length > 0) {
  312. return val.questionDetailList.map((item) => {
  313. if (val.value == item.name) {
  314. return <td style={{ width: '20%' }} className={item.abnormal != '0' ? "red" : ''}>{val.value}</td>
  315. }
  316. })
  317. } else {
  318. // 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>
  319. return <td style={{ width: '20%' }}>{dom} {val.labelSuffix}</td>
  320. }
  321. }
  322. render() {
  323. const {setHighter,refreshScroller, getInfomation, handleChangeValue,inspectList, inspectVal, list, labelList, windowHeight, delPartItem, handleLabelSub, handleClear, handleConfirm, fillActive, getExcelDataList, handleCloseExcel, handlePush } = this.props;
  324. const { tmpId, tmpIdx, id, pageTop, impId } = this.state;
  325. const contStyle={
  326. opacity:'0.4',
  327. right:'0',
  328. top:'1px',
  329. zIndex:'15',
  330. width:'14px',
  331. background:'#f1f1f1'};
  332. const barStyle={background:'#777',width:'100%'};
  333. return (
  334. <div className={styles.wrapper}>
  335. <div className={styles.check}>
  336. {
  337. getExcelDataList.length > 0 && getExcelDataList.map((items, ind) => {
  338. return <div style={{ marginTop: '10px' }}>
  339. {
  340. items && items.lisExcelRes.length > 0 ? <ul className={styles.excelDataLists}>
  341. {/*<img className={styles.close} src={close} alt="关闭导入excel数据" onClick={() => { this.handleDelClick(2, id) }} />*/}
  342. <span className={styles.close} id="impClose" onClick={() => { this.handleDelClick(2, ind) }}></span>
  343. <DelToast show={impId == ind ? true : false}
  344. top={'22px'}
  345. right={'-34px'}
  346. name="该导入项"
  347. cancel={this.handleCancel}
  348. confirm={this.delConfirm} />
  349. {
  350. items.lisExcelRes.map((item, idx) => {
  351. return <SlideExcel
  352. items={items}
  353. item={item}
  354. idx={idx}
  355. dateTime={this.state.dateTime}
  356. getInfomation={getInfomation}
  357. ></SlideExcel>
  358. })
  359. }
  360. </ul> : null
  361. }
  362. </div>
  363. })
  364. }
  365. <ul className={styles.labelWrap} >
  366. {
  367. labelList && labelList.map((item, idx) => {
  368. return <SlideSelect
  369. item={item}
  370. idx={idx}
  371. listDom={this.$ul}
  372. windowHeight={windowHeight}
  373. showToast={idx == id ? true : false}
  374. showFill={this.state.showFill}
  375. handlePush={handlePush}
  376. fillActive={fillActive}
  377. handleLabelSub={handleLabelSub}
  378. date={this.state.date}
  379. dateTime={this.state.dateTime}
  380. currentIdx={this.state.currentIdx}
  381. currentData={this.state.currentData}
  382. showDetails={this.showDetails}
  383. handleShowDate={this.handleShowDate}
  384. handleChangeDate={this.handleChangeDate}
  385. changeShowFill={this.changeShowFill}
  386. handleFillShow={this.handleFillShow}
  387. getItemList={this.getItemList}
  388. changeActivePart={this.changeActivePart}
  389. handleDelClick={this.handleDelClick}
  390. handleDelConfirm={this.delConfirm}
  391. handleConfirm={handleConfirm}
  392. getInfomation={getInfomation}
  393. setHighter={setHighter}
  394. ></SlideSelect>
  395. })
  396. }
  397. </ul>
  398. </div>
  399. <div style={{ position: "relative", clear: "both", top: "5px" }}>
  400. <Add showText="添加化验项" handleClick={(e) => this.handleSearchShow(e)} id="searchWrap" />
  401. {this.state.show ? <SearchOption windowHeight={windowHeight} height={280} refreshScroller={refreshScroller} pageTop={pageTop} handleChangeValue={handleChangeValue} visible={true}>
  402. {list && list.length > 0 ? this.getSearchList(list) : (inspectVal == '' ? '' : <p style={{ padding: '5px 30px', color: '#bfbfbf' }}>暂无筛选项</p>)}
  403. {
  404. (list && list.length > 0) || (inspectVal != '') || (inspectList&&inspectList.length==0) ? '' : <div>
  405. <p style={{ padding: '5px 30px', color: '#bfbfbf' }}>常用化验项</p>
  406. <ScrollArea speed={0.8}
  407. horizontal={false}
  408. stopScrollPropagation={true}
  409. style={{height:'225px'}}
  410. className={styles["area"]}
  411. verticalContainerStyle={contStyle}
  412. verticalScrollbarStyle={barStyle}
  413. contentClassName="content">
  414. {
  415. this.getCommonList()
  416. }
  417. </ScrollArea>
  418. </div>
  419. }
  420. </SearchOption> : ''}
  421. </div>
  422. </div>
  423. )
  424. }
  425. }
  426. export default Inspect;