index.jsx 13 KB

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