From 021426a6cebeccd0bcca0dc57889f7420d9917fc Mon Sep 17 00:00:00 2001 From: cheng.xu Date: Fri, 17 Jan 2020 09:29:12 +0800 Subject: [PATCH] 助力分享 --- pages/user/assistance/task_assistance.js | 527 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- pages/user/assistance/task_assistance.wxml | 6 +++--- pages/user/assistance/task_assistance.wxss | 4 +++- 3 files changed, 274 insertions(+), 263 deletions(-) diff --git a/pages/user/assistance/task_assistance.js b/pages/user/assistance/task_assistance.js index 739b1cd..72ddae2 100644 --- a/pages/user/assistance/task_assistance.js +++ b/pages/user/assistance/task_assistance.js @@ -32,10 +32,11 @@ Page({ dismantle: null, //帮拆记录数据集 is_user_task: null, //判断是不是领取的任务 zzjx_id: "", //真正进行的任务id - is_show:0,//任务的加载更多 - is_bc_show:0,//帮拆的加载更多 - bc_page:1,//帮拆的页码 - rw_page:1,//任务的页码 + is_show: 0, //任务的加载更多 + is_bc_show: 0, //帮拆的加载更多 + bc_page: 1, //帮拆的页码 + rw_page: 1, //任务的页码 + block: 0, //阻断助力的用户图片多次添加 //*********************************************start钱 canvasHidden: 0, //分享图片是否已经生成 is_share: 0, //是否显示画布 @@ -46,12 +47,12 @@ Page({ "miniapp/images/friendhelp/check.png", "miniapp/images/friendhelp/unfinished.png", "/public/upload/libao/temp/2019/12-20/51f251f44ea0f67b8efdc5bfa3a434b0.jpg" ], //固的分享图片 - - dynamic: null, //已助力的微信头像数组 - head_pic_arr:[],//助力的头像 - share_lb_img:"",//分享的礼包图片 - - + + dynamic: null, //已助力的微信头像数组 + head_pic_arr: [], //助力的头像 + share_lb_img: "", //分享的礼包图片 + + is_generate: 0, //是否重复点击拆一拆 already: 0, //已有几人助力 lack: 0, //还差几人助力 @@ -80,7 +81,7 @@ Page({ th.close(); th.syinfo(); th.imageinfo(); - + }, @@ -100,7 +101,7 @@ Page({ function(res) { if (res.data.code == 0) { getApp().my_warnning(res.data.data, 1, th); - //判断是不是领取的任务 + //判断是不是领取的任务 th.get_user_task(); //会员任务列表 th.user_task_list(); @@ -146,11 +147,11 @@ Page({ //任务时间 设置全局定时器 th.setData({ - timer:setInterval(function () { + timer: setInterval(function() { th.countDown(); }, 1000) }) - + } } @@ -206,7 +207,7 @@ Page({ //会员任务列表 this.user_task_list(); - //获取助力活动参与的人数 + //获取助力活动参与的人数 this.get_user_task_num(); }, @@ -244,15 +245,16 @@ Page({ success: function(res) { if (res.data.code == 0) { var dismantle = res.data.data.pageData[0].zlHelpUser; - if(res.data.data.total>5){ + if (res.data.data.total > 5) { var bc_page = th.data.bc_page + 1; - th.data({ bc_page: bc_page, - is_bc_show:1 + th.data({ + bc_page: bc_page, + is_bc_show: 1 }) - }else{ - getApp().showWarning("暂无更多内容", 0,th); + } else { + getApp().showWarning("暂无更多内容", 0, th); } - + th.setData({ dismantle: dismantle }); @@ -267,7 +269,7 @@ Page({ }, // 领取礼包 get_libao: function(e) { - var libao_id = e.currentTarget.dataset.libaoid;//礼包id + var libao_id = e.currentTarget.dataset.libaoid; //礼包id getApp().goto("/pages/user/assistance/giftpacklist?libao_id=" + libao_id + "&is_libao=" + 1); }, //查看礼包id @@ -321,18 +323,18 @@ Page({ }); var help_id = th.data.help_id; var user_id = getApp().globalData.user_id; - var rw_page=th.data.rw_page; + var rw_page = th.data.rw_page; rq.get("/api/weshop/marketing/help/help/user/page", { data: { - page:rw_page, - pageSize:5, + page: rw_page, + pageSize: 5, helpId: help_id, storeId: os.stoid, userId: user_id }, success: function(su) { if (su.data.code == 0) { - if (su.data.data.total > 5){ + if (su.data.data.total > 5) { var rw_page = th.data.rw_page + 1; th.setData({ rw_page: rw_page, @@ -341,7 +343,7 @@ Page({ getApp().my_warnning(); getApp().showWarning("暂无更多内容", 0); } - + var user_list = su.data.data.pageData; th.setData({ user_task_list: user_list @@ -522,7 +524,7 @@ Page({ sec: '00' } } - var txt = "aitem[" +0+ "].djs"; + var txt = "aitem[" + 0 + "].djs"; th.setData({ [txt]: obj }); @@ -573,163 +575,166 @@ Page({ } }) }, - - - + + + //************************ */ - shareFrends: function(e) { - var th = this; - if(th.data.is_generate) return ; - th.data.is_generate=1; - - var scene = 1; - ///二微码 - var path3 = os.url + "/api/wx/open/app/user/getWeAppEwm/" + - os.stoid + "?sceneValue=" + scene + "&pageValue=pages/index/index/index"; - //读取文件成功则OK-- - wx.getImageInfo({ - src: path3, - success: function(res) { - - var ewm_path=res.path; // - //var act_time="2019.06.26 - 2019.07.02"; //活动的时间 - var bg_time=ut.formar_no_full(th.data.dynamic.beginDate); - var end_time=ut.formar_no_full(th.data.dynamic.endDate); - var act_time=bg_time+"-"+end_time; - - - var iurl = th.data.iurl; //图片地址前缀 - const ctx = wx.createCanvasContext('share_id'); //绘图上下文 - var unit = th.data.screenWidth / 750 * 1.35; - var numsize = 20 * unit; //几人助力字体大小 - - var num = th.data.head_pic_arr.length; //已有几位好友助力 - - var aitem = th.data.aitem; //任务的数据集 - var sw_index = th.data.sw_index; //轮播的下标 - //任务id - var help_num = aitem[sw_index].helpNum; - - var q_num = help_num-num; //还差几位好友助力 - var already = num.toString().length + 1; //已有几位好友助力 - var lack = q_num.toString().length + 1; //还差几位好友助力 - - var size=15 * unit; - var imagesize = 40 * unit; //助力人的图片大小 - var left = 74 * unit; //助力人头像跟左边的距离 - var spacing = 12 * unit; //助力人图片间距 - var images = th.data.images; - ctx.drawImage(images[0], 0, 0, 445 * unit, 700 * unit); //分享的背景图片 - ctx.drawImage(images[1], 37 * unit, 185 * unit, 370 * unit, 377 * unit); //分享的背景图片 - - - ctx.drawImage(th.data.share_lb_img, 90 * unit, 231 * unit, 266 * unit, 160 * unit); //分享的礼包的背景图片 - - ctx.setFillStyle("rgb(221,153,116)"); - ctx.setFontSize(size) - ctx.fillText("已有", 77 * unit, 430 * unit); - ctx.setFillStyle("#FF4746"); - ctx.setFontSize(numsize) - ctx.fillText(num + "位", 108 * unit, 430 * unit); - ctx.setFillStyle("rgb(221,153,116)"); - ctx.setFontSize(size) - ctx.fillText("好友助力,还差", 116 * unit + already * numsize * unit, 430 * unit); - ctx.setFillStyle("#FF4746"); - ctx.setFontSize(numsize); - ctx.fillText(q_num + "位", 223 * unit + already * numsize * unit, 430 * unit); - ctx.setFillStyle("rgb(221,153,116)"); - ctx.setFontSize(size); - ctx.fillText("达成助力", 230 * unit + lack * numsize * unit + already * numsize * unit, 430 * unit); - - var c =num / help_num; - ctx.drawImage(images[2], 65 * unit, 445 * unit, 320 * unit, 12 * unit); - ctx.drawImage(images[3], 65 * unit, 445 * unit, 320 * unit * c, 12 * unit); - - - for (var i = 0; i < 6; i++) { - if (i < 0) { - ctx.save(); - ctx.beginPath(); //开始绘制 - ctx.arc(left + imagesize / 2, 505 * unit, imagesize / 2, 0, 2 * Math.PI); - ctx.setLineWidth(4 * unit); - ctx.setStrokeStyle('red'); - ctx.setFillStyle("white"); - ctx.fill(); - ctx.clip(); - ctx.drawImage(head_pic_arr.headPic, left, 505 * unit - imagesize / 2, imagesize, imagesize); - ctx.restore(); //恢复之前保存的绘图上下文 恢复之前保存的绘图上下午即状态 还可以继续绘制 - } else { - // 助力人的头像 - ctx.drawImage(images[4], left, 505 * unit - imagesize / 2, imagesize, imagesize); //分享的背景图片 - - } - left += imagesize + spacing; - } - - - - ctx.setFillStyle("rgb(255,255,255)"); - ctx.setFontSize(size); - ctx.fillText("优惠乐翻天,精彩就在你身边!", 37 * unit, 595 * unit); - ctx.setFillStyle("rgb(255,255,255)"); - ctx.setFontSize(size); - - ctx.fillText(act_time, 37 * unit, 620 * unit); //绘制活动是时间 - ctx.setFillStyle("rgb(255,255,255)"); - ctx.setFontSize(size); - ctx.fillText("长按识别二维码,可帮我助力!", 37 * unit, 660 * unit); - ctx.drawImage(ewm_path, 325 * unit, 585 * unit, 77 * unit, 77 * unit); //分享的背景图片 - ctx.save(); - //读取文件成功则OK-- - // wx.getImageInfo({ - // src: path3, - // success: function (res) { - //把画板内容绘制成图片,并回调 画板图片路径 - ctx.draw(false, function() { - setTimeout(function() { - wx.canvasToTempFilePath({ - x: 0, - y: 0, - width: 300, - height: 500, - destWidth: 400 * 2, - destHeight: 720 * 2, - canvasId: 'share_id', - success: function(res) { - wx.hideLoading(); - var shareImgPath = th.data.shareImgPath; - shareImgPath[0] = res.tempFilePath; - - th.setData({ - shareImgPath: shareImgPath, - canvasHidden: 1, - is_share: 1, - is_generate: 0, - canvasHidden: 1 - }) - if (!res.tempFilePath) { - wx.showModal({ - title: '提示', - content: '图片绘制中,请稍后重试', - showCancel: false - }) - return false; - } - - }, - fail(r) { - - } - }, 500) - }) - }) - } - }) - - - }, - - + shareFrends: function(e) { + var th = this; + if (th.data.is_generate) return; + th.data.is_generate = 1; + + var scene = 1; + ///二微码 + var path3 = os.url + "/api/wx/open/app/user/getWeAppEwm/" + + os.stoid + "?sceneValue=" + scene + "&pageValue=pages/index/index/index"; + //读取文件成功则OK-- + wx.getImageInfo({ + src: path3, + success: function(res) { + + var ewm_path = res.path; // + //var act_time="2019.06.26 - 2019.07.02"; //活动的时间 + var bg_time = ut.formar_no_full(th.data.dynamic.beginDate); + var end_time = ut.formar_no_full(th.data.dynamic.endDate); + var act_time = bg_time + "-" + end_time; + + + var iurl = th.data.iurl; //图片地址前缀 + const ctx = wx.createCanvasContext('share_id'); //绘图上下文 + var unit = th.data.screenWidth / 750 * 1.35; + var numsize = 20 * unit; //几人助力字体大小 + var head_list_img = th.data.head_pic_arr; + var num = th.data.head_pic_arr.length; //已有几位好友助力 + + var aitem = th.data.aitem; //任务的数据集 + var sw_index = th.data.sw_index; //轮播的下标 + //任务id + var help_num = aitem[sw_index].helpNum; + var q_num = help_num - num; //还差几位好友助力 + var already = num.toString().length + 1; //已有几位好友助力 + var lack = q_num.toString().length + 1; //还差几位好友助力 + + var size = 15 * unit; + var imagesize = 40 * unit; //助力人的图片大小 + var left = 74 * unit; //助力人头像跟左边的距离 + var spacing = 12 * unit; //助力人图片间距 + var images = th.data.images; + ctx.drawImage(images[0], 0, 0, 445 * unit, 700 * unit); //分享的背景图片 + ctx.drawImage(images[1], 37 * unit, 185 * unit, 370 * unit, 377 * unit); //分享的背景图片 + + + ctx.drawImage(th.data.share_lb_img, 90 * unit, 231 * unit, 266 * unit, 160 * unit); //分享的礼包的背景图片 + + ctx.setFillStyle("rgb(221,153,116)"); + ctx.setFontSize(size) + ctx.fillText("已有", 77 * unit, 430 * unit); + ctx.setFillStyle("#FF4746"); + ctx.setFontSize(numsize) + ctx.fillText(num + "位", 108 * unit, 430 * unit); + ctx.setFillStyle("rgb(221,153,116)"); + ctx.setFontSize(size) + ctx.fillText("好友助力,还差", 116 * unit + already * numsize * unit, 430 * unit); + ctx.setFillStyle("#FF4746"); + ctx.setFontSize(numsize); + ctx.fillText(q_num + "位", 223 * unit + already * numsize * unit, 430 * unit); + ctx.setFillStyle("rgb(221,153,116)"); + ctx.setFontSize(size); + ctx.fillText("达成助力", 230 * unit + lack * numsize * unit + already * numsize * unit, 430 * unit); + var c = num / help_num; + ctx.drawImage(images[2], 65 * unit, 445 * unit, 320 * unit, 12 * unit); + ctx.drawImage(images[3], 65 * unit, 445 * unit, 320 * unit * c, 12 * unit); + var head_list_num = 30; + var is_head_list = 0; + if (help_num < 8) { + // 判断已助力的人数 + + for (var a = 0; a < head_list_img.length; a++) { + ctx.save(); + ctx.beginPath(); //开始绘制 + ctx.arc(left + imagesize / 2, 505 * unit, imagesize / 2, 0, 2 * Math.PI); + ctx.setLineWidth(4 * unit); + ctx.setStrokeStyle('red'); + ctx.setFillStyle("white"); + ctx.fill(); + ctx.clip(); + ctx.drawImage(head_list_img[a], left , 505 * unit - imagesize / 2, imagesize, imagesize); + ctx.restore(); + left += imagesize + spacing; + + } + //这个是还未助力的位置 + for (var i = 0; i < q_num; i++) { + // 助力人的头像 + ctx.drawImage(images[4], left , 505 * unit - imagesize / 2, imagesize, imagesize); //分享的背景图片 + left += imagesize + spacing; + } + } + + + + ctx.setFillStyle("rgb(255,255,255)"); + ctx.setFontSize(size); + ctx.fillText("优惠乐翻天,精彩就在你身边!", 37 * unit, 595 * unit); + ctx.setFillStyle("rgb(255,255,255)"); + ctx.setFontSize(size); + + ctx.fillText(act_time, 37 * unit, 620 * unit); //绘制活动是时间 + ctx.setFillStyle("rgb(255,255,255)"); + ctx.setFontSize(size); + ctx.fillText("长按识别二维码,可帮我助力!", 37 * unit, 660 * unit); + ctx.drawImage(ewm_path, 325 * unit, 585 * unit, 77 * unit, 77 * unit); //分享的背景图片 + ctx.save(); + //读取文件成功则OK-- + // wx.getImageInfo({ + // src: path3, + // success: function (res) { + //把画板内容绘制成图片,并回调 画板图片路径 + ctx.draw(false, function() { + setTimeout(function() { + wx.canvasToTempFilePath({ + x: 0, + y: 0, + width: 300, + height: 500, + destWidth: 400 * 2, + destHeight: 720 * 2, + canvasId: 'share_id', + success: function(res) { + wx.hideLoading(); + var shareImgPath = th.data.shareImgPath; + shareImgPath[0] = res.tempFilePath; + + th.setData({ + shareImgPath: shareImgPath, + canvasHidden: 1, + is_share: 1, + is_generate: 0, + canvasHidden: 1 + }) + if (!res.tempFilePath) { + wx.showModal({ + title: '提示', + content: '图片绘制中,请稍后重试', + showCancel: false + }) + return false; + } + + }, + fail(r) { + + } + }, 500) + }) + }) + } + }) + + + }, + + preview: function() { var th = this; var shareImgPath = th.data.shareImgPath; @@ -761,85 +766,89 @@ Page({ } }) }, - + //把固定的图片加载到本地 - imageinfo:async function() { - var th = this; - var images = th.data.images; - var iurl = th.data.iurl; - for(var i in images){ - var img_path=iurl + images[i]; - await getApp().request.promise_downimg(img_path).then(res=>{ - images[i] = res; - }) - } - - th.data.images=images; - }, - - - //好友猜一猜 - save_share: function(e) { - var th = this; - var aitem = this.data.aitem; //任务的数据集 - var sw_index = this.data.sw_index; //轮播的下标 - var sw_item=aitem[sw_index]; - //任务id - var taskid = sw_item.id; - th.setData({ - is_share: 1 - }) - var url = "/api/weshop/marketing/help/help/task/involve/page"; - getApp().request.promiseGet(url, { - isShowLoading: true, - data: { - storeId: os.stoid, - taskId: taskid, - userId: getApp().globalData.user_id - } - }).then(res => { - if (res.data.code == 0) { - var data = res.data.data.pageData; //帮拆数组 - if (data.length > 0) { - th.data.dynamic=data[0]; - var path=th.data.iurl+sw_item.giftBagUrl; - //先获取礼包分享时的本地路径 - getApp().request.promise_downimg(path).then(res=>{ - th.data.share_lb_img= res; - //先获取会员的头像 - th.info_head(th.shareFrends); - }); - } - } else { - wx.hideLoading(); - getApp().my_warnning(res.data.msg, 0, th); - } - }) - }, - - //把已助力好友头像下载到本地 - info_head:async function(func) { - var th = this; - var images = th.data.dynamic.zlHelpUser; - var arr=new Array(); - if (images) { - for(var i in images){ - var img_path=images[i].headPic; - await getApp().request.promise_downimg(img_path).then(res=>{ - th.data.head_pic_arr.push(res); - }) - } - } - func(); - }, - - - + imageinfo: async function() { + var th = this; + var images = th.data.images; + var iurl = th.data.iurl; + for (var i in images) { + var img_path = iurl + images[i]; + await getApp().request.promise_downimg(img_path).then(res => { + images[i] = res; + }) + } + + th.data.images = images; + }, + + + //好友猜一猜 + save_share: function(e) { + var th = this; + var aitem = this.data.aitem; //任务的数据集 + var sw_index = this.data.sw_index; //轮播的下标 + var sw_item = aitem[sw_index]; + //任务id + var taskid = sw_item.id; + th.setData({ + is_share: 1 + }) + var url = "/api/weshop/marketing/help/help/task/involve/page"; + getApp().request.promiseGet(url, { + isShowLoading: true, + data: { + storeId: os.stoid, + taskId: taskid, + userId: getApp().globalData.user_id + } + }).then(res => { + if (res.data.code == 0) { + var data = res.data.data.pageData; //帮拆数组 + if (data.length > 0) { + th.data.dynamic = data[0]; + var path = th.data.iurl + sw_item.giftBagUrl; + //先获取礼包分享时的本地路径 + getApp().request.promise_downimg(path).then(res => { + th.data.share_lb_img = res; + //先获取会员的头像 + th.info_head(th.shareFrends); + }); + } + } else { + wx.hideLoading(); + getApp().my_warnning(res.data.msg, 0, th); + } + }) + }, + + //把已助力好友头像下载到本地 + info_head: async function(func) { + var th = this; + var images = th.data.dynamic.zlHelpUser; + var arr = new Array(); + var block = th.data.block; + if (images && block == 0) { + th.setData({ + block: 1 + }); + for (var i in images) { + var img_path = images[i].headPic; + await getApp().request.promise_downimg(img_path).then(res => { + th.data.head_pic_arr.push(res); + }) + } + } + func(); + }, + + + //礼包的详情 轮播图 libao_details: function(e) { var th = this; - var help_id = th.data.help_id;//活动id - var taskId = th.data.taskid;//任务id + var help_id = th.data.help_id; //活动id + var taskId = th.data.taskid; //任务id getApp().goto("/pages/user/assistance/giftpacklist?help_id=" + help_id + "&is_libao=" + 0 + "&taskId=" + taskId); }, //正在进行任务 diff --git a/pages/user/assistance/task_assistance.wxml b/pages/user/assistance/task_assistance.wxml index 0a32c1b..afa13fa 100644 --- a/pages/user/assistance/task_assistance.wxml +++ b/pages/user/assistance/task_assistance.wxml @@ -52,13 +52,13 @@ 好友拆一拆 - + - + diff --git a/pages/user/assistance/task_assistance.wxss b/pages/user/assistance/task_assistance.wxss index 23d9a25..4b265e8 100644 --- a/pages/user/assistance/task_assistance.wxss +++ b/pages/user/assistance/task_assistance.wxss @@ -2,8 +2,10 @@ page { background: #d01119; width: 100%; height: 100%; + } + .top-back { width: 100%; height: 60%; @@ -189,7 +191,7 @@ page { position: fixed; width: 100%; height: 100%; - background-color: red; + background-color: #d01119; z-index: 10; } -- libgit2 0.21.4