import Taro, { Component } from '@tarojs/taro'
import { View, Image } from '@tarojs/components'
import ListMore from '@/c/pageDataList/listMore'
import './index.scss'
export default class Comment extends Component {
constructor (props) {
super(props)
this.state = {
curObj: {},
}
}
componentWillMount () {
this.props.onRef(this)
}
getData = (curObj) => {
this.setState({
curObj
})
}
renderCommentBtn () {
const editIcon = require('@img/icon_g_edit.png')
return (
我想说两句
)
}
commentMoreHandle (index) {
const { curObj } = this.state
let mList = curObj.comm_list || []
mList.map((item, i) => {
if (index === i) item.isMoreAllShow = !item.isMoreAllShow
})
let newObj = {...curObj}
newObj.comm_list = [...mList]
this.setState({
curObj: newObj
})
}
addCommentHandle () {
const { curObj } = this.state
Taro.navigateTo({
url: `/pagesMore/comment/add?id=${curObj.id}&name=${curObj.estate_name}`
})
}
zanHandle (comment_id, flag) {
let apiStr = flag ? 'estatecommentunzan' : 'estatecommentzan'
Taro.api.house[apiStr]({
comment_id
}).then(res => {
this.props.getDtl()
})
}
render () {
const { curObj } = this.state
const zan1Icon = require('@img/i_g_zan.png')
const zan2Icon = require('@img/i_g_zan2.png')
let commentList = curObj.comm_list || []
const curItems = commentList.map((item, index) => {
const lvIcon = Taro.$getLvIcon(item.integral)
const oldList = item.child && item.child.length ? JSON.parse(JSON.stringify(item.child)) : []
const subList = item.isMoreAllShow ? [...oldList] : oldList.splice(0, 4)
return (
{item.nickname}
{item.create_at}
{item.comm_cont}
{
item.is_zan
?
:
}
{item.zan_count}
{
subList.map((sub, subIndex) => {
const lvSubIcon = Taro.$getLvIcon(sub.integral)
return (
{sub.nickname}
{sub.create_at}
{sub.comm_cont}
)
})
}
{
item.child.length > 4
?
item.isMoreAllShow
?
收起
:
-展开回复({item.child.length - 4}条)
: ''
}
)
})
return (
{curItems}
{
commentList.length === 0
&&
}
{this.renderCommentBtn()}
)
}
}