index.jsx 8.5 KB

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