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

  /**
   * 页面的初始数据
   */
  data: {
    seller:{},
    paletteImageSrc:'',
    palette:null,
    hasLoadData:false,
    act:'',
    hasActName:'',
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.options=options;
    this.setData({
      actType:options.act
    })
    this.GetSellerDetail();
  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  },
  GetSellerDetail(){
    let options=this.options
    App.Customer.GetSellerDetail({
      sid:options.id,
    }).then(async res=>{
      if(res.ret==200){
        let seller=res.data
        console.log('App',App)
        let qrcode=await App.Other.generate_qrcode({
          tpl_id: 25415,
          code_type: 'wxcode',
          'param_value[0]':80
        });
        this.setData({
          seller:seller,
          qrcode:qrcode.data,
          hasLoadData:true,
        })
        setTimeout(()=>{
          this.initImage()
        },0);
      }
    })
  },
  initImage(){
    this.setData({
      palette:{
        background: '#fff',
        width: getApp().system.windowWidth+'px',
        height: getApp().system.windowHeight+'px',
        views: [
          {
            type:'image',
            url:'https://xt04.colorcun.com/sellerShare/Share_'+this.options.id+'.png',
            css:{
              width:getApp().system.windowWidth+'px',
              height:(480*(getApp().system.windowWidth/600))+'px',
              mode:'aspectFill'
            }
          },
          {
            type:'text',
            text: "陕西风味面馆",
            css:{
              fontSize:'14px',
              color:'#f00',
              background:'#ff0',
              padding:'8px 20px',
              top:(480*(getApp().system.windowWidth/600)+20)+'px',
              left:'16px',
              lineHeight:'18px'
            }
          },
          {
            type:'rect',
            css:{
              color:'rgba(0,0,0,0.5)',
              top:(480*(getApp().system.windowWidth/600)+12)+'px',
              left:'0px',
              width:'320px',
              height:'34px'
            }
          },
          {
            type: 'image',
            url: this.data.qrcode,
            css: {
              bottom: '48rpx',
              right: '48rpx',
              width: '192rpx',
              height: '192rpx',
            },
          }
        ],
      }
    })
  },
  onImgOK(e){
    console.log('onImgOK',e.detail.path)
    wx.getImageInfo({
      src:e.detail.path,
      success:res=>{
        let w=getApp().system.windowWidth
        console.log('getImageInfo',res)
        this.setData({
          paletteImageWidth:w,
          paletteImageHeight:w/res.width*res.height,
          paletteImageSrc:e.detail.path,
        })
      }
    })
  },
  reviewImage(){
    wx.previewImage({
      urls:[this.data.paletteImageSrc],
    })
  }
})