const imgurl = require("../../utils/imgurl");
Component({
  properties: {
    mallList: {
      value: [],
      type: Array
    }
  },

  data: {
    teljpgUrl: imgurl.teljpg.url,
    list: [], // 广场、商户列表
    mallNum: 0, // 适用商户数量
  },

  methods: {
    // 跳转详情页
    gotoDetail(e) {
      console.log(e);
      wx.navigateTo({
        url: `/pages/index/searchbar/detail/index?id=${e.currentTarget.dataset.id}&mallTenantId=${e.currentTarget.dataset.tenantid}`
      })
    },
    phone: function (e) {
      let that = this;
      wx.makePhoneCall({
        phoneNumber: e.target.dataset.merchantlinkphone
      });
    },

    // 跳转资质页面
    // goCertification(e) {
    //   wx.navigateTo({
    //     url: `/pages/shopCertification/index?id=${e.currentTarget.dataset.id}`
    //   })
    // },

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

    goFitShop() {
      const arr = []
      this.data.list.forEach(item => {
        item.merchantVoList.forEach(el => {
          arr.push(el)
        })
      })
      wx.navigateTo({
        url: `/pages/fitShop/fitShop?list=${JSON.stringify(arr)}`,
        success: (res) => { },
        fail: (res) => { },
      });
    },

    expandList(e) {
      const index = e.currentTarget.dataset.index
      const arr = this.data.list
      arr[index].expand = !arr[index].expand
      this.setData({
        list: arr
      })
    }
  },

  ready() {
    this.setData({
      list: JSON.parse(JSON.stringify(this.properties.mallList))
    })

    console.log(this.data.mallList, 'mallList');
    let mallNum = 0
    this.data.list.forEach(item => {
      mallNum += item.merchantVoList.length
    })
    this.setData({
      mallNum: mallNum
    })
  },

  created() {

  }
})