index.jsx 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. linkHandle (item) {
  29. Taro.navigateTo({
  30. url: `/pagesRoom/dtl?id=${item.id}`
  31. })
  32. }
  33. render () {
  34. const testImg = 'http://icon.honglounews.com/ex_banner.jpg'
  35. const { newsList, isMoreAllShow } = this.state
  36. const curArr = JSON.parse(JSON.stringify(newsList))
  37. let cArr = isMoreAllShow ? [...curArr] : curArr.slice(0, 3)
  38. const itemsList = cArr.map((item, index) => {
  39. const cTagStr = item.custom_tag || ''
  40. const tagViews = cTagStr.split(',').map((tag, tagIndex) => {
  41. return (
  42. <View className="s" key={tagIndex}>{tag}</View>
  43. )
  44. })
  45. return (
  46. <View className="lhl-item col-1" key={index} onClick={this.linkHandle.bind(this, item)}>
  47. <View className="lhl-img">
  48. <Image src={item.pri_image + '_xs'} className="img" />
  49. </View>
  50. <View className="lhl-info">
  51. <View className="lhl-p1">{item.title}</View>
  52. <View className="lhl-p2">{item.price}万
  53. <View className="sub">单价:{parseInt(item.price * 10000 / item.area)}元/平</View>
  54. </View>
  55. <View className="lhl-p3">{item.estate_name}</View>
  56. <View className="lhl-sign">
  57. {tagViews}
  58. </View>
  59. </View>
  60. </View>
  61. )
  62. })
  63. return (
  64. <View className="l-house-list">
  65. {itemsList}
  66. {
  67. newsList.length > 3
  68. ?
  69. isMoreAllShow
  70. ?
  71. <View className="scoped-more t2" onClick={this.moreHandle.bind(this, index)}>收起
  72. <View className="sign"></View>
  73. </View>
  74. :
  75. <View className="scoped-more" onClick={this.moreHandle.bind(this, index)}>展开
  76. <View className="sign"></View>
  77. </View>
  78. : ''
  79. }
  80. </View>
  81. )
  82. }
  83. }