twt 2 years ago
parent
commit
4a63b5b878
5 changed files with 446 additions and 10 deletions
  1. 7 0
      pages.json
  2. 1 1
      pages/activity/jkDetail.vue
  3. 65 8
      pages/shop/goodsDetail.vue
  4. 1 1
      pages/shop/shop.vue
  5. 372 0
      pages/shop/wp.vue

+ 7 - 0
pages.json

@@ -362,6 +362,13 @@
 				"navigationBarTitleText": "兑换记录",
 				 "enablePullDownRefresh": true
 			}
+		},
+		{
+			"path": "pages/shop/wp",
+			"style": {
+				"navigationBarTitleText": "海报",
+				 "enablePullDownRefresh": false
+			}
 		}
     ],
 	"tabBar": {

+ 1 - 1
pages/activity/jkDetail.vue

@@ -65,7 +65,7 @@
 				</view>
 			</view> -->
 		</view>
-		<view class="detailBOx" v-if="dimgList">
+		<view class="detailBOx" v-if="dimgList.length>0">
 			<view class="detailTitle">活动详情</view>
 			<view class="detailImgBox" v-for="(item,index) in dimgList">
 				<img :src="item.img" alt="" class="detailImg" mode="widthFix">

+ 65 - 8
pages/shop/goodsDetail.vue

@@ -120,14 +120,14 @@
 				<image src="../../static/timg/home.png" mode="" class="bottomImg"></image>
 				<view class="bottomTxt">首页</view>
 			</view>
-			<!-- <view class="bottomImgBox" style="margin-left: 20rpx;" @click="sharewx">
+			 <view class="bottomImgBox" style="margin-left: 20rpx;" @click="sharewx">
 				<image src="../../static/timg/share.png" mode="" class="bottomImg"></image>
 				<view class="bottomTxt">分享</view>
-			</view> -->
-			<button open-type="share" class="bottomImgBox shareBtn" >
+			</view> 
+			<!-- <button open-type="share" class="bottomImgBox shareBtn" >
 				<image src="../../static/timg/share.png" mode="" class="bottomImg"></image>
 				<view class="bottomTxt">分享</view>
-			</button>
+			</button> -->
 			<view class="bottomBtn" @click="ljbuy" v-if="!activityEnd&&info.goodsDownTime">立即购买</view>
 			<view class="bottomBtn" @click="ljbuy" v-if="activityEnd&&!info.goodsDownTime">立即购买</view>
 			<view class="bottomBtn2"  v-if="activityEnd&&info.goodsDownTime">抢购结束</view>
@@ -203,6 +203,17 @@
 		</view>
 	</view>
 <!-- 	<view :style="{color:colorX}">asdfas</view> -->
+   <view class="shareBox" v-if="shareShow">
+   	 <view class="shareCont">
+		 <button open-type="share" class="bottomImgBox shareBtn" >
+		 	<image src="../../static/timg/share.png" mode="" class="bottomImg"></image>
+		 	<view class="bottomTxt">分享</view>
+		 </button>
+		 <view @click="gowp">
+			 生成海报
+		 </view>
+	 </view>
+   </view>
 </view>
 </template>
 
@@ -232,11 +243,18 @@
 				shengyuD:1,
 				shengyuH:12,
 				shengyuM:21,
-				//snapup:
+				shareShow:false,
+				ext:'',
+				shareId:'',
 			}
 		},
 		onLoad(opt) {
+			var ext=this.$common.getExtStoreId();
+			this.ext=ext
 			this.id=opt.id;
+			if(opt.shareId){
+				this.shareId=opt.shareId
+			}
 			//this.userInfo = uni.getStorageSync("userInfo");
 			this.userInfo=this.$store.state.userInfo;
 			this.ext=this.$common.getExtStoreId();
@@ -267,8 +285,28 @@
 			}, 2000);
 		},
 		methods: {
+			gowp(){
+				this.$http('openMall/shareQrCode', {
+				  bizType:1,
+				  path:'pages/shop/goodsDetail?id'+this.id+'&shareId='+this.userInfo.openId,
+				  goodsId:this.id,
+				  openId:this.userInfo.openId,
+				  unionId:this.ext.unionId
+				 },'GET').then(res => {
+					 
+				 })
+				var time=''
+				if(this.info.goodsDownTime){
+					var time = this.info.createTime.slice(0,10) + '~' +this.info.goodsDownTime.slice(0,10)
+				}else{
+					
+				}
+				uni.navigateTo({
+					url:'wp?img='+this.info.ImgList[0].url+'&name='+this.info.name+'&time='+time+'&sellingPoint'+this.info.sellingPoint
+				})
+			},
 			sharewx(){
-				
+				this.shareShow=true;
 			},
 			ckShop(){
 				uni.navigateTo({
@@ -386,7 +424,7 @@
 					data: that.info,
 					 success: function () {
 					   uni.navigateTo({
-					   	url:'confirm?itemQty='+that.goodsnum+'&shopID='+that.shopInfo.shopId+'&shopName='+that.shopInfo.shopName
+					   	url:'confirm?itemQty='+that.goodsnum+'&shopID='+that.shopInfo.shopId+'&shopName='+that.shopInfo.shopName+'&shareId='+that.shareId
 					   })
 					 }
 				}); 
@@ -444,7 +482,7 @@
 			return {
 				title: this.info.name,
 				imageUrl:img,
-				path: 'pages/shop/goodsDetail?id=' + this.id,
+				path: 'pages/shop/goodsDetail?id=' + this.id+'&shareId='+this.userInfo.openId,
 				success(res){
 					uni.showToast({
 						title:'分享成功'
@@ -463,6 +501,25 @@
 </script>
 
 <style scoped lang="less">
+.shareBox{
+	width: 100%;
+	height: 100vh;
+	background: rgba(0, 0, 0, 0.5);
+	position: fixed;
+	left: 0;
+	bottom: 0;
+	z-index: 11;
+}
+.shareCont{
+	width: 100%;
+	background: #FFFFFF;
+	position: absolute;
+	left: 0;
+	bottom: 0;
+	display: flex;
+	justify-content: space-around;
+	padding: 50rpx 0;
+}
 .timeTbox{
 		width: 750rpx;
 		height: 60rpx;

+ 1 - 1
pages/shop/shop.vue

@@ -77,7 +77,7 @@
 	   				   	</view>
 	   				   	<view class="Sold" >
 	   				   		<view v-if="item.showLabel&&item.showLabel.indexOf('3')!=-1">
-	   				   			已售 {{item.saleQty}}
+	   				   			已售 {{item.saleQty>0?item.saleQty:0}}
 	   				   		</view>
 	   				   	</view>
 	   				   </view>

+ 372 - 0
pages/shop/wp.vue

@@ -0,0 +1,372 @@
+<template>
+	<view class="box">
+		<view style="padding-top: 100rpx;">
+			<canvas canvas-id="mini_poster" style="width: 600rpx;height: 817rpx;margin-left: 73rpx;"></canvas><!-- :style="{ width: canvasW + 'px', height: canvasH + 'px' }" -->
+		</view>
+		<view style="height: 106rpx;"></view>
+		<!-- <view class="footer">
+			<view style="height: 106rpx; align-items: center; background-color: #333333;">
+				<button style="background: transparent; height: 106rpx; line-height: 106rpx;" @tap="toSaveImage">保存名片</button>
+			</view>
+		</view> -->
+		<view class="downloadBtn" @click="toSaveImage">保存图片</view>
+	</view>
+</template>
+
+<script>
+	export default {
+		data() {
+			return {
+				mpWxQr: "http://dmsphoto.66km.com.cn/marketing/F520E658D4A649B88DF210EA41432A01.png",
+				canvasW: 0,
+				canvasH: 0,
+				invest_areas: [{id: 1, name: "儿童教育"}, {id: 1, name: "少儿编程"}, {id: 1, name: "生物智能"}, {id: 1, name: "万物相连"}, {id: 1, name: "大数据"}],
+				nickname: "",
+				avatar: "",
+				company: "",
+				phone: "17610998099",
+				email: "redoume@163.com",
+				time: "2022.01.21~2022.01.2",
+				finished: false,
+				sellingPoint:'',
+			}
+		},
+		computed: {
+			showInvestAreas() {
+				if (this.invest_areas) {
+					const names = []
+					this.invest_areas.forEach(item => {
+						names.push(item.name)
+					})
+					return names.join(" ")
+				}
+				return '未设置'
+			}
+		},
+		onLoad(opt) {
+			//this.canvasW = uni.getSystemInfoSync().windowWidth
+			//this.canvasH = this.calculateCanvasHeight()
+			this.avatar=opt.img;
+			this.nickname=opt.name;
+			if(opt.sellingPoint){
+				this.sellingPoint=opt.sellingPoint;
+			}
+			
+			console.log(this.sellingPoint)
+			if(this.nickname.length>18){
+				this.nickname=this.nickname.substring(0,18)+'...'
+			}
+			this.canvasW =uni.upx2px(600)
+			this.canvasH = uni.upx2px(827)
+			this.toDrawCanvas()
+		},
+		methods: {
+			toSaveImage() {
+				if (!this.finished) {
+					uni.showToast({
+						title: '正在生成图片,稍后再试',
+						icon: 'none'
+					})
+					return
+				}
+				const that = this
+				uni.canvasToTempFilePath({
+					canvasId: 'mini_poster',
+					success: (res) => {
+						uni.saveImageToPhotosAlbum({
+							filePath: res.tempFilePath,
+							success: () => {
+								uni.showToast({
+									title: '保存成功'
+								})
+							},
+							fail() {
+								uni.showToast({
+									icon: 'none',
+									title: '保存名片码失败'
+								})
+							}
+						})
+					},
+					fail() {
+						uni.showToast({
+							icon: 'none',
+							title: '保存名片码失败'
+						})
+					}
+				})
+			},
+			async toDrawCanvas() {
+				const padding = uni.upx2px(34)
+				const cardHeight = uni.upx2px(380)
+				const cw = this.canvasW - 2 * padding
+
+				let ctx = uni.createCanvasContext('mini_poster', this)
+
+				// 透明背景
+				// ctx.setFillStyle('rgba(255, 255, 255, 0)')
+				ctx.setFillStyle('#FFFFFF')
+				ctx.fillRect(0, 0, this.canvasW, this.canvasH)
+				// draw card round rect
+				const r = uni.upx2px(12)
+				this.drawRoundRect(ctx, padding, padding, cw, cardHeight, r, 2)
+				// draw card content
+				this.drawCard(ctx, padding, padding, cw, cardHeight)
+				// draw avatar
+				const av = uni.upx2px(540)
+				const topimgh = uni.upx2px(317)
+				//console.log(av)
+				//console.log(topimgh)
+				const hi = await this.downloadImage(this.avatar)
+				if (hi.tempFilePath) {
+					const x =  uni.upx2px(30) 
+					const y =  uni.upx2px(30)
+					this.drawRoundRectAvatar(ctx, x, y, av, topimgh, r, hi.tempFilePath)
+					
+				}
+				// draw hello info
+				//this.drawHelloInfo(ctx, padding, padding + cardHeight + padding, cw)
+				// draw qr code
+				if (this.mpWxQr) {
+					
+					const hello = await this.downloadImage(this.mpWxQr)
+					//const padding = uni.upx2px(34)
+					//const av = uni.upx2px(180)
+					//const totalH = this.calculateCanvasHeight()
+					//console.log("totalH=="+totalH)
+					console.log(hello.tempFilePath)
+					var wxsx=uni.upx2px(68)
+					var wxsy=uni.upx2px(649)
+					var wxwidth=uni.upx2px(148)
+					if (hello.tempFilePath) {
+						ctx.drawImage(hello.tempFilePath, wxsx, wxsy, wxwidth,wxwidth)
+					}
+				}
+				ctx.draw()
+				this.finished = true
+			},
+			async drawCard(ctx, x, y, w, h) {
+				// draw company
+				//let vp = y + uni.upx2px(45)
+				//const hp = x + uni.upx2px(52)
+				let vp =  uni.upx2px(400)
+				const hp = uni.upx2px(52)
+				ctx.setTextBaseline('center')
+				const fz30 = uni.upx2px(32)
+				ctx.fillStyle = '#212121'
+				ctx.setFontSize(fz30)
+                ctx.fillText(this.nickname, hp, vp)
+				var timeX=hp;
+				var timeY=vp+30
+				
+				const fz26 = uni.upx2px(26)
+				ctx.setFillStyle('#3C3C3C')
+				ctx.setFontSize(fz26)
+				ctx.fillText(this.time, timeX, timeY)
+				var sm=this.sellingPoint
+				ctx.setFillStyle('#999999')
+				ctx.setFontSize(fz26)
+				var smy=timeY+20
+				var maxwidth = uni.upx2px(550)
+				if(sm.length>20){
+					var sm1=sm.substring(0,20)
+					ctx.fillText(sm1, timeX, smy)
+					if(sm.length>40){
+						var sm2=sm.substring(20,40)
+						ctx.fillText(sm2, timeX, smy+20)
+						var sm3=sm.substring(40,60)
+						ctx.fillText(sm3, timeX, smy+40)
+					}else{
+						var sm2=sm.substring(20,40)
+						ctx.fillText(sm2, timeX, smy+20)
+					}
+				}else{
+					ctx.fillText(sm, timeX, smy)
+				}
+				
+				
+				var wemtis1='名额有限 先到先得'
+				var wemtisx=uni.upx2px(240)
+				var wemtisy=uni.upx2px(700)
+				ctx.setFillStyle('#999999')
+				const fz24 = uni.upx2px(24)
+				ctx.setFontSize(fz24)
+				ctx.fillText(wemtis1,wemtisx,wemtisy)
+				var wemtis2='长按二维码识别参与活动'
+				var wemtisy2=wemtisy+30
+				ctx.fillText(wemtis2,wemtisx,wemtisy2)
+				// draw nickname
+				vp = vp + 30
+				
+				
+
+				vp = vp + 42
+				const iconW = uni.upx2px(30)
+				const textH = hp + iconW + 6
+				
+				ctx.setFillStyle('#333333')
+				ctx.setFontSize(fz30)
+				
+
+				vp = vp + 28
+				
+				ctx.setFillStyle('#333333')
+				ctx.setFontSize(fz30)
+				// ctx.fillText(this.showInvestAreas, textH, vp)
+				const oPadding = uni.upx2px(34)
+				const iPadding = uni.upx2px(40)
+				const textW = w - textH + oPadding - iPadding
+				//this.drawTextInOneLine(ctx, this.showInvestAreas, textH, vp, textW)
+
+				vp = vp + 28
+				
+				ctx.setFillStyle('#333333')
+				ctx.setFontSize(fz30)
+				//ctx.fillText(this.phone ? this.phone : '', textH, vp)
+			},
+			async drawHelloInfo(ctx, x, y, w) {
+				let vp = y + 12
+				const hp = x
+				ctx.setTextBaseline('top')
+				const fz30 = uni.upx2px(30)
+				ctx.setFillStyle('#333333')
+				ctx.setFontSize(fz30)
+				ctx.fillText('您好,', hp, vp)
+				const text = "我是来自 " + this.company + ' 的投资人' + this.nickname
+				const lines = this.drawTextInLines(ctx, text, hp, vp, w, 26)
+				vp += 26 * lines + 26
+				ctx.fillText('这是我的名片,请惠存。', hp, vp)
+				vp += 26
+				ctx.fillText('谢谢', hp, vp)
+
+				vp += 26
+				vp += 40
+				ctx.setFillStyle('#F37231')
+				ctx.fillRect(hp, vp, 20, 3)
+				vp += 7
+				ctx.setFillStyle('#333333')
+				const fz28 = uni.upx2px(28)
+				ctx.setFontSize(fz28)
+				ctx.fillText('长按识别二维码', hp, vp)
+				vp += 20
+				const ttt = '在大天使中查看我的更多信息'
+				ctx.fillText(ttt, hp, vp)
+			},
+			calculateCanvasHeight() {
+				// 400 is card height
+				const ctx = uni.createCanvasContext('test_poster')
+				const padding = uni.upx2px(34)
+				const text = "我是来自 " + this.company + ' 的投资人' + this.nickname
+				const rows = this.drawTextInLines(ctx, text, padding, 0, this.canvasW - 2 * padding, 26)
+				const cardH = uni.upx2px(380)
+				const h = padding * 2 + cardH + padding + 12 + 26 * 3 + rows * 26
+				return h + 90
+			},
+			_drawRoundRect(ctx, x, y, w, h, r) {
+				ctx.beginPath()
+				// 左上角
+				ctx.arc(x + r, y + r, r, Math.PI, Math.PI * 1.5)
+				// 右上角
+				ctx.arc(x + w - r, y + r, r, Math.PI * 1.5, Math.PI * 2)
+				// 右下角
+				ctx.arc(x + w - r, y + h - r, r, 0, Math.PI * 0.5)
+				// 左下角
+				ctx.arc(x + r, y + h - r, r, Math.PI * 0.5, Math.PI)
+				ctx.closePath()
+				// ctx.strokeStyle = '#D8D8D8';
+				ctx.fillStyle = '#FFFFFF';
+				// ctx.stroke()
+				ctx.fill()
+			},
+			drawRoundRect(ctx, x, y, w, h, r, lineWidth) {
+				ctx.save()
+				//this._drawRoundRect(ctx, x, y, w, h, r)
+				ctx.clip()
+				// draw left border
+				ctx.fillStyle = '#EEEEEE'
+				var y=uni.upx2px(619)
+				var bWidth=uni.upx2px(600)
+			    ctx.fillRect(0, y, bWidth, 2)
+				ctx.restore()
+			},
+			drawRoundRectAvatar(ctx, x, y, w, h, r, imgPath) {
+				ctx.save()
+				this._drawRoundRect(ctx, x, y, w, h, r)
+				ctx.clip()
+				ctx.drawImage(imgPath, x, y, w, h)
+				ctx.restore()
+			},
+			// TODO: measureText not works in App
+			drawTextInLines(ctx, t, x, y, w, lineHeight) {
+				const chr = t.split("")
+				let temp = ''
+				let row = []
+				for (let i = 0; i < chr.length; i++) {
+					if (ctx.measureText(temp).width < w) {
+						//
+					} else {
+						row.push(temp)
+						temp = ''
+					}
+					temp += chr[i]
+				}
+				row.push(temp)
+				for (const i in row) {
+					// i + 1 will be 11, 21,...
+					ctx.fillText(row[i], x, (y + (i * 1 + 1) * lineHeight))
+				}
+				return row.length
+			},
+			// TODO: measureText not works in app
+			drawTextInOneLine(ctx, t, x, y, w) {
+				const chr = t.split('')
+				let temp = ''
+				for (let i = 0; i < chr.length; i++) {
+					if (ctx.measureText(temp + '...').width <= w) {
+						temp += chr[i]
+					} else {
+						temp = temp.substring(0, temp.length - 1)
+						temp += '...'
+						break
+					}
+				}
+				ctx.fillText(temp, x, y)
+			},
+			downloadImage(url) {
+				return new Promise((resolve, reject) => {
+					uni.downloadFile({
+						url: url,
+						success: (res) => {
+							return resolve(res)
+						},
+						fail: (err) => {
+							return reject(err)
+						}
+					})
+				})
+			}
+		}
+	}
+</script>
+
+<style scoped>
+	.box{
+		width: 100%;
+		height: 100vh;
+		background: url('http://dmsphoto.66km.com.cn/thFiles/83BDAB66-DD76-4F3A-92B3-F6AF0BA57A9E.png');
+		background-size: 100% 100%;
+	}
+	.downloadBtn{
+		width: 329rpx;
+		height: 92rpx;
+		background: url('http://dmsphoto.66km.com.cn/thFiles/A0CF4704-69A8-4DAC-8943-75F98D1349DD.png');
+		background-size: 100% 100%;
+		line-height: 92rpx;
+		text-align: center;
+		font-size: 28rpx;
+		font-family: PingFangSC-Medium, PingFang SC;
+		font-weight: 500;
+		color: #DC490A;
+		margin: 0 auto;
+	}
+</style>