index.jsx 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. import React from 'react';
  2. import { SearchOption, InspectCommon, Calendar, Notify, ConfirmModal, Add, DelToast } from '@commonComp';
  3. import SlideExcel from './SlideExcel';
  4. import SlidePic from './SlidePic';
  5. import { deepClone, getPageCoordinate, getStatusImg,getDomUpDown ,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. time: 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.handleDelConfirm = this.handleDelConfirm.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. handleDelConfirm() {//弹窗确定
  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. Notify.success("删除成功");
  52. handlePush && handlePush({mode:8}); //右侧推送
  53. }
  54. handleDelClick(type, time) {
  55. if (type == 2) {
  56. this.setState({
  57. impId: idx,
  58. type: type,
  59. id: null
  60. })
  61. } else {
  62. this.setState({
  63. type: type,
  64. time: time,
  65. impId: null
  66. })
  67. }
  68. }
  69. handleCancel() {
  70. this.setState({
  71. type: null,
  72. id: null,
  73. impId: null
  74. })
  75. }
  76. componentDidMount() {
  77. $(document).click((event) => {
  78. let searchWrap = document.getElementById("searchWrap"); // 搜索按钮
  79. let searchOption = document.getElementById("searchOption"); // 搜索列表
  80. let inspectFill = document.getElementById("inspectFill"); // 公共填写单
  81. let _del = $('#delBox')[0]; // 删除弹窗
  82. let _impClose = $('#impClose')[0]; // 导入删除按钮
  83. let _addClose = $('#addClose')[0]; // 添加删除按钮
  84. let _closeTil = $('#delTit')[0]; // 弹窗标题
  85. if (searchOption&&!this.isBar) {//onMousedown的目标为滚动条时,添加弹窗不关闭
  86. if (searchOption != event.target && searchWrap != event.target && searchWrap != event.target.parentNode && !$.contains(searchOption, event.target)) { // Mark 1
  87. if(this.state.show){
  88. this.props.setHighter(48)
  89. }
  90. this.setState({ show: false });
  91. }
  92. }
  93. if (inspectFill&&!this.isBar) {//onMousedown的目标为滚动条时,子项弹窗不关闭
  94. if ($(event.target).attr('id') != "getSureTime"&&event.target.getAttribute('data-flg') != 'current' && inspectFill != event.target && !$.contains(inspectFill, event.target)) { // Mark 1
  95. if(this.state.showFill){
  96. this.props.setHighter(48)
  97. }
  98. this.setState({ showFill: false, date: false });
  99. }
  100. }
  101. if (_del&&!this.isBar) {//onMousedown的目标为滚动条时,删除弹窗不关闭
  102. if (!event.target.isEqualNode(_impClose) && !event.target.isEqualNode(_addClose) && !event.target.isEqualNode(_del) && event.target.parentNode != _del && !event.target.isEqualNode(_closeTil)) {
  103. this.setState({
  104. id: null,
  105. impId: null
  106. })
  107. }
  108. }
  109. });
  110. const that = this;
  111. document.addEventListener('mousedown',function(e){//onMousedown的目标为滚动条时,标签填写单不关闭
  112. if(e.target.className=='scrollbar'){
  113. that.isBar = true;
  114. }else{
  115. that.isBar = false;
  116. }
  117. });
  118. // this.setState({ dateTime: getCurrentDate(1) })
  119. }
  120. componentWillReceiveProps(nextProps) {
  121. if (nextProps.fillActive.name != this.props.fillActive.name) {
  122. this.setState({ num: 0 })
  123. }
  124. }
  125. changeShowFill() {
  126. this.setState({ showFill: false })
  127. this.props.setHighter(48)
  128. }
  129. handleChangeDate(info) {
  130. let date = getCalendarDate(info);
  131. this.setState({ dateTime: date, date: false })
  132. }
  133. handleSearchShow(e) {
  134. let tmpShow = this.state.show;
  135. const { handlePush } = this.props;
  136. this.setState({ show: !tmpShow, pageTop: getPageCoordinate(e).boxTop })
  137. if(tmpShow){
  138. this.props.setHighter(48)
  139. }else{
  140. this.props.detailClick(2)
  141. handlePush && handlePush({mode:8}); //右侧推送
  142. setPosition(e,"#searchOption",this.props.setHighter)
  143. }
  144. }
  145. handleFillShow(e, idx) {
  146. let tmpShow = this.state.showFill;
  147. let baseList = store.getState().inspect.fillActive;
  148. this.setState({
  149. showFill: !tmpShow,
  150. currentIdx: idx,
  151. currentData: baseList,
  152. dateTime: baseList.time ? baseList.time : getCurrentDate(1)
  153. })
  154. // e.stopPropagation();
  155. }
  156. handleShowDate() {
  157. this.setState({
  158. date: !this.state.date
  159. })
  160. }
  161. changeActivePart(idx, val, clear) {
  162. let nums = this.state.num;
  163. let fillActive;
  164. if (nums == 0) {
  165. fillActive = this.props.fillActive;
  166. } else {
  167. fillActive = this.state.currentData;
  168. }
  169. ++nums;
  170. this.setState({ num: nums });
  171. let tempArr = deepClone(fillActive);
  172. if (clear) { //点击清空按钮,至清初输入的数字
  173. for (let i = 0; i < tempArr.details.length; i++) {
  174. tempArr.details[i].value = ''
  175. tempArr.show = false;
  176. }
  177. tempArr.time = getCurrentDate(1);
  178. this.setState({ currentData: tempArr })
  179. return;
  180. } else {
  181. let tempNumPlus = 0;
  182. for (let i = 0; i < tempArr.details.length; i++) {
  183. if (i == idx) {
  184. tempArr.details[i].value = val
  185. }
  186. if (tempArr.details[i].value != undefined && tempArr.details[i].value != '') {
  187. tempArr.show = true;
  188. } else {
  189. ++tempNumPlus;
  190. if (tempNumPlus == tempArr.details.length) {
  191. tempArr.show = false;
  192. }
  193. }
  194. }
  195. tempArr.time = this.state.dateTime;
  196. this.setState({ currentData: tempArr })
  197. }
  198. }
  199. getItemList() { //填写单展示
  200. let number = this.state.num;
  201. let fillActive;
  202. if (number == 0) {
  203. fillActive = this.props.fillActive;
  204. } else {
  205. fillActive = this.state.currentData;
  206. }
  207. return <ul className={styles.searchLis} ref={this.$ul}>
  208. {
  209. fillActive && fillActive.details && fillActive.details.map((item, idx) => {
  210. if (item.controlType == 1) {
  211. return (
  212. <li className={`${styles.itemPart} ${fillActive.details.length > 1 ? '' : styles.itemPartOne}`}>
  213. <span className={styles.itemPartL}>{item.name}</span>
  214. <span className={styles.itemPartT}>
  215. <select className={styles.itemPartR} onChange={(e) => {
  216. if (e.target.value == '请选择') {
  217. this.changeActivePart(idx, '')
  218. return;
  219. }
  220. this.changeActivePart(idx, e.target.value);
  221. }}
  222. >
  223. <option value="请选择">请选择</option>
  224. {
  225. (item.questionDetailList).map((val) => {
  226. return <option value={val.name}
  227. selected={val.name == item.value ? true : false}
  228. >{val.name}</option>
  229. })
  230. }
  231. </select>
  232. </span>
  233. </li>
  234. )
  235. } else if (item.controlType == 6) {
  236. return (
  237. <li className={`${styles.itemPart} ${fillActive.details.length > 1 ? '' : styles.itemPartOne}`}>
  238. <span className={styles.itemPartL} title={item.name}>{item.name}</span>
  239. <span className={styles.itemPartT}>
  240. <input type="text"
  241. placeholder="(填写)"
  242. value={item.value}
  243. onKeyUp={(e) => { this.changeActivePart(idx, e.target.value.trim()) }}
  244. />
  245. <p className={styles.unit} title={item.labelSuffix}>{item.labelSuffix}</p>
  246. </span>
  247. </li>
  248. )
  249. }
  250. })
  251. }
  252. </ul>
  253. }
  254. handleSign(item,idx){
  255. const { handleSign,handlePush } = this.props;
  256. handleSign(item,idx)
  257. handlePush && handlePush({mode:8}); //右侧推送
  258. }
  259. getSearchList(list) {//搜索列表
  260. const contStyle={
  261. opacity:'0.4',
  262. right:'0',
  263. top:'1px',
  264. zIndex:'15',
  265. width:'14px',
  266. background:'#f1f1f1'};
  267. const barStyle={background:'#777',width:'100%'};
  268. return <ul className={`${styles.searchLiUl} ${styles.searchIsp}`} style={{height:'205px',width:'356px',overflow:'auto'}}>
  269. {
  270. list && list.map((item, idx) => {
  271. let renderText = item.uniqueName ? item.uniqueName + `(${item.name})` : item.name // 有大项需要显示大项
  272. return <li key={idx}
  273. className={styles.searchLi}
  274. title={renderText}
  275. onClick={() => {
  276. this.props.setHighter(48)
  277. this.handleSign(item, idx, 'search');
  278. this.setState({ show: false })
  279. }}
  280. >
  281. {renderText}
  282. </li>
  283. })
  284. }
  285. </ul>;
  286. }
  287. getCommonList() {//常用列表
  288. const { handleSign, inspectList } = this.props;
  289. return <ul className={styles.searchLiUl}>
  290. {
  291. inspectList && inspectList.map((item, idx) => {
  292. return <li key={idx}
  293. className={styles.searchLi}
  294. title={item.name}
  295. onClick={() => {
  296. this.props.setHighter(48)
  297. this.handleSign(item.questionId, idx, 'common');
  298. this.setState({ show: false })
  299. }}
  300. >
  301. {item.name}
  302. </li>
  303. })
  304. }
  305. </ul>
  306. }
  307. showDetails(val) {
  308. let min = val.minValue, max = val.maxValue, value = val.value, dom = '';
  309. dom = getDomUpDown(min,max,value)
  310. if (val.questionDetailList.length > 0) {
  311. return val.questionDetailList.map((item) => {
  312. if (val.value == item.name) {
  313. return <td style={{ width: '20%' }} className={item.abnormal != '0' ? "red" : ''}>{val.value}</td>
  314. }
  315. })
  316. } else {
  317. // 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>
  318. return <td style={{ width: '20%' }}>{dom} {val.labelSuffix}</td>
  319. }
  320. }
  321. render() {
  322. const {setHighter,refreshScroller,checkOnOff, getInfomation,setTipValue, handleChangeValue,labelListSmall,inspectList, inspectVal, list, labelListBig, windowHeight, windowWidth,detailClick, handleLabelSub, handleClear, handleConfirm, fillActive, getExcelDataList, handleCloseExcel, handlePush,handleDelConfirm } = this.props;
  323. const { tmpId, tmpIdx, time, pageTop, impId } = this.state;
  324. const contStyle={
  325. opacity:'0.4',
  326. right:'0',
  327. top:'1px',
  328. zIndex:'15',
  329. width:'14px',
  330. background:'#f1f1f1'};
  331. const barStyle={background:'#777',width:'100%'};
  332. return (
  333. <div className={styles.wrapper}>
  334. <div className={styles.check}>
  335. <ul className={styles.labelWrap} >
  336. {
  337. labelListSmall && labelListSmall.map((item, idx) => {
  338. return <SlidePic
  339. item={item}
  340. checkOnOff={checkOnOff}
  341. idx={idx}
  342. time={time}
  343. handlePush={handlePush}
  344. handleDelClick={this.handleDelClick}
  345. setTipValue={setTipValue}
  346. handleDelConfirm={handleDelConfirm}
  347. ></SlidePic>
  348. })
  349. }
  350. {
  351. labelListBig && labelListBig.map((item, idx) => {
  352. return <SlidePic
  353. item={item}
  354. checkOnOff={checkOnOff}
  355. idx={idx}
  356. time={time}
  357. handlePush={handlePush}
  358. handleDelClick={this.handleDelClick}
  359. setTipValue={setTipValue}
  360. handleDelConfirm={handleDelConfirm}
  361. ></SlidePic>
  362. })
  363. }
  364. </ul>
  365. </div>
  366. <div style={{ position: "relative", clear: "both", top: "5px" }}>
  367. <Add showText="添加检验项" handleClick={(e) => this.handleSearchShow(e)} id="searchWrap" />
  368. {this.state.show ? <SearchOption searchType="1" detailClick={detailClick} windowHeight={windowHeight} height={280} refreshScroller={refreshScroller} pageTop={pageTop} handleChangeValue={handleChangeValue} visible={true}>
  369. {list && list.length > 0 ? this.getSearchList(list) : (inspectVal == '' ? '' : <p style={{ padding: '5px 136px', color: '#bfbfbf' }}>暂无筛选项</p>)}
  370. {/* {
  371. (list && list.length > 0) || (inspectVal != '') || (inspectList&&inspectList.length==0) ? '' : <div>
  372. <p style={{ padding: '5px 30px', color: '#bfbfbf' }}>常用检验项</p>
  373. <ScrollArea speed={0.8}
  374. horizontal={false}
  375. stopScrollPropagation={true}
  376. style={{height:'225px'}}
  377. className={styles["area"]}
  378. verticalContainerStyle={contStyle}
  379. verticalScrollbarStyle={barStyle}
  380. contentClassName="content">
  381. {
  382. this.getCommonList()
  383. }
  384. </ScrollArea>
  385. </div>
  386. } */}
  387. </SearchOption> : ''}
  388. </div>
  389. </div>
  390. )
  391. }
  392. }
  393. export default Inspect;