index.jsx 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import React, {Component} from 'react';
  2. import style from './index.less'
  3. import showImg from "@common/images/show.png";
  4. import hideImg from "@common/images/close.png";
  5. class RecommendInspect extends Component {
  6. constructor(props) {
  7. super(props)
  8. this.state = {
  9. showAll: false,
  10. }
  11. this.renderItem = this.renderItem.bind(this)
  12. }
  13. changeShowFlag() {
  14. this.setState({
  15. showAll: !this.state.showAll
  16. })
  17. }
  18. renderItem(item) {
  19. const { changeFlag } = this.props
  20. return <span>
  21. <input
  22. id={item.id + item.name}
  23. onChange={changeFlag(item)}
  24. type="checkbox"
  25. checked={item.checked}
  26. />
  27. <label for={item.id + item.name}>{item.name}</label>
  28. </span>
  29. }
  30. listHide() {
  31. console.log('5555')
  32. const { list } = this.props
  33. let firstLineNum = 0; //第一行字数
  34. let secondLineNum = 0; //第二行字数
  35. return list.map((item, index) => {
  36. console.log('44444444',firstLineNum,index)
  37. // firstLineNum = firstLineNum + item.name.length + 2;
  38. // if (firstLineNum > 26) {
  39. // secondLineNum = secondLineNum + item.name.length + 2;
  40. // if(secondLineNum > 20) {
  41. // return;
  42. // } else {
  43. // return this.renderItem(item)
  44. // }
  45. // } else {
  46. // return this.renderItem(item)
  47. // }
  48. });
  49. }
  50. render() {
  51. const { title,list, changeFlag } = this.props
  52. const { showAll } = this.state
  53. // console.log('1111',list)
  54. // const listAll = list.map(item => {
  55. // console.log('22222',item)
  56. // return <span> item</span>
  57. // {/* this.renderItem(item) */}
  58. // });
  59. return (
  60. <ul>
  61. <li className={style["firstLi"]}>
  62. <div className={style["title"]}>{title}:</div>
  63. <div className={style["content"]}>
  64. {list.length === 0
  65. ?<span >无</span>
  66. : showAll
  67. ? this.listHide()
  68. : this.listHide()}
  69. {/* {secondLineNum > 21 ? (
  70. <span
  71. style={{ display: "inline-block" }}
  72. className={style["show"]}
  73. onClick={this.changeShowFlag.bind(this)}
  74. >
  75. {showAll ? '收起' : '更多'}
  76. <img src={showAll ? hideImg : showImg} />
  77. </span>
  78. ) : (
  79. ""
  80. )} */}
  81. </div>
  82. </li>
  83. </ul>
  84. )
  85. }
  86. }
  87. export default RecommendInspect;