index.jsx 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. import React, { Component } from "react";
  2. import styles from "./index.less";
  3. import { normalVal,getArrow,timestampToTime,getDomUpDown,getPageCoordinate,setPosition,setFontColorSize } from '@utils/tools';
  4. import { InspectCommon, Notify,DelToast} from '@commonComp';
  5. import slideUp from "@common/images/slide-up.png";
  6. import slideDown from "@common/images/slide-down.png";
  7. import checkOff from '@common/images/check_off.png';
  8. import checkOn from '@common/images/check_on.png';
  9. import $ from 'jquery';
  10. import date1 from '../img/date1.png';
  11. import ScrollArea from 'react-scrollbar';
  12. import InspectName from '../InspectName';
  13. import up from '@images/up.png';
  14. import down from '@images/down.png';
  15. class SlideSelect extends Component {
  16. constructor(props) {
  17. super(props);
  18. this.state = {
  19. show:false,
  20. activeInd:false,
  21. activeName:'',
  22. canEdit:true,
  23. style:'',
  24. };
  25. this.toTime = this.toTime.bind(this);
  26. this.handleSlide = this.handleSlide.bind(this);
  27. this.handleDel = this.handleDel.bind(this);
  28. this.handleCancel = this.handleCancel.bind(this);
  29. this.delConfirm = this.delConfirm.bind(this);
  30. this.timeSure = this.timeSure.bind(this);
  31. this.setEdit = this.setEdit.bind(this);
  32. this.handleLabelSub = this.handleLabelSub.bind(this);
  33. this.handleBlur = this.handleBlur.bind(this);
  34. this.checkOnOff = this.checkOnOff.bind(this);
  35. }
  36. handleChangeDate(date) {
  37. // console.log(date,'外')
  38. }
  39. componentDidMount() {
  40. const {item} = this.props;
  41. $(document).click((event) => {
  42. if($(event.target).attr("id")!='addClose'&&$(event.target).attr("id")!='delTit'){
  43. this.setState({
  44. activeInd:false
  45. })
  46. }
  47. });
  48. let type = getArrow(item.minValue,item.maxValue,item.value||null)
  49. this.setState({style:type,value:item.value,time:item.time})
  50. const that = this;
  51. document.addEventListener('mousedown',function(e){
  52. //onMousedown的目标为滚动条时,标签填写单不关闭
  53. if(e.target.className=='scrollbar'){
  54. that.isBar = true;
  55. }else{
  56. that.isBar = false;
  57. }
  58. });
  59. // this.setState({ dateTime: getCurrentDate(1) })
  60. }
  61. toTime(time){
  62. let tmpTim = time.split(',').join('')-0
  63. if(time && tmpTim.toString() != 'NaN'){
  64. let date = new Date('1900-01-01');
  65. let dateTim = date.getTime();
  66. let times = (tmpTim-2)*24*60*60*1000;
  67. let result = timestampToTime(dateTim+times).split(' ')[0]
  68. return result;
  69. }else{
  70. return time;
  71. }
  72. }
  73. handleSlide(){
  74. let tmpShow = this.state.show
  75. this.setState({
  76. show:!tmpShow
  77. })
  78. }
  79. handleDel(time){
  80. const {handleDelClick,item} = this.props;
  81. this.setState({
  82. activeInd:true,
  83. activeName:item.uniqueName,
  84. })
  85. handleDelClick&&handleDelClick(1,time);
  86. }
  87. handleCancel(){
  88. this.setState({
  89. activeInd:false,
  90. activeName:''
  91. })
  92. }
  93. delConfirm(item){
  94. const {handleDelConfirm,handlePush} = this.props;
  95. handleDelConfirm&&handleDelConfirm(item);
  96. Notify.success("删除成功");
  97. handlePush && handlePush({mode:8}); //右侧推送
  98. this.setState({
  99. activeInd:false,
  100. activeName:''
  101. })
  102. }
  103. timeSure(date){
  104. const {handleChangeDate} = this.props;
  105. handleChangeDate&&handleChangeDate(date)
  106. }
  107. handleLabelSub(e,questionId,idx){
  108. const {handleLabelSub,handleFillShow,setHighter,refreshScroller} = this.props;
  109. handleLabelSub(e,questionId,idx);
  110. handleFillShow(e,idx);
  111. //弹窗高度超出屏幕,增加页面高度
  112. setPosition(e,"#inspectFill",setHighter);
  113. /*setTimeout(function(){//如果检验下面有很多数据,则会跳过头
  114. refreshScroller()&&refreshScroller().scrollYTo(290);
  115. })*/
  116. }
  117. handleInput(e,item,sign){
  118. const {setTipValue} = this.props
  119. setTipValue(item,e.target.value,sign)
  120. if(sign == 2){
  121. let type = getArrow(item.minValue,item.maxValue,e.target.value||null)
  122. this.setState({
  123. style:type
  124. })
  125. }
  126. }
  127. handleBlur(){
  128. const {handlePush} = this.props;
  129. $('.canEdit').attr('disabled','disabled')
  130. handlePush && handlePush({mode:8}); //右侧推送
  131. }
  132. checkOnOff(item){
  133. const {checkOnOff,handlePush} = this.props
  134. checkOnOff(item)
  135. handlePush && handlePush({mode:8}); //右侧推送
  136. }
  137. setEdit(e){
  138. $('.canEdit').blur().attr('disabled','disabled')
  139. $(e.target).removeAttr('disabled').focus()
  140. }
  141. render() {
  142. const {item,idx,time} = this.props;
  143. const {canEdit,activeInd,activeName,value,style} = this.state;
  144. return (
  145. item.flg == 1?<li key={item.uniqueName+idx} className={`${styles.slideLi} clearfix`}>
  146. <table>
  147. <tr>
  148. <img className={styles.imgCheck} src={item.check?checkOn:checkOff} onClick={()=>this.checkOnOff(item)} alt=""/>
  149. <span className={styles.bigname}>{item.uniqueName}</span>
  150. <span className={styles.smallname}></span>
  151. <span className={styles.edit}></span>
  152. <span className={styles.maxmin}></span>
  153. <span className={styles.pass}>检验时间:
  154. <input disabled="disabled" type="text"
  155. class="canEdit"
  156. onDoubleClick={(e)=>this.setEdit(e)}
  157. style={{color:style==2||style==4?'red':style==1?'#D949FF':'#333'}}
  158. placeholder='(填写)'
  159. autoComplete="off"
  160. value={item.time}
  161. onInput={(e)=>{this.handleInput(e,item,1)}}
  162. onBlur={()=>{this.handleBlur()}}
  163. />
  164. </span>
  165. <span id="addClose" className={styles.partDel} onClick={()=>{this.handleDel(item.time)}}></span>
  166. </tr>
  167. </table>
  168. <DelToast show={time==item.time&&activeInd?true:false}
  169. name={activeName}
  170. right={'-34px'}
  171. top={'30px'}
  172. cancel={this.handleCancel}
  173. confirm={()=>{this.delConfirm(item)}}/>
  174. </li>:<li key={item.uniqueName+idx} className={`${styles.slideLi} clearfix`}>
  175. <span style={{width:'22px'}}></span>
  176. <span className={styles.bigname}>{item.name}</span>
  177. <span className={styles.smallname}>{item.uniqueName}</span>
  178. <span className={styles.edit}>
  179. <input disabled="disabled" type="text"
  180. class="canEdit"
  181. onDoubleClick={(e)=>this.setEdit(e)}
  182. style={{ color: style == 2 || style == 4 ? 'red' : style == 1 ? '#D949FF' : '#333', backgroundColor: item.value && item.value.length>0 ? '#eeeeee' : ''}}
  183. placeholder='(填写)'
  184. autoComplete="off"
  185. value={item.value||item.otherValue}
  186. onInput={(e)=>{this.handleInput(e,item,2)}}
  187. onBlur={()=>{this.handleBlur()}}
  188. /><img style={{display:style==1||style==2?'inline-block':'none'}} src={style==1?down:style==2?up:''} />{item.units}
  189. </span>
  190. <span className={styles.maxmin}>{normalVal(item.minValue,item.maxValue)}</span>
  191. <span className={styles.pass}>检验时间:
  192. <input disabled="disabled" type="text"
  193. class="canEdit"
  194. onDoubleClick={(e)=>this.setEdit(e)}
  195. style={{color:style==2||style==4?'red':style==1?'#D949FF':'#333'}}
  196. placeholder='(填写)'
  197. autoComplete="off"
  198. value={item.time}
  199. onInput={(e)=>{this.handleInput(e,item,1)}}
  200. onBlur={()=>{this.handleBlur()}}
  201. />
  202. </span>
  203. <span id="addClose" className={styles.partDel} onClick={()=>{this.handleDel(item.time)}}></span>
  204. <DelToast show={time==item.time&&activeInd?true:false}
  205. name={activeName}
  206. right={'-34px'}
  207. top={'30px'}
  208. cancel={this.handleCancel}
  209. confirm={()=>{this.delConfirm(item)}}/>
  210. </li>
  211. );
  212. }
  213. }
  214. export default SlideSelect;