index.jsx 2.5 KB

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