import Taro, { Component } from '@tarojs/taro' import { View, Image } from '@tarojs/components' import './index.scss' export default class Comment extends Component { constructor (props) { super(props) this.state = { otherObj: '', dataList: [], curObj: {}, } } componentWillMount () { this.props.onRef(this) } getData = (dataList, otherObj) => { const arrIndex = Math.floor(Math.random() * dataList.length) this.setState({ curObj: dataList[arrIndex], otherObj, }) } netLink () { const { curObj, otherObj } = this.state Taro.navigateTo({ url: `/pagesQa/msg/chat?to_user_id=${curObj.user_id}&eTitle=${otherObj.name}&eId=${otherObj.id}` }) } callHandle () { const { curObj } = this.state Taro.makePhoneCall({ phoneNumber: curObj.sale_phone }) } afterCount (type) { if (type === 'chat') { this.netLink() } if (type === 'call') { this.callHandle() } } countHandle (type) { const { curObj, otherObj } = this.state let params = { target_id: otherObj.id, target_type: 2, sale_id: curObj.sale_id, click_type: type === 'call' ? '2' : '1' // 1在线聊 2打电话 } Taro.api.room.apiusercontactclick(params).then(() => { this.afterCount(type) }).catch(() => { this.afterCount(type) }) } render () { const { curObj } = this.state const tagStr = curObj.custom_tag ? curObj.custom_tag.substring(0, 8) : '' return ( {curObj.sale_name} {tagStr} 在线问 打电话 ) } }