index.jsx 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. curObj: {},
  10. }
  11. }
  12. componentWillMount () {
  13. this.props.onRef(this)
  14. }
  15. getData = (curObj) => {
  16. this.setState({
  17. curObj
  18. })
  19. }
  20. renderCommentBtn () {
  21. const editIcon = require('@img/icon_g_edit.png')
  22. return (
  23. <View className="scoped-comment-btn">
  24. <View className="scb-btn" onClick={this.addCommentHandle.bind(this)}>
  25. <Image className="img" src={editIcon} />
  26. <View className="t">我想说两句</View>
  27. </View>
  28. </View>
  29. )
  30. }
  31. commentMoreHandle (index) {
  32. const { curObj } = this.state
  33. let mList = curObj.comm_list || []
  34. mList.map((item, i) => {
  35. if (index === i) item.isMoreAllShow = !item.isMoreAllShow
  36. })
  37. let newObj = {...curObj}
  38. newObj.comm_list = [...mList]
  39. this.setState({
  40. curObj: newObj
  41. })
  42. }
  43. addCommentHandle () {
  44. const { curObj } = this.state
  45. Taro.navigateTo({
  46. url: `/pagesMore/comment/add?id=${curObj.id}&name=${curObj.estate_name}`
  47. })
  48. }
  49. zanHandle (comment_id, flag) {
  50. let apiStr = flag ? 'estatecommentunzan' : 'estatecommentzan'
  51. Taro.api.house[apiStr]({
  52. comment_id
  53. }).then(res => {
  54. this.props.getDtl()
  55. })
  56. }
  57. render () {
  58. const { curObj } = this.state
  59. const zan1Icon = require('@img/i_g_zan.png')
  60. const zan2Icon = require('@img/i_g_zan2.png')
  61. let commentList = curObj.comm_list || []
  62. const curItems = commentList.map((item, index) => {
  63. const lvIcon = Taro.$getLvIcon(item.integral)
  64. const oldList = item.child && item.child.length ? JSON.parse(JSON.stringify(item.child)) : []
  65. const subList = item.isMoreAllShow ? [...oldList] : oldList.splice(0, 4)
  66. return (
  67. <View className="lcb-item" key={index}>
  68. <View className="lb-img">
  69. <Image className="img" src={item.avatar} />
  70. </View>
  71. <View className="lb-info">
  72. <Navigator url={'/pagesMore/comment/dtl?id=' + item.id + '&estateId=' + curObj.id} >
  73. <View className="lb-p1">{item.nickname}
  74. <Image className="i" src={lvIcon}></Image>
  75. </View>
  76. <View className="lb-time">{item.create_at}</View>
  77. <View className="lb-p2">{item.comm_cont}</View>
  78. </Navigator>
  79. <View className="lb-zan" onClick={this.zanHandle.bind(this, item.id, item.is_zan)}>
  80. {
  81. item.is_zan
  82. ?
  83. <Image className="i" src={zan2Icon}/>
  84. :
  85. <Image className="i" src={zan1Icon}/>
  86. }
  87. <View className={item.is_zan ? 'n cur' : 'n'}>{item.zan_count}</View>
  88. </View>
  89. <View className="lb-sub">
  90. <View>
  91. {
  92. subList.map((sub, subIndex) => {
  93. const lvSubIcon = Taro.$getLvIcon(sub.integral)
  94. return (
  95. <View className="lcb-item" key={subIndex}>
  96. <View className="lb-img">
  97. <Image className="img" src={sub.avatar} />
  98. </View>
  99. <Navigator url={'/pagesMore/comment/dtl?id=' + item.id + '&estateId=' + curObj.id} className="lb-info">
  100. <View className="lb-p1">{sub.nickname}
  101. <Image className="i" src={lvSubIcon}></Image>
  102. </View>
  103. <View className="lb-time">{sub.create_at}</View>
  104. <View className="lb-p2">{sub.comm_cont}</View>
  105. </Navigator>
  106. </View>
  107. )
  108. })
  109. }
  110. </View>
  111. {
  112. item.child.length > 4
  113. ?
  114. item.isMoreAllShow
  115. ?
  116. <View className="lb-more t2" onClick={this.commentMoreHandle.bind(this, index)}>收起
  117. <View className="sign"></View>
  118. </View>
  119. :
  120. <View className="lb-more" onClick={this.commentMoreHandle.bind(this, index)}>-展开回复({item.child.length - 4}条)
  121. <View className="sign"></View>
  122. </View>
  123. : ''
  124. }
  125. </View>
  126. </View>
  127. </View>
  128. )
  129. })
  130. return (
  131. <View className="l-comment-box">
  132. <View>
  133. {curItems}
  134. {
  135. commentList.length === 0
  136. &&
  137. <ListMore isOther={true} text="来聊两句?"/>
  138. }
  139. </View>
  140. {this.renderCommentBtn()}
  141. </View>
  142. )
  143. }
  144. }