index.jsx 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import Taro, { Component } from '@tarojs/taro'
  2. import { View, Image } from '@tarojs/components'
  3. import ListMore from '@/c/pageDataList/listMore'
  4. import './index.scss'
  5. export default class Comment extends Component {
  6. constructor (props) {
  7. super(props)
  8. this.state = {
  9. newsList: [],
  10. isMoreAllShow: false,
  11. }
  12. }
  13. componentWillMount () {
  14. this.props.onRef(this)
  15. }
  16. getData = (newsList) => {
  17. this.setState({
  18. newsList
  19. })
  20. }
  21. moreHandle () {
  22. let { isMoreAllShow } = this.state
  23. isMoreAllShow = !isMoreAllShow
  24. this.setState({
  25. isMoreAllShow
  26. })
  27. }
  28. render () {
  29. const testImg = 'http://icon.honglounews.com/ex_banner.jpg'
  30. const { newsList, isMoreAllShow } = this.state
  31. const curArr = JSON.parse(JSON.stringify(newsList))
  32. let cArr = isMoreAllShow ? [...curArr] : curArr.slice(0, 3)
  33. const curItems = cArr.map((item, index) => {
  34. const imgUrl = `${item.pri_image ? item.pri_image + '_xs' : testImg}`
  35. return (
  36. <View className="lb-item" key={index}>
  37. <Navigator url={'/pagesMore/news/indexDtl?id=' + item.id} className="lb-img">
  38. <Image className="img" src={imgUrl} />
  39. </Navigator>
  40. <View className="lb-info">
  41. <Navigator url={'/pagesMore/news/indexDtl?id=' + item.id} className="lb-p1">{item.title}</Navigator>
  42. {
  43. item.create_at
  44. &&
  45. <View className="lb-p2">{item.create_at.substring(0, 10)}</View>
  46. }
  47. </View>
  48. </View>
  49. )
  50. })
  51. return (
  52. <View className="l-list-box">
  53. {curItems}
  54. {
  55. newsList.length > 3
  56. ?
  57. isMoreAllShow
  58. ?
  59. <View className="scoped-more t2" onClick={this.moreHandle.bind(this, index)}>收起
  60. <View className="sign"></View>
  61. </View>
  62. :
  63. <View className="scoped-more" onClick={this.moreHandle.bind(this, index)}>展开
  64. <View className="sign"></View>
  65. </View>
  66. : ''
  67. }
  68. {
  69. newsList.length === 0
  70. &&
  71. <ListMore isOther={true} text="观点在路上"/>
  72. }
  73. </View>
  74. )
  75. }
  76. }