index.jsx 15 KB

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