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. Unity5.X 创建基本的3D游戏场景

    点New(新建懒得写了,反正不是智障应该都会) 创建好的项目会自带一个场景,场景会自带Main Camera (主摄像机),Directional Light (方向光)   系统自带几个可以创建的3 ...

  2. vue2.0变化(转载)

    原文链接:https://www.cnblogs.com/itbainianmei/p/6062249.html 1.每个组件模板template,不再支持片段代码 之前: <template& ...

  3. layui select change

    <select lay-filter="test"></select> layui.use([ 'form'], function() { var form ...

  4. Laravel源码解析之反射的使用

    前言 PHP的反射类与实例化对象作用相反,实例化是调用封装类中的方法.成员,而反射类则是拆封类中的所有方法.成员变量,并包括私有方法等.就如"解刨"一样,我们可以调用任何关键字修饰 ...

  5. shell 键盘录入和运算

    一.read 命令,从键盘读入数据,赋给变量 1.脚本代码 #!/bin/sh read arg1 arg2 echo "第一个参数: $arg1" echo "第二个参 ...

  6. Spring注解+Axis2开发WebService

    用Spring注解方式: 配置扫描指定包下的类 <context:component-scan base-package="包名" />   标识类为spring管理的 ...

  7. 手写一个节点大小平衡树(SBT)模板,留着用

    看了一下午,感觉有了些了解.应该没有错,有错希望斧正,感谢 #include<stdio.h> #include<string.h> struct s { int key,le ...

  8. Oracle 学习笔记 14 -- 集合操作和高级子查询

    Oracel提供了三种类型的集合操作:各自是并(UNION) .交(INTERSECT). 差(MINUS) UNION :将多个操作的结果合并到一个查询结果中,返回查询结果的并集,自己主动去掉反复的 ...

  9. B树索引与索引优化

    B树索引与索引优化 MySQL的MyISAM.InnoDB引擎默认均使用B+树索引(查询时都显示为“BTREE”),本文讨论两个问题: 为什么MySQL等主流数据库选择B+树的索引结构? 如何基于索引 ...

  10. SpringMVC+Spring+Hibernate框架整合原理,作用及使用方法

    转自:https://blog.csdn.net/bieleyang/article/details/77862042 SSM框架是spring MVC ,spring和mybatis框架的整合,是标 ...