import { doNavigateWithUser } from '../../utils/helper';
import { isObjEmpty } from '../../utils/index';
import { static_url } from '../../utils/util';

Component({

  /**
   * 组件的属性列表
   */
  properties: {
    item: { // 循环项
      type: Object,
      value: null,
    },
    type: {
      type: String,
      value: ''
    },
    isLast: {
      type: Boolean,
      value: false
    },

    joinType:{
        type:String,
        value:"2"
    }
  
  },

  /**
   * 组件的初始数据
   */
  data: {
    picUrl: static_url,
    staticUrl: static_url,
  },

  /**
   * 组件的方法列表
   */
  methods: {
    // 导航触发父组件方法
    handleOptionClick() {
      const { item } = this.data;
      let openParmas = {
        latitude: Number(item.lat),
        longitude: Number(item.lng),
        name: item.name,
        address: item.addr,
      }
      if (!isObjEmpty(openParmas)) {
        Object.assign(openParmas, this.bMapTransQQMap(openParmas.longitude, openParmas.latitude));
        wx.openLocation(openParmas);
      }
    },

    // 地图转腾讯地图
    bMapTransQQMap: function (lng, lat) {
      return {
        longitude: lng,
        latitude: lat
      };
    },


    //拨打电话触发事件
    headlePhoneClick() {
      const {
        item
      } = this.data;
      wx.makePhoneCall({
        phoneNumber: item.tel
      })
    },
    //进入小区
    headerEnterClick() {
      const {
        item,
        type
      } = this.data;
      if (type) {
        console.log('共享空间点击事件');
        return;
      }
      doNavigateWithUser({
        url: `/packages/community/dwelling/index?title=${item.name}&id=${item.community_id}`
      })
    },
    headerEnterClick2(e){
        let that = this
        if(that.data.joinType == 3){
            let community_id = e.currentTarget.dataset.id;
            let name = e.currentTarget.dataset.name;
            let that= this
            that.triggerEvent('chooseCommunity',{
                name,community_id
            })
            wx.navigateBack({
                delta:1
            })
        }else{
            console.log(456);
            that.headerEnterClick()
        }
    },
    //选择小区
    chooseClick(e){
        let community_id = e.currentTarget.dataset.id;
        let name = e.currentTarget.dataset.name;
        let that= this
        // that.triggerEvent('chooseCommunity',{
        //     name,community_id
        // })
        wx.setStorageSync('currentCommunity', name)
        wx.setStorageSync('currentCommunityId', community_id)
        wx.navigateBack({
            delta:1
        })
    },
  }
})