邓平艺 5 years ago
parent
commit
36815edf28
  1. 83
      pages/goodsDetail/index.vue

83
pages/goodsDetail/index.vue

@ -157,7 +157,7 @@
this.s_id = options.share_id || ''
this.getGoodsDetail();
this.getWxCode()
this.getBackground()
// this.getBackground()
},
methods: {
getBackground() {
@ -176,6 +176,20 @@
}
})
},
//
getGoodsBackground() {
let _this = this
let goods = _this.goods_detail;
let imageUrl = goods.share_cover || goods.cover;
wx.getImageInfo({
src: imageUrl,
success: function(sres) {
_this.goodShare = sres.path
console.log('商品分享图',_this.goodShare)
}
})
console.log('商品分享图',_this.goodShare)
},
//
bindGoods() {
var _this = this;
@ -240,20 +254,59 @@
var context = wx.createCanvasContext('mycanvas');
let goods = that.goods_detail;
let title = goods.name;
let imageUrl = goods.share_cover || goods.cover;
var path = that.backgroundImg;
let price = '¥'+goods.specs[0].selling_price;
//
// var path = that.backgroundImg;
context.setFillStyle("#fff")
context.fillRect(0, 0, 375, 600)
let goodsBackground = that.goodShare
// context.drawImage(path, 0, 0, 375, 667);
context.drawImage(path, 0, 0, 375, 667);
context.drawImage(goodsBackground, 10, 10, 355, 300);
//
let wxcode = that.onceCode
context.drawImage(wxcode, 18, 530, 120, 120);
//
// context.setFontSize(24);
// context.setFillStyle('#fff');
// context.setTextAlign('center');
// context.fillText(title, 34, 620);
context.drawImage(wxcode, 238, 440, 120, 120);
let message = '长按识别小程序码'
context.setFontSize(16);
context.setFillStyle('#999');
context.setTextAlign('center');
context.fillText(message,300,580);
//
context.setFontSize(30);
context.setFillStyle('#FF0000');
context.setTextAlign('center');
context.fillText(price,50, 450);
console.log('长度',title.length)
if(title.length < 18 ) {
context.fillText(title, 10, 350);
}else if(18<title.length && title.length<36) {
console.log('1111')
let before = title.substr(0,18)
let last = title.substr(18,title.length)
//
context.setFontSize(20);
context.setFillStyle('#222');
context.setTextAlign('left');
context.fillText(before, 10, 350);
context.fillText(last, 10, 374);
}else if(title.length > 36) {
console.log('22222')
console.log(title.substr(18,41))
let before = title.substr(0,18)
let last = title.substr(18,28)
let last1 = title.substr(36,title.length)
//
context.setFontSize(20);
context.setFillStyle('#222');
context.setTextAlign('left');
context.fillText(before, 10, 350);
context.fillText(last, 10, 374);
context.fillText(last1, 10, 398);
}
context.stroke();
context.draw();
//
@ -309,13 +362,14 @@
wx.hideToast()
console.log(that.onceCode)
console.log(that.backgroundImg)
if(that.onceCode&&that.backgroundImg) {
if(that.onceCode) {
that.createNewImg()
}else if(!that.onceCode){
this.$msg('小程序码生成失败!')
}else if(!that.backgroundImg){
this.$msg('海报背景图生成失败!')
}
// else if(!that.backgroundImg){
// this.$msg('!')
// }
},
//
getGoodsDetail() {
@ -327,6 +381,7 @@
this.goods_detail = res.data;
if(this.goods_detail) {
this.getGoodsBackground()
if(this.pt == 2) {
this.bindGoods()
}

Loading…
Cancel
Save