index.jsx 14 KB

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