index.jsx 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import Taro, { Component } from '@tarojs/taro'
  2. import { View, Image } from '@tarojs/components'
  3. import './index.scss'
  4. export default class Comment extends Component {
  5. constructor (props) {
  6. super(props)
  7. this.state = {
  8. otherObj: '',
  9. dataList: [],
  10. curObj: {},
  11. }
  12. }
  13. componentWillMount () {
  14. this.props.onRef(this)
  15. }
  16. getData = (dataList, otherObj) => {
  17. const arrIndex = Math.floor(Math.random() * dataList.length)
  18. this.setState({
  19. curObj: dataList[arrIndex],
  20. otherObj,
  21. })
  22. }
  23. netLink () {
  24. const { curObj, otherObj } = this.state
  25. Taro.navigateTo({
  26. url: `/pagesQa/msg/chat?to_user_id=${curObj.user_id}&eTitle=${otherObj.name}&eId=${otherObj.id}`
  27. })
  28. }
  29. callHandle () {
  30. const { curObj } = this.state
  31. Taro.makePhoneCall({
  32. phoneNumber: curObj.sale_phone
  33. })
  34. }
  35. afterCount (type) {
  36. if (type === 'chat') {
  37. this.netLink()
  38. }
  39. if (type === 'call') {
  40. this.callHandle()
  41. }
  42. }
  43. countHandle (type) {
  44. const { curObj, otherObj } = this.state
  45. let params = {
  46. target_id: otherObj.id,
  47. target_type: 2,
  48. sale_id: curObj.sale_id,
  49. click_type: type === 'call' ? '2' : '1' // 1在线聊 2打电话
  50. }
  51. Taro.api.room.apiusercontactclick(params).then(() => {
  52. this.afterCount(type)
  53. }).catch(() => {
  54. this.afterCount(type)
  55. })
  56. }
  57. render () {
  58. const { curObj } = this.state
  59. const tagStr = curObj.custom_tag ? curObj.custom_tag.substring(0, 8) : ''
  60. return (
  61. <View className="scoped-sale">
  62. <View className="ss-img">
  63. <Image src={curObj.sale_avatar} className="img"/>
  64. </View>
  65. <View className="ss-info">
  66. <View className="p1">{curObj.sale_name}</View>
  67. <View className="p2">{tagStr}</View>
  68. </View>
  69. <View className="ss-r">
  70. <View className="b" onClick={this.countHandle.bind(this, 'chat')}>在线问</View>
  71. <View className="b t2" onClick={this.countHandle.bind(this, 'call')}>打电话</View>
  72. </View>
  73. </View>
  74. )
  75. }
  76. }