discount.js 3.86 KB
// pages/me/follow.js
import util from '../../utils/util';
import App from '../../utils/api';
const {regeneratorRuntime} = global
Page({

  /**
   * 页面的初始数据
   */
  data: {
    sellers:[],
    hasMore:true,
    activity:null,
	discountlist:[
		{
			name:'超值套餐',
			slogan:'尝遍特色菜品 就选超值套餐'
		},
		{
			name:'线下特惠',
			slogan:'先预订再就餐 享受会员特惠'
		},
		{
			name:'买单优惠',
			slogan:'使用平台买单 多重优惠叠加'
		},
	],
	tabidx:0,
  },
  sellers:[],
  /**
   * 生命周期函数--监听页面加载
   */
  options:null,
  onLoad: function (options) {
    //latitude=34.215637&longitude=108.891264&scale=16&height=397
    this.options=options;
	this.setData({
		tabidx:options.tabidx,
	})
  },
  formatSellers(data){
    let sellers=[];
    let hasChange=false
    this.sellers.forEach(seller=>{
      if(seller.id==data.sid){
        hasChange=true
        seller.hasFollow=data.hasFollow
      }
      if(seller.hasFollow){
        sellers.push(seller)
      }
    })
    if(!hasChange){
      sellers=[]
    }
    this.setData({
      sellers:sellers
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    if(this.hasMore || this.data.sellers.length==0){
      this.sellers=[]
      this.offset=1
      this.setData({
        sellers:[]
      })
      this.selectComponent('#getpos').getPos();
    }
  },

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

  },

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

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

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function (e) {
    console.log(e)
    if(this.hasMore){
      this.GetCollectionSellerList();
    }
  },
  offset:1,
  size:10,
  hasMore:true,
  GetCollectionSellerList(){
    this.city=JSON.parse(this.options.city)
    App.Customer.GetActivitySellerListByFoods({
      code:this.city.code,
      pid:this.city.pid,
      offset:this.offset,
      size:this.size,
      distance:50,
      lat_extend:this.location.latitude,
      lng_extend:this.location.longitude,
    }).then(res=>{
      let sellers=res.data;
      let sellersLength=sellers.length;
      this.hasMore=sellersLength>=this.size
      if(this.hasMore){
        this.offset+=1
      }
      sellers.forEach((seller,si) => {
        // if(seller.distance || seller.distance===0) {
        //   seller.distance = parseInt(seller.distance);
        //   if (seller.distance > 1000) {
        //     seller.distance = (seller.distance / 1000).toFixed(2) + 'km'
        //   } else {
        //     seller.distance += 'm';
        //   }
        // }
        if(seller.seller_tel){
          seller.seller_tel=seller.seller_tel.split(',');
        }else{
          seller.seller_tel=[]
        }
        seller.hasFollow=true
      })
      sellers=[...this.data.sellers,...sellers]
      this.setData({
        sellers:sellers,
        hasMore:this.hasMore,
      })
      this.sellers=sellers
    })
  },
  gotoDetail(e){
    wx.navigateTo({
      url:'/pages/reserve/detail?id='+util.attr(e,'sid')
    })
  },
  onpos(e){
    console.log(e);
    this.location=e.detail
    this.GetCollectionSellerList();
  },
  hasActivityEvent(e){
    console.log('hasActivityEvent',e);
    App.Task.GetTaskInfo({pos:'home'}).then(res=>{
      let activity=res.data.activity
      if(!activity) return;
      let time=new Date()/1000
      if(activity.status==1 && activity.starttime<time && time<activity.endtime){
        this.setData({
          activity:activity,
        })
      }
    })
  },
  switchdiscount(e){
	let tabidx=util.attr(e,'tabidx');
	this.setData({
		tabidx:tabidx,
	})  
  }
})