free_delivery.js 3.89 KB
// packageF/pages/free_delivery/free_delivery.js
var o = getApp().globalData.setting
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    url: o.imghost,
    userInfo:null,
    login_title:'暂未登录,请先登录',
    login_name:'授权登录',
    login_off:false,
    hd_id:'',
    delHeight:736,  //默认窗口高度,用于对比,定位图片用
    delOff:false,  //窗口高度对比,false 用默认定位,ture 定位调整

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let window_info = wx.getWindowInfo()
    if (window_info.screenHeight > this.data.delHeight) {
      this.setData({
        delOff:true
      })
    }

    if (options && options.id) {
      this.setData({
        hd_id:options.id
      })
      this.getInfo()
    }else{
      wx.showToast({
        title: '获取活动失败',
        icon: 'none',
        duration: 2000,
        mask:true
      })
      setTimeout(()=>{
        wx.reLaunch({
          url: '/pages/index/index/index'
        })
      },2000)
    }

  },
  getInfo(){
    app.promiseGet(`/api/weshop/meitu/storeMeituHdlist/get/${app.globalData.setting.stoid}/${this.data.hd_id}`, {}).then(res => {
      if (res.data.code == 0 && res.data.data && res.data.data.hd_name) {        
        wx.setNavigationBarTitle({
          title: res.data.data.hd_name
        })
      } 
  })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    let userInfo = getApp().globalData.userInfo;
    this.setData({
      userInfo
    })
    if (userInfo) {
      if (userInfo.mobile) {
        this.setData({
          login_title:userInfo.mobile,
          login_name:'领取会员'
        })
      }else{
        getApp().globalData.userInfo=null
        wx.setStorageSync("userinfo", null);
      }
    }

  },
	//--跳到绑定页面--  
	gobindtel: function () {
    let userInfo = this.data.userInfo
    let login_off = this.data.login_off
    if (userInfo) {
      if (!login_off) {
        this.setData({
          login_off:true
        })
        wx.showLoading({
          title: '领取中',
          mask: true,
        });
        app.request.promisePost('/api/weshop/meitu/storeMeituUserlist/save', {
          is_json: true,
          data: {
            store_id: app.globalData.setting.stoid,
            user_id: app.globalData.user_id,
            hd_id: this.data.hd_id,
          },
        }).then((res)=>{       
          if(res.data.code == 0) {
            wx.showToast({
              title: res.data.msg,
              icon: 'none',
              duration: 2000,
              mask:true,
            });
            this.setData({
              login_name:'已领取'
            })
            // setTimeout(()=>{
            //   wx.reLaunch({
            //     url: '/pages/index/index/index'
            //   })
            // },2000)
            // self.getData(true, '/api/weshop/goods/page?isnewwhere=1&is_mainshow=1&isonsale=1&dis_type=1', self.data.currentQuery, false);	
          } else {
            this.setData({
              login_off:false
            })
            wx.showToast({
              title: res.data.msg,
              icon: 'none',
              duration: 2000,
              mask:true,
            });
          }
          
        });




      }
    }else{
      wx.navigateTo({
        url: '/packageE/pages/togoin/togoin',
      })
    }
	},
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

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

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
    wx.stopPullDownRefresh()
  },

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

  },

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

  }
})