com.jsx 2.5 KB

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