const imgurl = require("../../utils/imgurl");
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    merchantVoList: {
      value: [],
      type: Array
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    teljpgUrl: imgurl.teljpg.url,
    showMore:false,
    more: "点击查看更多",
    hidden:"hidden",
    height: ""
  },
  
  /**
   * 组件的方法列表
   */
  methods: {
    /**
   * 跳转到门店列表的详情页面
   */
    gotoDetail(e) {
      tt.navigateTo({
        url: `/pages/index/searchbar/detail/index?id=${e.currentTarget.dataset.id}`
      })
    },
    goCertification(e){
      tt.navigateTo({
        url: `/pages/shopCertification/shopCertification?id=${e.currentTarget.dataset.id}`
      })
    },
    goFitShop(){
      tt.navigateTo({
        url: `/pages/fitShop/fitShop?list=${JSON.stringify(this.data.merchantVoList)}`,
        success: (res) => { 
          
        },
        fail: (res) => {
          
        },
      });
    },
    goMap(e){

      let {latitude,longitude} = e.currentTarget.dataset.item
      console.log(latitude,longitude);
      tt.openLocation({
        latitude:Number(latitude),
        longitude:Number(longitude),
        scale: 18,
        success() {
          console.log("打开地图成功");
        },
        fail(err) {
          console.log("打开地图失败:", err.errMsg);
        },
      });

    },
    // 点击查看更多
    more: function () {
      console.log(this.properties.merchantVoList,"merchantVoList");
      let that = this;
      if (that.data.more == '点击查看更多') {
        this.setData({
          hidden: "",
          height: 'auto!important',
          more: "点击收起",
          showMore: true
        })
      } else {
        that.setData({
          hidden: "hidden",
          height: 4 * 140 + 'rpx',
          more: "点击查看更多",
          showMore: true
        })
      }
    },
    phone: function (e) {
      let that = this;
      tt.makePhoneCall({
        phoneNumber: e.target.dataset.merchantlinkphone
      });
    },
    
  },
  
  ready: function () {
    let merchantVoList = this.properties.merchantVoList;
    if (merchantVoList.length>0){
      if (merchantVoList.length <= 4) {
        this.setData({
          height: merchantVoList.length * 140 + 'rpx',
          showMore: false,
          hidden:"hidden"
        })
      } else if (merchantVoList && merchantVoList.length > 4) {
        this.setData({
          height: 4 * 140 + 'rpx'
        })
      }
    }
  }
});
