detail.js 3.66 KB
// pages/reserve/detail.js
import util from '../../utils/util';
import App from '../../utils/api';
const {regeneratorRuntime} = global
Page({

  /**
   * 页面的初始数据
   */
  data: {
    seller:{},
    IsCollectionSeller:false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log('onLoad', options)
    this.options=options
    App.Customer.IsCollectionSeller({
      sid:options.id,
      openid:getApp().openid
    }).then(res=>{
      this.setData({
        IsCollectionSeller:res.data,
      })
    })
  },
  GetSellerDetail(){
    let options=this.options
    App.Customer.GetSellerDetail({
      sid:options.id,
      lat:this.location.latitude,
      lng:this.location.longitude,
    }).then(res=>{
      if(res.ret==200){
        let seller=res.data
        let seller_tel=[]
        if(seller.seller_tel){
          seller_tel=seller.seller_tel.split(',')
        }else{
          seller_tel=[seller.seller_phone];
        }
        seller.seller_tel=seller_tel
        seller.distance=parseInt(seller.distance);
        if(seller.distance>1000){
          seller.distanceStr=(seller.distance/1000).toFixed(2)+'公里'
        }else{
          seller.distanceStr=seller.distance+'米';
        }
        if(seller.envi_image.length<1){
          seller.envi_image=['http://qn.colorcun.com/custom/lite-online/image/def-banner.png']
        }
        this.setData({
          seller:seller,
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

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

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

  },

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

  },

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

  },

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

  },

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

  },
  reserve(){
    let seller_tel=this.data.seller.seller_tel
    if(seller_tel.length<1) return util.toast('商家电话错误','none')
    if(seller_tel.length==1){//只有一个电话
      let phone=seller_tel[0].replace(/[^\d]/,'')
      wx.makePhoneCall({
        phoneNumber:phone
      })
    }else{
      this.selectComponent('#as').show();
    }
  },
  reservePhone(e){
    let phone=e.detail.value.replace(/[^\d]/,'')
    wx.makePhoneCall({
      phoneNumber:phone
    })
  },
  follow(e){
    console.log('收藏',e)
    this.setData({
      IsCollectionSeller:!this.data.IsCollectionSeller
    })
    if(this.data.IsCollectionSeller){//已收藏

    }else{

    }
  },
  getPos(){
    this._getPos().then(res => {
      console.log('wx.getLocation.then', res);
      this.location=res
      this.GetSellerDetail();
    }).catch((e) => {
      console.log('wx.getLocation.catch', e);
      if ('getLocation:fail auth deny' == e.errMsg || 'getLocation:fail:auth denied' == e.errMsg) {
        this.selectComponent('#showModal').options({
          header: '定位失败',
          body: '需要地理位置授权'
        }).show();
      } else {
        setTimeout(() => {
          this.getPos()
        }, 500)
      }

    })
  },
  _getPos(){
    return new Promise((success, fail) => {
      wx.getLocation({
        type: 'gcj02',
        success: (res) => {
          success(res)
        },
        fail: (res) => {
          fail(res)
        },
        complete: (res) => {
          console.log('wx.getLocation', res)
        }
      });
    })
  },
})