const app = getApp();
const template = require('../../template/templates.js');
Page({
/**
* 页面的初始数据
*/
data: {
hidden: true,
dataList: {
img_bg: '../../img/share_picture/shareListPicbg1.jpg',
title: '',
img: '',
qrCodeUrl: '',
plusPrice: null, //PLUS价格
faceValue: null, //代金券面值 },
referrerVOid: null,
saveImgBtnHidden: false,
openSettingBtnHidden: true,
referrerVOidShow: ""
},
getVouchersId: function(vouchersId) {
wx.request({
url: app.data.urls + 'vouchers/detail/id',
data: vouchersId,
method: "POST",
header: {
'content-type': 'application/json' // 默认值
},
success: (res) => {
console.log(res)
let dataList = this.data.dataList,
data = {
status: 1,
customerId: app.data.customerId,
type: 1
}
dataList.name = res.data.data.restaurant.name;
if (dataList.name.length > 10) {
dataList.name = `${dataList.name.substr(0, 9)}...`;
}
let payMoney = res.data.data.deductionPrice / 100,
useDiscountPrice = res.data.data.useDiscountPrice / 100;
//plus价格
let price = res.data.data.vipcardPrice / 100;
//地址 和电话
let address = res.data.data.restaurant.address;
let moblie = `电话:${res.data.data.restaurant.moblie}`;
dataList.address = address
dataList.moblie = moblie dataList.content = `立省${payMoney - price}元`;
dataList.originalCost = `原价:${payMoney}元`;
dataList.realPrice = `${price}元`;
dataList.useDiscountPrice = `( 消费满${useDiscountPrice}元可用 )`;
dataList.deductionPriceShow = `${payMoney}元代金券`;
template.getDistributorMsg(data, res => {
console.log(res)
this.setData({
plusPrice: price,
faceValue: payMoney,
referrerVOidShow: res.data.data.referrerVO.id,
// referrerVOid: res.data.data.referrerVO.id
})
this.referrerGenQRCode(vouchersId, res.data.data.referrerVO.id, res => {
// 获取店铺或者二维码
console.log(res)
let qrCodeUrl = `https://www.yooeepoint.com.cn${res.data.localQrCodeUrl}`; // 小程序二维码
let img = `https://www.yooeepoint.com.cn${res.data.localTitleImageUrl}` // 店铺图片
//背景图片
let vouchers_background = 'https://www.yooeepoint.com.cn/images/vouchers_background.png' this.downLoadImage(qrCodeUrl, res => { // 网络图片下载本地(canvas限制图片使用本地路径)
dataList.qrCodeUrl = res.tempFilePath;
this.downLoadImage(img, res => {
dataList.img = res.tempFilePath;
this.downLoadImage(vouchers_background, res => {
dataList.vouchers_background = res.tempFilePath; //背景图片
this.getSystemInfo(res => {
dataList.windowWidth = res.windowWidth
dataList.windowHeight = res.windowHeight
this.creatCanvas(dataList);
}) }) })
}) })
})
}
})
},
// 绘制分享图片
creatCanvas: function(data) { const ctx = wx.createCanvasContext('shareImg');
//背景图
// ctx.setFillStyle('#fff')
// ctx.fillRect(0, 0, data.windowWidth, data.windowHeight * 0.78)
ctx.drawImage(data.vouchers_background, 0, 0, data.windowWidth, data.windowHeight);
//banner图
//banner图
ctx.drawImage(data.img, 0, 10, data.windowWidth, data.windowHeight * 0.315);
//店铺名称
ctx.setFontSize(data.windowWidth / (750 / 35));
ctx.setTextAlign('center');
ctx.setFillStyle('#000000');
ctx.fillText(data.name, data.windowWidth / 2, data.windowHeight * 0.39 + 6);
//多少元代金券
ctx.setFontSize(data.windowWidth / (750 / 30));
ctx.setTextAlign('center');
ctx.setFillStyle('#000000');
ctx.fillText(data.deductionPriceShow, data.windowWidth / 2, data.windowHeight * 0.39 + 30); // 满减条件
ctx.setFillStyle('#000000');
ctx.setFontSize(data.windowWidth / (750 / 25));
ctx.fillText(data.useDiscountPrice, data.windowWidth / 2, data.windowHeight * 0.39 + 45); //原价
ctx.setFontSize(data.windowWidth / (750 / 22));
ctx.setFillStyle('#666666');
ctx.fillText(data.originalCost, data.windowWidth / 2 + 120, data.windowHeight * 0.50); // 立省
ctx.setFillStyle('#f10c0c');
ctx.setFontSize(data.windowWidth / (750 / 22));
ctx.fillText(data.content, data.windowWidth / 2 + 120, data.windowHeight * 0.50+ 15); // plus价
ctx.setFontSize(data.windowWidth / (750 / 55));
ctx.setFillStyle('#f10c0c');
ctx.fillText(data.realPrice, data.windowWidth / 2, data.windowHeight * 0.60-15 ); // 地址和电话
ctx.setFontSize(data.windowWidth / (750 / 25));
ctx.setFillStyle('#323232');
ctx.fillText(data.address, data.windowWidth / 2, data.windowHeight *0.60+15); ctx.setFontSize(data.windowWidth / (750 / 20));
ctx.setFillStyle('#323232');
ctx.fillText(data.moblie, data.windowWidth / 2, data.windowHeight *0.60+35); // 二维码图
ctx.drawImage(data.qrCodeUrl, data.windowWidth * 0.38-2, data.windowHeight * 0.73, data.windowWidth * 0.25, data.windowWidth * 0.25); // tip
ctx.setTextAlign('center');
ctx.setFillStyle('#fff');
ctx.setFontSize(data.windowWidth / (750 / 22));
ctx.fillText("长按识别图中小程序码购买", data.windowWidth / 2, data.windowHeight * 0.95); // tip
ctx.setTextAlign('center');
ctx.setFillStyle('#fff');
ctx.setFontSize(data.windowWidth / (750 / 18));
ctx.fillText("想要吃点喝点,首选搜城天下", data.windowWidth / 2, data.windowHeight * 0.97); //
// ctx.setTextAlign('right');
// ctx.setFillStyle('#282828');
// ctx.setFontSize(data.windowWidth / (750 / 22));
// ctx.fillText("长按识别二维码", data.windowWidth * 0.89, data.windowHeight * 0.60 + 35);
//结束绘制/展示
ctx.stroke();
ctx.draw(false, () => {
this.toShare();
});
}, // 获取二维码/店铺图片
referrerGenQRCode: function(vouchersId, referrerId, successCallBack) {
let data = {
referrerId: referrerId,
serviceType: 3,
vouchersId: vouchersId
}
wx.request({
url: app.data.urls + `html5/toShareImagePage`,
data: data,
method: 'POST',
success: (res) => {
successCallBack(res)
}
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function(options) {
wx.showLoading({
title: '加载中',
mask: true
});
console.log(options) this.getVouchersId(options.vouchersId)
console.log(options.referrerId)
this.setData({
vouchersId: options.vouchersId,
referrerVOid: options.referrerId,
partnersId: options.partnersId,
isFreeObtain: options.isFreeObtain,
restaurantId: options.restaurantId
})
console.log(this.data.referrerVOid)
// 初始化数据
}, // 动态设置画布宽高
getSystemInfo: function(successCallBack) {
wx.getSystemInfo({
success: (res) => {
successCallBack(res)
}
})
}, // 网络图片下载本地(canvas限制图片使用本地路径)
downLoadImage: function(data, successCallBack) {
wx.downloadFile({
url: data,
success: function(res) {
successCallBack(res)
}
}) },
// 分享图片生成后展示
toShare: function() {
wx.canvasToTempFilePath({
x: 0,
y: 0,
canvasId: 'shareImg',
success: (res) => {
console.log(res)
wx.hideLoading();
this.setData({
prurl: res.tempFilePath,
hidden: false
})
}
})
},
// 分享图片保存到相册
savePic: function() {
let that = this
wx.getSetting({
success: res => {
if (!res.authSetting['scope.writePhotosAlbum']) { //用户同意授权
wx.authorize({
scope: 'scope.writePhotosAlbum',
success: () => {
this.saveImageToPhotosAlbum();
},
fail: () => { //这里是用户拒绝授权后的回调
that.setData({
saveImgBtnHidden: true,
openSettingBtnHidden: false
})
}
})
} else { //用户已经授权过
this.saveImageToPhotosAlbum();
}
}
})
},
saveImageToPhotosAlbum: function() {
wx.saveImageToPhotosAlbum({
filePath: this.data.prurl,
success(res) {
this.onShareAppMessage()
}
})
},
handleSetting: function(e) {
let that = this;
// 对用户的设置进行判断,如果没有授权,即使用户返回到保存页面,显示的也是“去授权”按钮;同意授权之后才显示保存按钮
if (!e.detail.authSetting['scope.writePhotosAlbum']) {
wx.showModal({
title: '提示',
content: '若不打开授权,则无法将图片保存在相册中!',
showCancel: false
})
that.setData({
saveImgBtnHidden: true,
openSettingBtnHidden: false
})
} else {
wx.showModal({
title: '提示',
content: '您已授权,赶紧将图片保存在相册中吧!',
showCancel: false
})
that.setData({
saveImgBtnHidden: false,
openSettingBtnHidden: true
})
}
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function() {
// return {
// title: '【搜城天下】' + this.data.dataList.name,
// path: '/pages/goinSharePic/goinSharePic?vouchersId=' + this.data.vouchersId + "&referrerVOid=" + this.data.referrerVOid,
// imageUrl: this.data.prurl
// }
console.log("kankan" + this.data.referrerVOidShow)
return {
title: '【' + this.data.plusPrice + '元抢购】' + this.data.faceValue + '元代金券',
path: '/pages/vouchersDetails/vouchersDetails?vouchersId=' + this.data.vouchersId + "&referrerId=" + this.data.referrerVOidShow + '&restaurantId=' + this.data.restaurantId + '&isFreeObtain=' + this.data.isFreeObtain + '&partnersId=' + this.data.partnersId,
imageUrl: this.data.prurl
} },
onReady: function() {
wx.hideLoading();
}
})

微信小程序 分享海报的更多相关文章

  1. 关于微信小程序分享/转发功能的实现方法

    实现微信小程序分享,可以有两个入口: 1. 小程序右上角菜单自带的分享 这个入口是默认关闭的,需要在当前页面中调用showShareMenu方法,开启分享 onLoad: function () { ...

  2. golang-vue实现微信小程序分享到朋友圈

    最近涉及到微信小程序分享到朋友圈,不知道微信为什么不直接接口分享,咱也不敢佛,咱也不敢问,只能百度问度娘,看官方文档,网上的一些分享五花八门,每一个重点的,所以整理了一下到底怎样生成二维码分享图片才是 ...

  3. 微信小程序分享转发用法大全——自定义分享、全局分享、组合分享

    官方提供的自定义分享 使用隐式页面配置函数实现的全局分享-推荐 使用隐式路由实现的全局分享-不推荐,仅供了解隐式路由 前言: 目前微信小程序只开放了页面自定义分享的API,为了能够更灵活的进行分享配置 ...

  4. 微信小程序分享至朋友圈的方法

    最近研究怎么实现微信小程序分享至朋友圈,对就是朋友圈. 微信小程序目前没有直接提供方法来将小程序分享至朋友圈,不过可以采用曲线救国的方式来达到目的. 方法分两步: 1.通过浏览器将希望分享的东西风向至 ...

  5. 微信小程序--分享功能

    微信小程序--分享功能 微信小程序前段时间开放了小程序右上角的分享功能, 可以分享任意一个页面到好友或者群聊, 但是不能分享到朋友圈 这里有微信开发文档链接:点击跳转到微信分享功能API 入口方法: ...

  6. 微信小程序分享支持自定义封面图

    微信小程序又发布更新了,刚好昨天支付宝也发布小程序,不能让它抢了风头的节奏.微信小程序主要更新如下:“小程序分享支持自定义封面图,公众号及小程序客服可发送小程序卡片.同时,我们还开放了获取发票抬头,指 ...

  7. 微信小程序--分享报错(thirdScriptError Cannot read property 'from' of undefined;at pages/index/index page onShareAppMessage function TypeError: Cannot read property 'from' of undefined)

    分享功能: onShareAppMessage: function (res) { if (res.from === 'button') { // 来自页面内转发按钮 console.log(res. ...

  8. 微信小程序分享朋友圈的实现思路与解决办法

    实现思路 那么既然小程序没有分享到朋友圈的api,我们怎么实现分享到朋友圈呢,下面我介绍一下实现思路. 既然没有捷径,那就走复杂一点的路线,那就是需要用户手动分享到朋友圈,问题又来了,用户手动分享的话 ...

  9. 微信小程序分享功能的path路径

    表示被微信小程序坑惨了 糟心的开始写,老板说先不上太复杂,就先显示了两个页面,然后开开心心的发布,测试了几遍,没啥问题呀.结果,一上上去,就被老板批了! 啥呀! 这分享怎么这个鬼样子!明明我看文档都是 ...

随机推荐

  1. Mysql 分库分表方案

    0 引言 当一张表的数据达到几千万时,你查询一次所花的时间会变多,如果有联合查询的话,我想有可能会死在那儿了.分表的目的就在于此,减小数据库的负担,缩短查询时间. mysql中有一种机制是表锁定和行锁 ...

  2. 8、Situation-Dependent Combination of Long-Term and Session-Based Preferences in Group Recommendations: An Experimental Analysis ----组推荐中基于长期和会话偏好的情景依赖组合

    一.摘要: 背景:会话组推荐系统的一个主要挑战是如何适当地利用群组成员之间的交互引起用户偏好,这可能会偏离用户的长期偏好.长期偏好和群组诱导的偏好之间的相对重要性应该根据具体的群组设置而变化. 本文: ...

  3. d3基础图形模板笔记

    散点图(scatter plot): http://bl.ocks.org/weiglemc/6185069 雷达图(radar): http://xgfe.github.io/uploads/che ...

  4. 使用命令:ssh-add 时,出现 “Could not open a connection to your authentication agent.”

    为 GitHub 账号设置 SSH Key时, 使用命令:ssh-add,出现“Could not open a connection to your authentication agent”,解决 ...

  5. Flask-Babel 使用简介(翻译文档)

    最近用flask-bable翻译一个项目,在网站上查找到有一个示例文档,地址:http://translations.readthedocs.io/en/latest/flask-babel.html ...

  6. linux内核(三)文件系统

    1.为什么需要根文件系统 (1)init进程的应用程序在根文件系统上(2)根文件系统提供了根目录/(3)内核启动后的应用层配置(etc目录)在根文件系统上.几乎可以认为:发行版=内核+rootfs(4 ...

  7. UVALive 3231 Fair Share

    Fair Share Time Limit: 3000ms Memory Limit: 131072KB This problem will be judged on UVALive. Origina ...

  8. HDU 4240 Route Redundancy

    Route Redundancy Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. Origin ...

  9. POJ3684 Physics Experiment 【物理】

    Physics Experiment Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1031   Accepted: 365 ...

  10. debian mysql 定时自己主动备份的脚本

    #!/bin/sh LOG=/var/log/mysql-backup.log # mysql db info USER_ROOT=XXXXXX USER_PWD=XXXXXXX # mysql da ...