Pārlūkot izejas kodu

[商户详情][新增][生成海报]

tags/江西版6.1.0
luqc pirms 6 gadiem
vecāks
revīzija
0566654617
6 mainītis faili ar 354 papildinājumiem un 60 dzēšanām
  1. Binārs
      assets/images/download.png
  2. +1
    -36
      components/merchantcoupons/index.wxml
  3. +0
    -5
      components/merchantcoupons/index.wxss
  4. +286
    -4
      pages/index/detail/index.js
  5. +28
    -15
      pages/index/detail/index.wxml
  6. +39
    -0
      pages/index/detail/index.wxss

Binārs
assets/images/download.png Parādīt failu

Pirms Pēc
Platums: 200  |  Augstums: 200  |  Izmērs: 6.1 KiB

+ 1
- 36
components/merchantcoupons/index.wxml Parādīt failu

@@ -1,41 +1,6 @@
<navigator url="/pages/coupon/detail/index?couponChannelId={{data.couponChannelId}}&couponId={{data.couponId}}&title={{data.title}}">
<!-- 首页优惠券列表页面 -->
<view class="coupons" wx:if="{{data.targetAd!=2}}">
<view class="coupons-img">
<image src="{{data.coverImg}}" mode='aspectFill' lazy-load="true"></image>
</view>
<view class="coupons-info">
<view class="coupons-info-name tit">{{data.title}}</view>
<view class="coupons-info-name subtitle">{{data.subTitle}}</view>
<view class="coupons-info-price-p">
<view class='price'>
<text>{{data.salePriceStr}}<text style="font-size:24rpx;display:inline-block;margin-right:10rpx;font-weight:400;">元</text></text>
<view class="coupons-info-manjian" style="margin-top:10rpx;" wx:if="{{data.type == 1}}">
<view class='view01' wx:if="{{data.unit==0}}">{{data.priceStr}}元</view>
<view wx:if="{{data.unit==1}}">{{data.priceStr}}小时</view>
<!-- <text class='txt2'>满{{data.usePriceStr}}元可用</text> -->
</view>
<view class="coupons-info-manjian" wx:elif="{{data.type == 2||data.type == 3||data.type==4||data.type==5}}">
<text class='view01' wx:if="{{data.unit==0}}">{{data.priceStr}}元</text>
<text wx:if="{{data.unit==1}}">{{data.priceStr}}小时</text>
<!-- <text class='txt2'>仅限本店使用</text> -->
</view>
</view>
<!-- <view class="coupons-info-manjian1" wx:if="{{data.merchantVoList.length==1}}">{{data.merchantVoList[0].merchantName}}</view>
<view class="coupons-info-manjian1" wx:if="{{data.merchantVoList.length>1}}">多商户通用</view> -->
</view>
</view>
<view class="coupons-btn">
<!-- 优惠券价格 -->
<i-button i-class="coupons-btn-gm" wx:if="{{data.salePriceStr==0&&data.remainInventory!=0}}" data-date='{{data}}'>免费领</i-button>
<i-button i-class="coupons-btn-gm" wx:if="{{data.salePriceStr!=0&&data.remainInventory!=0}}" data-date='{{data}}'>马上购</i-button>
<i-button i-class="coupons-btn-gms" wx:if="{{data.remainInventory==0}}" data-date='{{data}}'>已售罄</i-button>
<i-button i-class="coupons-btn-gms" wx:if="{{data.status==1}}" data-date='{{data}}'>已下架</i-button>
</view>
<!-- <view class="coupons-info-name sy">剩余{{data.remainInventory}}</view> -->
</view>
<!-- 限时抢购 -->
<view class="xianshicoupons" wx:else>
<view class="coupons">
<view class="coupons-img">
<image src="{{data.coverImg}}" mode='aspectFill' lazy-load="true"></image>
</view>


+ 0
- 5
components/merchantcoupons/index.wxss Parādīt failu

