index.jsx 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import React, { Component } from "react";
  2. import styles from "./index.less";
  3. import { normalVal, timestampToTime, getStatusImg,setFontColorSize } from '@utils/tools';
  4. class InspectName extends Component {
  5. constructor(props) {
  6. super(props);
  7. this.state = {
  8. isEdit: false,
  9. value:''
  10. };
  11. this.handleInput = this.handleInput.bind(this)
  12. this.handleBlur = this.handleBlur.bind(this)
  13. this.handleEdit = this.handleEdit.bind(this)
  14. }
  15. componentDidMount(){
  16. const {item} = this.props
  17. this.setState({
  18. value:item.inpValue,
  19. isEdit:item.inpValue?true:false
  20. });
  21. if(this.refs.iptTip){
  22. this.refs.iptTip.getDOMNode().value = item.inpValue
  23. }
  24. }
  25. handleEdit(){
  26. this.setState({
  27. isEdit:true
  28. },()=>{
  29. this.refs.iptTip.getDOMNode().focus()
  30. })
  31. }
  32. handleBlur(){
  33. let val = this.state.value
  34. if (val) return
  35. this.setState({
  36. isEdit:false
  37. })
  38. }
  39. handleInput(e){
  40. const {setTipValue,idx} = this.props
  41. this.setState({
  42. value:e.target.value
  43. })
  44. this.props.setTipValue(idx,e.target.value)
  45. }
  46. render(){
  47. const {item,getInfomation,idx,handleLabelSub} = this.props
  48. return item.show ? <p className={styles.staticTagActive}>
  49. <span className={`${styles.tagSpan} ${styles.selectTagSpan} ${setFontColorSize(2,6)}`} data-flg="current" onClick={(e)=>handleLabelSub(e,item.questionId,idx)}>
  50. {item.name}
  51. <span className={styles.imgInfo1} title='点击i图标可查看详细说明' onClick={()=>getInfomation({name:item.uniqueName || '', position: 1, type: 12})}></span>
  52. </span>
  53. {
  54. item.inpValue||this.state.isEdit?<div title={this.state.value} className={styles.iptTipWrap} onClick={this.handleEdit}>
  55. <input
  56. ref="iptTip"
  57. onBlur={this.handleBlur}
  58. onInput={this.handleInput}
  59. className={styles.iptValue}
  60. type="text"/>
  61. <span></span>
  62. </div>:<span className={styles.iptValueBtn} onClick={this.handleEdit}>点击备注</span>
  63. }
  64. </p>:
  65. <p >
  66. <i className={`${styles.tagSpan} ${styles.tagSpanS} ${setFontColorSize(2)}`} data-flg="current" onClick={(e)=>handleLabelSub(e,item.questionId,idx)}>
  67. {item.name}
  68. <span className={styles.imgInfo} title='点击i图标可查看详细说明' onClick={()=>getInfomation({name:item.uniqueName || '', position: 1, type: 12})}></span>
  69. </i>
  70. </p>
  71. }
  72. }
  73. export default InspectName;