index.jsx 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  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 } 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.getCurrentDate = this.getCurrentDate.bind(this)
  34. this.getItemList = this.getItemList.bind(this)
  35. this.getSearchList = this.getSearchList.bind(this)
  36. this.getCommonList = this.getCommonList.bind(this)
  37. this.changeActivePart = this.changeActivePart.bind(this)
  38. this.showDetails = this.showDetails.bind(this)
  39. this.delConfirm = this.delConfirm.bind(this)
  40. this.handleCancel = this.handleCancel.bind(this)
  41. this.handleSearchShow = this.handleSearchShow.bind(this)
  42. this.changeShowFill = this.changeShowFill.bind(this)
  43. this.handleFillShow = this.handleFillShow.bind(this)
  44. this.handleDelClick = this.handleDelClick.bind(this)
  45. }
  46. delConfirm() {//弹窗确定
  47. const { delPartItem, handleCloseExcel, handlePush } = this.props;
  48. const { type, id ,impId} = this.state;
  49. if (type == 1) {
  50. delPartItem(id)
  51. } else if (type == 2) {
  52. handleCloseExcel(impId)
  53. }
  54. this.setState({
  55. type: null,
  56. id: null,
  57. impId: null
  58. })
  59. Notify.success("删除成功");
  60. handlePush && handlePush(); //右侧推送
  61. }
  62. handleDelClick(type, idx) {
  63. if (type == 2){
  64. this.setState({
  65. impId:idx,
  66. type: type,
  67. id:null
  68. })
  69. }else{
  70. this.setState({
  71. type: type,
  72. id: idx,
  73. impId:null
  74. })
  75. }
  76. }
  77. handleCancel() {
  78. this.setState({
  79. type: null,
  80. id: null,
  81. impId: null
  82. })
  83. }
  84. componentDidMount() {
  85. $(document).click((event) => {
  86. let searchWrap = $('#searchWrap')[0]; // 搜索按钮
  87. let searchOption = $('#searchOption')[0]; // 搜索列表
  88. let inspectFill = $('#inspectFill')[0]; // 公共填写单
  89. let _del = $('#delBox')[0]; // 删除弹窗
  90. let _impClose = $('#impClose')[0]; // 导入删除按钮
  91. let _addClose = $('#addClose')[0]; // 添加删除按钮
  92. let _closeTil = $('#delTit')[0]; // 弹窗标题
  93. if (searchOption) {
  94. if (searchOption != event.target && searchWrap != event.target && searchWrap != event.target.parentNode && !$.contains(searchOption, event.target)) { // Mark 1
  95. this.setState({ show: false });
  96. }
  97. }
  98. if (inspectFill) {
  99. if (event.target.getAttribute('data-flg') != 'current' && inspectFill != event.target && !$.contains(inspectFill, event.target)) { // Mark 1
  100. this.setState({ showFill: false, date: false });
  101. }
  102. }
  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. this.getCurrentDate();
  111. }
  112. componentWillReceiveProps(nextProps) {
  113. if (nextProps.fillActive.name != this.props.fillActive.name) {
  114. this.setState({ num: 0 })
  115. }
  116. }
  117. changeShowFill() {
  118. this.setState({ showFill: false })
  119. }
  120. handleChangeDate(info) {
  121. let date = info.year + '-' + (info.month < 10 ? '0' + info.month : info.month) + '-' + (info.day < 10 ? '0' + info.day : info.day);
  122. this.setState({ dateTime: date, date: false })
  123. }
  124. handleSearchShow(e) {
  125. let tmpShow = this.state.show;
  126. this.setState({ show: !tmpShow,pageTop:getPageCoordinate(e).boxTop })
  127. // e.stopPropagation();
  128. }
  129. handleFillShow(e, idx) {
  130. let tmpShow = this.state.showFill;
  131. let baseList = store.getState().inspect.fillActive;
  132. this.setState({
  133. showFill: !tmpShow,
  134. currentIdx: idx,
  135. currentData: baseList,
  136. dateTime: baseList.time ? baseList.time : this.getCurrentDate()
  137. })
  138. e.stopPropagation();
  139. }
  140. handleShowDate() {
  141. this.setState({
  142. date: !this.state.date
  143. })
  144. }
  145. getCurrentDate() {
  146. let myDate = new Date();
  147. let year = myDate.getFullYear(); //获取完整的年份(4位,1970-????)
  148. let mon = myDate.getMonth() - 0 + 1; //获取当前月份(0-11,0代表1月)
  149. let day = myDate.getDate(); //获取当前日(1-31)
  150. let date = year + '-' + (mon < 10 ? '0' + mon : mon) + '-' + (day < 10 ? '0' + day : day);
  151. this.setState({ dateTime: date })
  152. return date;
  153. }
  154. changeActivePart(idx, val, clear) {
  155. let nums = this.state.num;
  156. let fillActive;
  157. if (nums == 0) {
  158. fillActive = this.props.fillActive;
  159. } else {
  160. fillActive = this.state.currentData;
  161. }
  162. ++nums;
  163. this.setState({ num: nums });
  164. let tempArr = deepClone(fillActive);
  165. if (clear) { //点击清空按钮,至清初输入的数字
  166. for (let i = 0; i < tempArr.details.length; i++) {
  167. tempArr.details[i].value = ''
  168. tempArr.show = false;
  169. }
  170. tempArr.time = this.getCurrentDate();
  171. this.setState({ currentData: tempArr })
  172. return;
  173. } else {
  174. let tempNumPlus = 0;
  175. for (let i = 0; i < tempArr.details.length; i++) {
  176. if (i == idx) {
  177. tempArr.details[i].value = val
  178. }
  179. if (tempArr.details[i].value != undefined && tempArr.details[i].value != '') {
  180. tempArr.show = true;
  181. } else {
  182. ++tempNumPlus;
  183. if (tempNumPlus == tempArr.details.length) {
  184. tempArr.show = false;
  185. }
  186. }
  187. }
  188. tempArr.time = this.state.dateTime;
  189. this.setState({ currentData: tempArr })
  190. }
  191. }
  192. getItemList() { //填写单展示
  193. let number = this.state.num;
  194. let fillActive;
  195. if (number == 0) {
  196. fillActive = this.props.fillActive;
  197. } else {
  198. fillActive = this.state.currentData;
  199. }
  200. return <ul className={styles.searchLis}>
  201. {
  202. fillActive && fillActive.details && fillActive.details.map((item, idx) => {
  203. if (item.controlType == 1) {
  204. return (
  205. <li className={`${styles.itemPart} ${fillActive.details.length > 1 ? '' : styles.itemPartOne}`}>
  206. <span className={styles.itemPartL}>{item.name}</span>
  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. </li>
  225. )
  226. } else if (item.controlType == 6) {
  227. return (
  228. <li className={`${styles.itemPart} ${fillActive.details.length > 1 ? '' : styles.itemPartOne}`}>
  229. <span className={styles.itemPartL} title={item.name}>{item.name}</span>
  230. <span className={styles.itemPartT}>
  231. <input type="text"
  232. placeholder="(填写)"
  233. value={item.value}
  234. onKeyUp={(e) => { this.changeActivePart(idx, e.target.value.trim()) }}
  235. />
  236. <p className={styles.unit} title={item.labelSuffix}>{item.labelSuffix}</p>
  237. </span>
  238. </li>
  239. )
  240. }
  241. })
  242. }
  243. </ul>
  244. }
  245. getSearchList(list) {//搜索列表
  246. const { handleSign } = this.props;
  247. return <ul className={styles.searchLiUl}>
  248. {
  249. list && list.map((item, idx) => {
  250. return <li key={idx}
  251. className={styles.searchLi}
  252. title={item.name == item.retrievalName ? item.name : item.name + '(' + item.retrievalName + ')'}
  253. onClick={() => {
  254. handleSign(item.questionId, idx,'search');
  255. this.setState({ show: false })
  256. }}
  257. >
  258. {item.name}{item.name == item.retrievalName ? null : '(' + item.retrievalName + ')'}
  259. </li>
  260. })
  261. }
  262. </ul>
  263. }
  264. getCommonList(){//常用列表
  265. const { handleSign,inspectList } = this.props;
  266. return <ul className={styles.searchLiUl}>
  267. {
  268. inspectList && inspectList.map((item, idx) => {
  269. return <li key={idx}
  270. className={styles.searchLi}
  271. title={item.name}
  272. onClick={() => {
  273. handleSign(item.questionId, idx,'common');
  274. this.setState({ show: false })
  275. }}
  276. >
  277. {item.name}
  278. </li>
  279. })
  280. }
  281. </ul>
  282. }
  283. showDetails(val) {
  284. if (val.questionDetailList.length > 0) {
  285. return val.questionDetailList.map((item) => {
  286. if (val.value == item.name) {
  287. return <td style={{ width: '20%' }} className={item.abnormal != '0' ? "red" : ''}>{val.value}</td>
  288. }
  289. })
  290. } else {
  291. 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>
  292. }
  293. }
  294. render() {
  295. const { getInfomation,handleChangeValue,inspectVal, list, labelList,windowHeight, delPartItem, handleLabelSub, handleClear, handleConfirm, fillActive, getExcelDataList, handleCloseExcel, handlePush } = this.props;
  296. const { tmpId, tmpIdx,id,pageTop,impId} = this.state;
  297. return (
  298. <div className={styles.wrapper}>
  299. <div className={styles.check}>
  300. {
  301. getExcelDataList.length > 0 && getExcelDataList.map((items, ind) => {
  302. return <div style={{ marginTop: '10px' }}>
  303. {
  304. items && items.lisExcelRes.length > 0 ? <ul className={styles.excelDataLists}>
  305. {/*<img className={styles.close} src={close} alt="关闭导入excel数据" onClick={() => { this.handleDelClick(2, id) }} />*/}
  306. <span className={styles.close} id="impClose" onClick={() => { this.handleDelClick(2, ind) }}></span>
  307. <DelToast show={impId==ind?true:false}
  308. name="该导入项"
  309. cancel={this.handleCancel}
  310. confirm={this.delConfirm}/>
  311. {
  312. items.lisExcelRes.map((item, idx) => {
  313. return <SlideExcel
  314. items={items}
  315. item={item}
  316. idx={idx}
  317. dateTime={this.state.dateTime}
  318. getInfomation={getInfomation}
  319. ></SlideExcel>
  320. })
  321. }
  322. </ul> : null
  323. }
  324. </div>
  325. })
  326. }
  327. <ul className={styles.labelWrap} >
  328. {
  329. labelList && labelList.map((item, idx) => {
  330. return <SlideSelect
  331. item={item}
  332. idx={idx}
  333. showToast={idx==id?true:false}
  334. showFill={this.state.showFill}
  335. handlePush={handlePush}
  336. fillActive={fillActive}
  337. handleLabelSub={handleLabelSub}
  338. date={this.state.date}
  339. dateTime={this.state.dateTime}
  340. currentIdx={this.state.currentIdx}
  341. currentData={this.state.currentData}
  342. showDetails={this.showDetails}
  343. handleShowDate={this.handleShowDate}
  344. handleChangeDate={this.handleChangeDate}
  345. changeShowFill={this.changeShowFill}
  346. handleFillShow={this.handleFillShow}
  347. getItemList={this.getItemList}
  348. changeActivePart={this.changeActivePart}
  349. handleDelClick={this.handleDelClick}
  350. handleDelConfirm={this.delConfirm}
  351. handleConfirm={handleConfirm}
  352. getInfomation={getInfomation}
  353. ></SlideSelect>
  354. })
  355. }
  356. </ul>
  357. </div>
  358. <div style={{ position: "relative", clear: "both" }}>
  359. <Add showText="添加化验项" handleClick={(e) => this.handleSearchShow(e)} id="searchWrap" />
  360. {this.state.show ? <SearchOption windowHeight={windowHeight} height={280} pageTop={pageTop} handleChangeValue={handleChangeValue} visible={true}>
  361. {list && list.length>0?this.getSearchList(list):(inspectVal == ''?'':<p style={{padding:'5px 30px',color:'#bfbfbf'}}>暂无筛选项</p>)}
  362. {
  363. list && list.length>0 || (inspectVal != '')?'':<div>
  364. <p style={{padding:'5px 30px',color:'#bfbfbf'}}>常用化验项</p>
  365. {
  366. this.getCommonList()
  367. }
  368. </div>
  369. }
  370. </SearchOption> : ''}
  371. </div>
  372. </div>
  373. )
  374. }
  375. }
  376. export default Inspect;