import React from 'react'; import { SearchOption, InspectCommon, Calendar ,Notify,ConfirmModal,Add} from '@commonComp'; import { deepClone } from '@utils/tools'; import styles from './index.less'; import date1 from './img/date1.png'; import date2 from './img/date2.png'; import close from './img/close.png'; import store from '@store'; import $ from 'jquery'; class Inspect extends React.Component { constructor(props) { super(props); this.state = { show: false, showFill: false, date: false, currentIdx: '', dateTime:"", currentData:{}, numPlus:0, //判断是否所有的填写单都是空 num:0, //暂存数据,获取一次,不能每次都是新的数据 toastText:'', visible:false, type:null, id:null } this.handleChangeDate = this.handleChangeDate.bind(this) this.handleShowDate = this.handleShowDate.bind(this) this.getCurrentDate = this.getCurrentDate.bind(this) this.getItemList = this.getItemList.bind(this) this.getSearchList = this.getSearchList.bind(this) this.changeActivePart = this.changeActivePart.bind(this) this.normalVal = this.normalVal.bind(this) this.showDetails = this.showDetails.bind(this) this.delConfirm = this.delConfirm.bind(this) this.handleCancel = this.handleCancel.bind(this) this.handleSearchShow = this.handleSearchShow.bind(this) } delConfirm(){//弹窗确定 const{delPartItem,handleCloseExcel,handlePush} = this.props; const{type,id} = this.state; if(type==1){ delPartItem(id) }else if(type==2){ handleCloseExcel(id) } this.setState({ visible:false, type:null, id:null, }) Notify.success("删除成功"); handlePush&&handlePush(); //右侧推送 } handleDelClick(type,idx){ this.setState({ type:type, id:idx, visible:true }) if(type==1){//单项 this.setState({ toastText:'是否删除该化验项?' }) }else if(type==2){//导入项 this.setState({ toastText:'是否删除导入项?' }) } } handleCancel(){ this.setState({ visible:false, type:null, id:null, }) } componentDidMount() { $(document).click((event) => { let searchWrap = $('#searchWrap')[0]; // 搜索按钮 let searchOption = $('#searchOption')[0]; // 搜索列表 let inspectFill = $('#inspectFill')[0]; // 公共填写单 if(searchOption){ if ( searchOption != event.target && searchWrap != event.target && searchWrap != event.target.parentNode && !$.contains(searchOption, event.target)) { // Mark 1 this.setState({ show: false }); } } if(inspectFill){ if ( event.target.getAttribute('data-flg') != 'current' && inspectFill != event.target && !$.contains(inspectFill, event.target)) { // Mark 1 this.setState({ showFill: false }); } } }); this.getCurrentDate(); } componentWillReceiveProps(nextProps){ if(nextProps.fillActive.name != this.props.fillActive.name){ this.setState({num:0}) } } handleChangeDate(info) { let date = info.year+'-'+(info.month<10?'0'+info.month:info.month)+'-'+(info.day<10?'0'+info.day:info.day); this.setState({dateTime:date,date:false}) } handleSearchShow(e) { let tmpShow = this.state.show; this.setState({ show: !tmpShow }) // e.stopPropagation(); } handleFillShow(e,idx) { let tmpShow = this.state.showFill; let baseList = store.getState().inspect.fillActive; this.setState({ showFill: !tmpShow, currentIdx:idx, currentData:baseList, dateTime:baseList.time?baseList.time:this.getCurrentDate() }) e.stopPropagation(); } handleShowDate(){ this.setState({ date:!this.state.date }) } getCurrentDate(){ let myDate = new Date(); let year = myDate.getFullYear(); //获取完整的年份(4位,1970-????) let mon = myDate.getMonth()-0+1; //获取当前月份(0-11,0代表1月) let day = myDate.getDate(); //获取当前日(1-31) let date = year+'-'+(mon<10?'0'+mon:mon)+'-'+(day<10?'0'+day:day); this.setState({dateTime:date}) return date; } changeActivePart(idx,val){ let nums = this.state.num; let fillActive; if(nums == 0){ fillActive = this.props.fillActive; }else{ fillActive = this.state.currentData; } ++nums; this.setState({num:nums}); let tempArr = deepClone(fillActive); let tempNumPlus = 0; for (let i = 0; i < tempArr.details.length; i++) { if (i == idx) { tempArr.details[i].value = val } if(tempArr.details[i].value != undefined && tempArr.details[i].value != ''){ tempArr.show = true; }else{ ++tempNumPlus; if(tempNumPlus == tempArr.details.length){ tempArr.show = false; } } } tempArr.time = this.state.dateTime; this.setState({currentData:tempArr}) } getItemList(){ //填写单展示 let number = this.state.num; let fillActive; if(number == 0){ fillActive = this.props.fillActive; }else{ fillActive = this.state.currentData; } return
{item.labelSuffix}
{value.itemName} | {value.value} {value.unit} | {this.normalVal(value.min,value.max)} | {value.time == ''?('导入时间: '+this.state.dateTime):'化验时间: '+value.time} |
{ handleLabelSub(e, item.questionId,idx); this.handleFillShow(e,idx) }}>{item.name}
:{ handleLabelSub(e,item.questionId,idx); this.handleFillShow(e,idx) }}>{item.name}
} { item.show ?{val.name} | {this.showDetails(val)}{this.normalVal(val.minValue,val.maxValue)} | {'化验时间:'+item.time} |
{ this.state.dateTime }
{toastText}