index.jsx 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  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. <span className={styles.itemPartT}>
  208. <select className={styles.itemPartR} onChange={(e) => {
  209. if (e.target.value == '请选择') {
  210. this.changeActivePart(idx, '')
  211. return;
  212. }
  213. this.changeActivePart(idx, e.target.value);
  214. }}
  215. >
  216. <option value="请选择">请选择</option>
  217. {
  218. (item.questionDetailList).map((val) => {
  219. return <option value={val.name}
  220. selected={val.name == item.value ? true : false}
  221. >{val.name}</option>
  222. })
  223. }
  224. </select>
  225. </span>
  226. </li>
  227. )
  228. } else if (item.controlType == 6) {
  229. return (
  230. <li className={`${styles.itemPart} ${fillActive.details.length > 1 ? '' : styles.itemPartOne}`}>
  231. <span className={styles.itemPartL} title={item.name}>{item.name}</span>
  232. <span className={styles.itemPartT}>
  233. <input type="text"
  234. placeholder="(填写)"
  235. value={item.value}
  236. onKeyUp={(e) => { this.changeActivePart(idx, e.target.value.trim()) }}
  237. />
  238. <p className={styles.unit} title={item.labelSuffix}>{item.labelSuffix}</p>
  239. </span>
  240. </li>
  241. )
  242. }
  243. })
  244. }
  245. </ul>
  246. }
  247. getSearchList(list) {//搜索列表
  248. const { handleSign } = this.props;
  249. return <ul className={styles.searchLiUl}>
  250. {
  251. list && list.map((item, idx) => {
  252. return <li key={idx}
  253. className={styles.searchLi}
  254. title={item.name == item.retrievalName ? item.name : item.name + '(' + item.retrievalName + ')'}
  255. onClick={() => {
  256. handleSign(item.questionId, idx,'search');
  257. this.setState({ show: false })
  258. }}
  259. >
  260. {item.name}{item.name == item.retrievalName ? null : '(' + item.retrievalName + ')'}
  261. </li>
  262. })
  263. }
  264. </ul>
  265. }
  266. getCommonList(){//常用列表
  267. const { handleSign,inspectList } = this.props;
  268. return <ul className={styles.searchLiUl}>
  269. {
  270. inspectList && inspectList.map((item, idx) => {
  271. return <li key={idx}
  272. className={styles.searchLi}
  273. title={item.name}
  274. onClick={() => {
  275. handleSign(item.questionId, idx,'common');
  276. this.setState({ show: false })
  277. }}
  278. >
  279. {item.name}
  280. </li>
  281. })
  282. }
  283. </ul>
  284. }
  285. showDetails(val) {
  286. if (val.questionDetailList.length > 0) {
  287. return val.questionDetailList.map((item) => {
  288. if (val.value == item.name) {
  289. return <td style={{ width: '20%' }} className={item.abnormal != '0' ? "red" : ''}>{val.value}</td>
  290. }
  291. })
  292. } else {
  293. 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>
  294. }
  295. }
  296. render() {
  297. const { getInfomation,handleChangeValue,inspectVal, list, labelList,windowHeight, delPartItem, handleLabelSub, handleClear, handleConfirm, fillActive, getExcelDataList, handleCloseExcel, handlePush } = this.props;
  298. const { tmpId, tmpIdx,id,pageTop,impId} = this.state;
  299. return (
  300. <div className={styles.wrapper}>
  301. <div className={styles.check}>
  302. {
  303. getExcelDataList.length > 0 && getExcelDataList.map((items, ind) => {
  304. return <div style={{ marginTop: '10px' }}>
  305. {
  306. items && items.lisExcelRes.length > 0 ? <ul className={styles.excelDataLists}>
  307. {/*<img className={styles.close} src={close} alt="关闭导入excel数据" onClick={() => { this.handleDelClick(2, id) }} />*/}
  308. <span className={styles.close} id="impClose" onClick={() => { this.handleDelClick(2, ind) }}></span>
  309. <DelToast show={impId==ind?true:false}
  310. name="该导入项"
  311. cancel={this.handleCancel}
  312. confirm={this.delConfirm}/>
  313. {
  314. items.lisExcelRes.map((item, idx) => {
  315. return <SlideExcel
  316. items={items}
  317. item={item}
  318. idx={idx}
  319. dateTime={this.state.dateTime}
  320. getInfomation={getInfomation}
  321. ></SlideExcel>
  322. })
  323. }
  324. </ul> : null
  325. }
  326. </div>
  327. })
  328. }
  329. <ul className={styles.labelWrap} >
  330. {
  331. labelList && labelList.map((item, idx) => {
  332. return <SlideSelect
  333. item={item}
  334. idx={idx}
  335. showToast={idx==id?true:false}
  336. showFill={this.state.showFill}
  337. handlePush={handlePush}
  338. fillActive={fillActive}
  339. handleLabelSub={handleLabelSub}
  340. date={this.state.date}
  341. dateTime={this.state.dateTime}
  342. currentIdx={this.state.currentIdx}
  343. currentData={this.state.currentData}
  344. showDetails={this.showDetails}
  345. handleShowDate={this.handleShowDate}
  346. handleChangeDate={this.handleChangeDate}
  347. changeShowFill={this.changeShowFill}
  348. handleFillShow={this.handleFillShow}
  349. getItemList={this.getItemList}
  350. changeActivePart={this.changeActivePart}
  351. handleDelClick={this.handleDelClick}
  352. handleDelConfirm={this.delConfirm}
  353. handleConfirm={handleConfirm}
  354. getInfomation={getInfomation}
  355. ></SlideSelect>
  356. })
  357. }
  358. </ul>
  359. </div>
  360. <div style={{ position: "relative", clear: "both" }}>
  361. <Add showText="添加化验项" handleClick={(e) => this.handleSearchShow(e)} id="searchWrap" />
  362. {this.state.show ? <SearchOption windowHeight={windowHeight} height={280} pageTop={pageTop} handleChangeValue={handleChangeValue} visible={true}>
  363. {list && list.length>0?this.getSearchList(list):(inspectVal == ''?'':<p style={{padding:'5px 30px',color:'#bfbfbf'}}>暂无筛选项</p>)}
  364. {
  365. list && list.length>0 || (inspectVal != '')?'':<div>
  366. <p style={{padding:'5px 30px',color:'#bfbfbf'}}>常用化验项</p>
  367. {
  368. this.getCommonList()
  369. }
  370. </div>
  371. }
  372. </SearchOption> : ''}
  373. </div>
  374. </div>
  375. )
  376. }
  377. }
  378. export default Inspect;