partner.js 4.1 KB
// pages/partner/partner.js
const app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    wd: '',
    jd: '',
    parentList: [],
    parentImg: [],
    imgUrls: [],
    currentSwiper: 0,
    shoplist: [],
    autoplay: true,
    interval: 2000,
    duration: 1000,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {

  },

  enter(e) {
    let token = wx.getStorageSync("token");
    if (token == '') {
      wx.showToast({
        title: '请先登录',
        icon: 'none'
      })
      setTimeout(function() {
        wx.navigateTo({
          url: '/pages/index/index',
        })
      }, 1000)
    } else {
      let url = e.currentTarget.dataset.url;
      wx.navigateTo({
        url: '../sharepage/sharepage?url=' + url,
      })
    }

  },

  //获取合作商户的分类
  getshoplist() {
    let that = this;
    var url = '/api/portal/Compare/cateList';
    var params = {
      // token: wx.getStorageSync('token'),

    }
    app.post(url, params).then((res) => {
      console.log(res);
      that.setData({
        shoplist: res
      })



    }).catch((err) => {

    })
  },

  swiperChange: function(e) {
    this.setData({
      currentSwiper: e.detail.current
    })
  },
  // 产后分类
  childkind: function(e) {

    let token = wx.getStorageSync("token");
    if (token == '') {
      wx.showToast({
        title: '请先登录',
        icon: 'none'
      })
      setTimeout(function() {
        wx.navigateTo({
          url: '/pages/index/index',
        })
      }, 1000)
    } else {
      let type = e.currentTarget.dataset.type;
      let name = e.currentTarget.dataset.name
      wx.navigateTo({
        url: '../partneritem/afterchildbirth/afterchildbirth?type=' + type + '&name=' + name,
      })
    }

  },


  //服务详情页
  detail(e) {

    let token = wx.getStorageSync("token");
    if (token == '') {
      wx.showToast({
        title: '请先登录',
        icon: 'none'
      })
      setTimeout(function() {
        wx.navigateTo({
          url: '/pages/index/index',
        })
      }, 1000)
    } else {
      let compareId = e.currentTarget.dataset.compareid;


      wx.navigateTo({
        url: '../partneritem/afterchildbirthrecover/afterchildbirthrecover?compareId=' + compareId,
      })
    }

  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    var that = this
    wx.getLocation({
      type: 'gcj02',
      success: function(res) {
        console.log(res)
        var latitude = res.latitude
        var longitude = res.longitude
        that.setData({
          wd: latitude, //纬度
          jd: longitude //经度
        })
        that.getPartner(latitude, longitude)
      }
    })

    that.getshoplist()
  },

  // 获取合作商户列表
  getPartner: function(latitude, longitude) {
    let that = this;
    let url = "/api/portal/Compare/index";
    let params = {
      lat: that.data.jd,
      lng: that.data.wd
    }
    app.post(url, params).then((res) => {
      console.log(res)
      let list = res.compare;
      console.log(list)
      // for (var i = 0; i < list.length; i++) {
      //   if (list[i].distance.length){

      //   }
      //   list[i].distance = list[i].distance.toFixed(2)
      // }

      console.log(list)

      // let newlist=list;
      // for(var obj of newlist){
      //   obj.distance = obj.distance.toFixed("2")
      // }
      that.setData({
        parentList: list,
        parentImg: res.banner,
        imgUrls: res.banner.splice(0, 3)
      })


      console.log(that.data.parentImg)
    }).catch((errMsg) => {})




  },



  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})