import ImSend from './../../utils/imSend'
import { loginByUserInfo } from '../../utils/login'
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    agent_user: Object,
    house_id: String
  },

  /**
   * 组件的初始数据
   */
  data: {

  },
  pageLifetimes: {
    show () {
      this.setData({
        loginStatus: getApp().globalData.token ? true : false
      })
    }
  },

  /**
   * 组件的方法列表
   */
  methods: {
    makePhone () {
      wx.makePhoneCall({
        phoneNumber: this.properties.agent_user.phone,
      })
    },
    toAgentDetail () {
      wx.navigateTo({
        url: `/pages/agent-detail/agent-detail?agency_id=${this.properties.agent_user.agency_user_id}`,
      })
    },
    senMsg () {
      ImSend.sendVrMsg(getApp().globalData.last_house, '', this.properties.agent_user.agency_user_id, false).then(res => {
        wx.navigateTo({
          url: `/pages/chat/chat?toId=${this.properties.agent_user.agency_user_id}&toName=${this.properties.agent_user.name}`,
        })
      })
    },
    bindgetuserinfo (e) {
      const { action } = e.currentTarget.dataset
      loginByUserInfo().then(res => {
        this.setData({
          loginStatus: getApp().globalData.token ? true : false
        })
        this[action] && this[action]()
      })
    }
  }
})