@@ -256,9 +256,4 @@ navigator{
}
navigator:nth-of-type(2n+1){
margin-right: 10rpx;
}
/* 限时抢购样式 */
.xianshicoupons{
width: 100%;
position: relative
}

+ 286
- 4
pages/index/detail/index.js Parādīt failu

@@ -11,16 +11,32 @@ Page({
teljpgUrl: imgurl.teljpg.url,
share01: imgurl.share01.url,
actUrl: imgurl.act.url,
poster:'./../../../assets/images/picture.png',
page: 1,
imglist:null,
shopVoList:[],
couponList:[],//活动劵列表
data:{
currentTab: 0,
isshare:false
isshare:false,
showpost: false,
imgHeight: 0,
},
id:null
id:null,
windowWidth: 0,
windowHeight: 0,
totalHeight: 0,
canvasScale: 1.0,// 画布放大的倍数,因为如果保存的是一倍的分享图片的话,分享图会有点虚。所以保存的时候,canvasScale设置为2.0,wxss 里面的left: 500%;打开注释。就可保存两倍的分享图
},
/**
* 分享海报的生成
*/
//关闭海报
closePoste: function() {
this.setData({
showpost: false
})
},

/**
* 生命周期函数--监听页面加载
@@ -37,7 +53,257 @@ Page({
currentTab: 0
})
}
// 获取到屏幕的宽高等信息
wx.getSystemInfo({
success: function(res) {
that.setData({
windowWidth: res.windowWidth,
windowHeight: res.windowHeight
})
}
})
},
/**
* 绘制分享海报
*/
begainDrawShareImage() {
var that = this
// 适配屏幕
let scale = this.data.windowWidth / 375.0
this.setData({ totalHeight: 767* scale})
// 获取Canvas
let ctx = wx.createCanvasContext('myCanvas')

// 放大 因为不放大的话,生成的分享图会模糊。暂时先注释
ctx.scale(this.data.canvasScale, this.data.canvasScale)

// 绘制主背景白色
ctx.setFillStyle('#ffffff')
ctx.fillRect(0, 0, this.data.windowWidth, this.data.totalHeight)
ctx.draw()

// 首先要绘制顶部的背景图片,因为它在最底层,然后才能绘制其他内容
let topImageWidth = parseInt(375 * scale) // 因为小数有时候会请求不到图片,所以转成int
let topImageHeight = parseInt(250 * scale)
let src1 = this.data.data.merchantImgUrl + `?imageView/2/w/${topImageWidth}/h/${topImageHeight}`
wx.getImageInfo({
src: src1,
success: function(res) {
ctx.drawImage(res.path, 0, 0, topImageWidth, topImageHeight)
// 覆盖黑色蒙层
ctx.setFillStyle('rgba(0,0,0,0.3)')
ctx.fillRect(0, 0, topImageWidth, topImageHeight)

ctx.draw(true)

that.drawOtherContent(ctx, scale)
that.drawOtherImage(ctx,scale)
}
})
},

// 绘制除了图片之外的剩余内容
drawOtherContent(ctx, scale) {

// 绘制中间的灰色背景
ctx.setFillStyle('rgba(246,246,246,1)')
//(x轴,y轴,宽,高)
ctx.fillRect(14 * scale, 230 * scale, 347 * scale, 58 * scale)

//name
ctx.setFillStyle('white');
ctx.setFontSize(30 * scale);
this.canvasTextAutoLine(this.data.data.merchantName, ctx, 20 * scale, 200 * scale, 30 * scale, 258 * scale, 1)
// address
ctx.setFillStyle('#000');
ctx.setFontSize(18 * scale);
this.canvasTextAutoLine("地址:"+this.data.data.shopVoList[0].floorName+this.data.data.shopVoList[0].buildingName+this.data.data.shopVoList[0].shopNumber, ctx, 20 * scale, 270 * scale, 22 * scale, 305 * scale, 1)

// this.drawNormalText(ctx, '探索新鲜好去处', 82 * scale, 596 * scale, 14 * scale, '#3C3C3C', 'left', 'middle', scale);
// this.drawNormalText(ctx, '长按右侧小程序码', 82 * scale, 620 * scale, 12 * scale, '#9A9CAC', 'left', 'middle', scale);
// this.drawNormalText(ctx, '查看更多店铺信息和热评', 82 *scale,635*scale, 12*scale, '#9A9CAC', 'left', 'middle', scale);

ctx.draw(true)

},

// 绘制活动图片
drawOtherImage(ctx, scale) {

let that = this
// 如果该商户有活动商品
if(this.data.couponList.length>0){
let cotentImageWidth = parseInt(136 * scale)
let cotentImageHeight = parseInt(136 * scale)
for (let i = 0; i < this.data.couponList.length; i++){
let imageItem = this.data.couponList[i].coverImg
let src1 = imageItem + `?imageView/2/w/${cotentImageWidth}/h/${cotentImageHeight}`
wx.getImageInfo({
src: src1,
success: function (res) {
ctx.drawImage(res.path, 15 * scale + i*180*scale, 300 * scale, cotentImageWidth, cotentImageHeight)
ctx.draw(true)
}
})
}
//没有活动商品生成小程序码
}else{
if(this.data.qrCode){
let coImageWidth = parseInt(336 * scale)
let coImageHeight = parseInt(336 * scale)
let src1 = this.data.qrCode + `?imageView/2/w/${topImageWidth}/h/${topImageHeight}`
wx.getImageInfo({
src: src1,
success: function(res) {
ctx.drawImage(res.path, 0, 0, coImageWidth, coImageHeight)
ctx.draw(true)
}
})
}
}
// icon
// ctx.setShadow(0, 8 * scale, 20, 'rgba(0,0,0,0.1)')
// ctx.drawImage('./../../../assets/images/download.png', 13 * scale, 590 * scale, 54*scale, 54*scale)
// ctx.setShadow(0, 0, 0, 'white')
// ctx.draw(true)
},

// 绘制只有一行的文字
drawNormalText(ctx, str, x, y, font, style, align, baseLine) {
ctx.setFontSize(font);
ctx.setFillStyle(style);
ctx.setTextAlign(align);
ctx.setTextBaseline(baseLine);
ctx.fillText(str, x, y);
},


/*
* 绘制多行文本,自动换行,超出添加...
*
str:要绘制的字符串
canvas:canvas对象
initX:绘制字符串起始x坐标
initY:绘制字符串起始y坐标
lineHeight:字行高,自己定义个值即可
maxWidth: 文本最大宽度
row: 最大行数
*/
canvasTextAutoLine: function(str, ctx, initX, initY, lineHeight, maxWidth, row = 1) {
var lineWidth = 0;
var lastSubStrIndex = 0;
var currentRow = 1;
for (let i = 0; i < str.length; i++) {
lineWidth += ctx.measureText(str[i]).width;
if (lineWidth > maxWidth) {
currentRow++;
let newStr = str.substring(lastSubStrIndex, i)
if (currentRow > row && str.length > i) {
newStr = str.substring(lastSubStrIndex, i - 2) + '...'
}
ctx.fillText(newStr, initX, initY);
initY += lineHeight;
lineWidth = 0;
lastSubStrIndex = i;

if (currentRow > row) {
break;
}
}
if (i == str.length - 1) {
ctx.fillText(str.substring(lastSubStrIndex, i + 1), initX, initY);
}
}
},
// 保存图片
saveImage() {
var _this = this
var image = _this.data.poster

wx.getImageInfo({
src: image,
success: function (sres) {
var imgSrc = sres.path;
wx.showLoading({
title: '保存中',
mask: true
})
setTimeout(function () {
wx.saveImageToPhotosAlbum({
filePath: imgSrc,
success: function (data) {
// wx.showToast({
// title: '保存成功',
// icon: 'success',
// duration: 2000
// })
console.log(data)
wx.showModal({
title: '友情提示',
content: '图片保存成功,请到相册查找分享',
success(res) {
if (res.confirm) {
} else if (res.cancel) {
}
}
})

},
fail: function (err) {
// console.log(err);
if (err.errMsg === "saveImageToPhotosAlbum:fail auth deny") {
console.log("当初用户拒绝,再次发起授权")
wx.openSetting({
success(settingdata) {
console.log(settingdata)
if (settingdata.authSetting['scope.writePhotosAlbum']) {
console.log('获取权限成功,给出再次点击图片保存到相册的提示。')
} else {
console.log('获取权限失败,给出不给权限就无法正常使用的提示')
}
}
})
}
},
complete(res) {
console.log(res);
}
})
wx.hideLoading();
}, 2000)






}

})

},
/**
* 获取access_token
*/
getaccess_token:function(access_token){
wx.request({
url:"https://api.weixin.qq.com/wxa/getwxacode?access_token=" + access_token,
method: 'POST',
data: {
path: 'pages/index/index', // 必须是已经发布的小程序存在的页面(否则报错)
width: 430,
auto_color: false,// 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调
line_color: {"r":"0","g":"0","b":"0"} // auto_color 为 false 时生效,使用 rgb 设置颜色 例如 {"r":"xxx","g":"xxx","b":"xxx"} 十进制表示
},
success:function(res){
console.log(res);
}
})
},
/**
* 拨打电话
*/
@@ -68,6 +334,23 @@ Page({
this.setData({
currentTab: e.detail.current
});
},
/**
* 隐藏分享海报
*/
hideposter:function(){
this.setData({
showpost: false,
})
},
/**
* 显示分享海报
*/
showPoster:function(){
this.setData({
showpost: true,
})
this.begainDrawShareImage();
},
//点击切换
clickTab: function (e) {
@@ -127,7 +410,7 @@ Page({
data: data
}).then(res => {
that.setData({
couponList: res.data,
couponList: res.data.list,
})
})
.catch(err => {
@@ -154,7 +437,6 @@ Page({

},
onShareAppMessage: function (res) {
debugger
var that = this;
var shareObj = {
title: that.data.data.title,


+ 28
- 15
pages/index/detail/index.wxml Parādīt failu

@@ -1,4 +1,4 @@
<!--pages/index/detail/index.wxml-->
<!-- pages/index/detail/index.wxml -->
<view>
<swiper class="index-slide" autoplay="true" circular="false">
<block wx:for="{{imglist}}" wx:key="unique">
@@ -19,7 +19,6 @@
</view>
<view class='fenxiang' wx:if="{{data.type!=50&&data.type!=51}}" bindtap='showshare'>
<image class="fenxiang" src='{{share01}}' mode="widthFix"></image>
</view>
</view>
<!-- 一个商铺 -->
@@ -30,7 +29,9 @@
<text>商户位置</text>
</view>
<view class='merchants'>
<text wx:for="{{shopVoList}}" wx:key="{{index}}">{{item.buildingName}}{{item.floorName}}--{{item.shopNumber}}</text>
<text wx:for="{{shopVoList}}" wx:key="{{index}}">
{{item.buildingName}}{{item.floorName}}--{{item.shopNumber}}
</text>
</view>
</view>
</view>
@@ -49,15 +50,17 @@
<!-- 商户简介 -->
<view class='merchant-phones'>
<view class="swiper-tab">
<view class="swiper-tab-item {{currentTab==0?'active-tab':''}}" data-current="0" bindtap="clickTab">优惠信息</view>
<view class="swiper-tab-item {{currentTab==1?'active-tab':''}}" data-current="1" bindtap="clickTab">商家简介</view>
<view class="swiper-tab-item {{currentTab==0?'active-tab':''}}" data-current="0" bindtap="clickTab">
优惠信息
</view>
<view class="swiper-tab-item {{currentTab==1?'active-tab':''}}" data-current="1" bindtap="clickTab">
商家简介
</view>
</view>
<!--   <swiper current="{{currentTab}}" duration="300" bindchange="swiperTabView"> -->
<!-- <swiper current="{{currentTab}}" duration="300" bindchange="swiperTabView"> -->
<view class='swiperactive'>
<!-- 商户对应的活动 -->

<view wx:if="{{currentTab==0}}">

<view class='coupons clearfix'>
<c-coupons wx:if="{{couponList.length!=0}}" wx:for="{{couponList}}" paramAtoB="{{loading}}" wx:key="unique" data="{{item}}" list="{{couponList}}" />
</view>
@@ -67,36 +70,46 @@
<text>我们正在筹备一大波优惠活动</text>
</view>
<view class="loading" wx:if="{{loading}}">
<image src="{{loadingUrl}}" mode="widthFix"></image>{{content}}</view>
<image src="{{loadingUrl}}" mode="widthFix"></image>
{{content}}
</view>
<view class='loadingtext' wx:if="{{loadingtext}}">{{loadingtext}}</view>
</view>
<!-- 商户简介 -->

<view wx:elif="{{currentTab==1}}">
<text wx:if="{{data.summary}}">{{data.summary}}</text>
<text wx:else>{{"信息完善中,敬请期待。"}}</text>    </view>
<text wx:else>{{"信息完善中,敬请期待。"}}</text>
</view>
</view>
<!--   </swiper> -->
<!-- </swiper> -->
<view class='merchant-info'>
<view hidden='currentTabsIndex!=0'>
<text wx:if="{{data.summary}}">{{data.summary}}</text>
</view>

</view>
</view>
<!-- 分享弹框 -->
<view class='modal' wx:if="{{isshare}}" bindtap='hidemodal'>
<view class='modal-content'>
<view>
<button class='share user-motto' data-id='{{data.id}}' data-couponId='{{data.couponId}}' data-title='{{data.title}}' id="shareBtn" open-type="share" hover-class="other-button-hover"></button>
<button class='share user-motto' data-id='{{data.id}}' data-couponId='{{data.couponId}}' data-title='{{data.title}}' id="shareBtn" open-type="share" hover-class="other-button-hover"></button>
<image src='./../../../assets/images/wechat.png' mode='aspectFit'></image>
<text>微信好友</text>
</view>
<view>
<view bindtap='showPoster'>
<image src='./../../../assets/images/picture.png' mode='aspectFit'></image>
<text>生成海报</text>
</view>
</view>
</view>
<!-- 分享海报 -->
<view class='postermodal' wx:if="{{showpost}}" bindtap='hideposter'>
<canvas canvas-id='myCanvas' class='canvas-content' style='height:{{totalHeight * canvasScale}}px;width:{{375*canvasScale}}px'>
<cover-view class='save-button' bindtap='saveImage'>
<cover-image src="./../../../assets/images/download.png" class="share-image"></cover-image>
</cover-view>
</canvas>
</view>
</view>

</view>

+ 39
- 0
pages/index/detail/index.wxss Parādīt failu

@@ -224,6 +224,7 @@ position:fixed;
}
.swiperactive{
min-height: 300rpx;
margin-bottom:20rpx;
}
/* modal */
.modal{
@@ -266,4 +267,42 @@ position:fixed;
margin-top: 30rpx;
width: 100rpx;
height: 100rpx;
}
/*分享海报样式*/
.canvas-content{
display: flex;
top: 0;
left: 0;
/* left: 500%; 分享图不显示在页面上面,就将画布设置在页面之外*/
}

.save-button {
position: fixed;
width: 80rpx;
height: 80rpx;
bottom: 40rpx;
right: 40rpx;
border-radius: 50rpx;
z-index: 200;
background: rgba(0, 0, 0, 0.75);
}

.save-button .share-image {
position: absolute;
top: 22rpx;
left: 22rpx;
width: 36rpx;
height: 36rpx;
}
/*分享海报蒙层*/
.postermodal{
width: 100%;
height: 100%;
position: fixed;
top: 0;
left: 0;
background: rgba(0,0,0,0.5);
overflow: hidden;
z-index: 50;
color: #fff;
}

Notiek ielāde…
Atcelt
Saglabāt