afterchildbirth.js 4.8 KB
// pages/partneritem/afterchildbirth/afterchildbirth.js
const app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    wd: '',
    jd: '',
    rank_index: 0,
    rankCon: ['排序','按热度排序', '按距离排序', '按价格排序'],
    listInfo: [],
    keywords: '',
    choose_index: 0,
    addr_index: 0,
    chooseCon: '',
    choseid: '',
    addresid: '',
    addrCon: '',
    name:'产后',
    type:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)
    let that = this;
    that.setData({
      type:options.type
    })

    wx.setNavigationBarTitle({
      title: options.name //页面切换,更换页面标题
    })


    // if(that.data.type==1){
    //   wx.setNavigationBarTitle({
    //     title: '备孕期' //页面切换,更换页面标题
    //   })
    // }else if (that.data.type==2){
    //   wx.setNavigationBarTitle({
    //     title: '孕早期' //页面切换,更换页面标题
    //   })
    // }else if (that.data.type == 3) {
    //   wx.setNavigationBarTitle({
    //     title: '孕中期' //页面切换,更换页面标题
    //   })
    // }else if (that.data.type == 4) {
    //   wx.setNavigationBarTitle({
    //     title: '孕晚期' //页面切换,更换页面标题
    //   })
    // }else if (that.data.type == 5) {
    //   wx.setNavigationBarTitle({
    //     title: '产后' //页面切换,更换页面标题
    //   })
    // }else if (that.data.type == 6) {
    //   wx.setNavigationBarTitle({
    //     title: '亲子' //页面切换,更换页面标题
    //   })
    // }
   
    wx.getLocation({
      type: 'wgs84',
      success: function (res) {
        console.log(res)
        var latitude = res.latitude
        var longitude = res.longitude
        that.setData({
          wd: latitude,   //纬度
          jd: longitude   //经度
        })
        that.getClassify(latitude, longitude)
      }
    })
  },
  // 获取筛选
  getChoose: function (e) {
    let that = this;
    that.setData({
      choose_index: e.detail.value,
      choseid: that.data.chooseCon[e.detail.value].id,
      listInfo:[]
    })
    that.getClassify()
  },
  // 获取地址
  getAddr: function (e) {
    let that = this;
    that.setData({
      addr_index: e.detail.value,
      addresid: that.data.addrCon[e.detail.value].id,
      listInfo:[]
    })
    that.getClassify()
  },
  // 获取分类列表信息
  getClassify: function (latitude, longitude) {
    let that = this;
    let url = "/api/portal/Compare/chooseList";
    let params = {
      lat: that.data.jd,
      lng: that.data.wd,
      city: that.data.addresid,
      order: that.data.rank_index,
      choose: that.data.choseid,
      keyword: that.data.keywords,
      type:that.data.type
    }
    app.post(url, params).then((res) => {

      console.log(res)
      // let screen = [];
      let listFixed = res.compare;
      console.log(listFixed)
      for (var i = 0; i < listFixed.length; i++) {
        // listFixed[i].distance = listFixed[i].distance.toFixed(2);
        // screen.push(listFixed[i].find_tag);
      }
      let newchose=res.choose;
      let chosename={
        id:'',
        title:'全部'
      }
      newchose.unshift(chosename);
      console.log(newchose)
      that.setData({
        listInfo: listFixed,
        chooseCon: newchose,
        addrCon: res.addr
      })

      console.log(that.data.listInfo)
    }).catch((errMsg) => {})
  },
  // 获取排序
  getRank: function(e){
    this.setData({
      rank_index: e.detail.value,
      listInfo:[]
    })
    this.getClassify()
  },
  // 获取搜索条件
  getKeywords:function(e){
    this.setData({
      keywords: e.detail.value
    })
    // 条件筛选
    if (e.detail.value == '' || e.detail.value == null){
      this.getClassify();
    }
  },
  // 点击搜索  获取分类列表
  searchTap:function(e){
    this.setData({
      listInfo:[]
    })
    
    this.getClassify();
  },
  // 点击跳转到 产后详情
  childtail: function (e) {
    let compareId = e.currentTarget.dataset.compareid;

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

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

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

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

  },

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

  },

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

  },

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

  },

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

  },
})