1. 程式人生 > >一鍵撥號,定位,長按二維碼圖片

一鍵撥號,定位,長按二維碼圖片

var app = getApp();
Page({

  /**
   * 頁面的初始資料
   */
  data: {
    info: {
      mobile: '',
      telphone: '',
      address: '',
      latitude: "",
      longitude: "",

    },
    imgalist: ['https://www.njnrkj.com/MEIRONG/image/contact/code.jpg', 'https://www.njnrkj.com/MEIRONG/image/contact/code.jpg'],  
  },

  /**
   * 生命週期函式--監聽頁面載入
   */
  onLoad: function (options) {
  //  this.loadInfo();
    
    var that = this
    var scene_img = 'https://www.njnrkj.com/MEIRONG/image/contact/code.jpg' //這裡新增圖片的地址  
    that.setData({
      scene: scene_img
    })
  },
  previewImage: function (e) {
    wx.previewImage({
      current: this.data.imgalist, // 當前顯示圖片的http連結     
      urls: this.data.imgalist // 需要預覽的圖片http連結列表     
    })
    wx.getImageInfo({// 獲取圖片資訊(此處可不要)  
      src: 'https://www.njnrkj.com/MEIRONG/image/contact/code.jpg',
      success: function (res) {
        console.log(res.width)
        console.log(res.height)
      }
    })
  },
  clickMobile: function () {
    wx.makePhoneCall({
      phoneNumber: this.data.info.telphone
    })
  },

  clickTelephone: function () {
    wx.makePhoneCall({
      phoneNumber: this.data.info.mobile
    })
  },

  loadInfo: function () {
    var that = this;
    var cacheInfo = wx.getStorageSync('info');
    if (cacheInfo) {
      that.setData({
        info: cacheInfo
      });
      return;
    }
    wx.request({
      url: 'https://www.njnrkj.com/app/public/index.php/index/contact/MrContact',
      dataType: 'json',
      success: function (res) {
        // console.log('res=' + res);
        if (res.statusCode == 200 && res.data.error != "error") {
          that.setData({
            info: res.data.info
          });
          wx.setStorage({
            key: 'info',
            data: res.data.info
          });
        } else {
          wx.showToast({
            icon: 'none',
            title: '沒有訪問許可權或訪問出錯',
          });
        }
      },
      fail: function (err) {
        wx.showToast({
          icon: 'none',
          title: '訪問出錯',
        });
      }
    })
  },
  /**
   * 地址點選事件
   */
  clickAddress: function (e) {
    console.log('click address.....');
    wx.openLocation({
      latitude: 32.0902400000 || 0,
      longitude: 118.7813700000 || 0,
      name: this.data.info.storeName || '',
      address: this.data.info.address || ''
    })
  },
  /**
   * 生命週期函式--監聽頁面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命週期函式--監聽頁面顯示
   */
  onShow: function () {
    this.loadInfo();
  },

  /**
   * 生命週期函式--監聽頁面隱藏
   */
  onHide: function () {

  },

  /**
   * 生命週期函式--監聽頁面解除安裝
   */
  onUnload: function () {
    wx.removeStorage({
      key: 'info',
      success: function (res) { },
    });
  },

  /**
   * 頁面相關事件處理函式--監聽使用者下拉動作
   */
  onPullDownRefresh: function () {
    wx.removeStorageSync('info');
    this.loadInfo();
  },

  /**
   * 頁面上拉觸底事件的處理函式
   */
  onReachBottom: function () {

  },

  /**
   * 使用者點選右上角分享
   */
  onShareAppMessage: function () {

  }
})

<view class="container">

<view class="qrcode2"></view>
   

  <image class="codepic" bindtap='previewImage' src ='{{scene}}'></image> 
 
  <view class="input-compont">
    <view class="address-input">
      <view>
        <text class='mobile'>手機:{{info.telphone}} </text>
        <image bindtap='clickMobile' mode='widthFix' class='img1' src='https://www.njnrkj.com/MEIRONG//image/contact/mobile.png' />
      </view>
    </view>

    <view class="address-input">
      <view>
        <text>美麗熱線:{{info.mobile}} </text>
        <image bindtap='clickTelephone' mode='widthFix' class='img2' src='https://www.njnrkj.com/MEIRONG//image/contact/call.png' />
      </view>
    </view>

    <view class="address-input last-input">
      <view>
        <view class='address_top'>
          <text>門店地址:{{info.address}}</text>
          <image catchtap='clickAddress' mode='widthFix' class='img3' src='https://www.njnrkj.com/MEIRONG//image/contact/direction.png' />
        </view>
      </view>
    </view>
  </view>
</view>