diff --git a/pages/user/assistance/task_assistance.js b/pages/user/assistance/task_assistance.js index e24304d..739b1cd 100644 --- a/pages/user/assistance/task_assistance.js +++ b/pages/user/assistance/task_assistance.js @@ -46,7 +46,12 @@ Page({ "miniapp/images/friendhelp/check.png", "miniapp/images/friendhelp/unfinished.png", "/public/upload/libao/temp/2019/12-20/51f251f44ea0f67b8efdc5bfa3a434b0.jpg" ], //固的分享图片 - dynamic: [], //已助力的微信头像数组 + + dynamic: null, //已助力的微信头像数组 + head_pic_arr:[],//助力的头像 + share_lb_img:"",//分享的礼包图片 + + is_generate: 0, //是否重复点击拆一拆 already: 0, //已有几人助力 lack: 0, //还差几人助力 @@ -75,7 +80,7 @@ Page({ th.close(); th.syinfo(); th.imageinfo(); - //end + }, @@ -207,10 +212,6 @@ Page({ }, - - - - //帮拆记录的 dismantle_record: function(e) { var aitem = this.data.aitem; //任务的数据集 @@ -572,222 +573,163 @@ Page({ } }) }, - //钱 分享图 - imageinfo: function() { - var th = this; - var images = th.data.images; - var iurl = th.data.iurl; - wx.getImageInfo({ - src: iurl + images[0], - success: function(res) { - //res.path是网络图片的本地地址 - images[0] = res.path; - }, - fail: function(res) { - } - }); - wx.getImageInfo({ - src: iurl + images[1], - success: function(res) { - //res.path是网络图片的本地地址 - images[1] = res.path; - }, - fail: function(res) { - } - }); - wx.getImageInfo({ - src: iurl + images[2], - success: function(res) { - //res.path是网络图片的本地地址 - images[2] = res.path; - }, - fail: function(res) { - - } - }); - wx.getImageInfo({ - src: iurl + images[3], - success: function(res) { - //res.path是网络图片的本地地址 - images[3] = res.path; - }, - fail: function(res) { - } - }); - wx.getImageInfo({ - src: iurl + images[4], - success: function(res) { - //res.path是网络图片的本地地址 - images[4] = res.path; - }, - fail: function(res) { - } - }); - wx.getImageInfo({ - src: iurl + images[5], - success: function(res) { - //res.path是网络图片的本地地址 - images[5] = res.path; - }, - fail: function(res) { - } - }); - wx.getImageInfo({ - src: iurl + images[6], - success: function(res) { - //res.path是网络图片的本地地址 - images[6] = res.path; - }, - fail: function(res) { - } - }); - - wx.getImageInfo({ - src: iurl + images[7], - success: function(res) { - //res.path是网络图片的本地地址 - images[7] = res.path; - }, - fail: function(res) { - } - }) - th.setData({ - images: images - }) - - }, - //生成分享图,用于分享给好友帮拆 - demolition: function() { - var th = this; - - - }, + + + //************************ */ - shareFrends: function(e) { - var th = this; - var is_generate = th.data.is_generate; //是否重复提交拆一拆 - if (is_generate == 0) { - th.setData({ - is_generate: 1 - }) - var scene = th.data.gid; - ///二微码 - // var path3 = os.url + "/api/wx/open/app/user/getWeAppEwm/" + - // a.stoid + "?sceneValue=" + scene + "&pageValue=pages/goods/goodsInfo/goodsInfo"; - var iurl = th.data.iurl; //图片地址前缀 - const ctx = wx.createCanvasContext('share_id'); //绘图上下文 - var unit = th.data.screenWidth / 750 * 1.35; - var numsize = 20 * unit; //几人助力字体大小 - var size = 15 * unit; - var num = th.data.already; //已有几位好友助力 - var q_num = th.data.lack; //还差几位好友助力 - var already = num.toString().length + 1; //已有几位好友助力 - var lack = q_num.toString().length + 1; //还差几位好友助力 - 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(images[5], 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 = q_num / 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 dynamic = th.data.dynamic; //助力的微信头像 - for (var i = 0; i < 6; i++) { - if (i < 0) { - // ctx.beginPath(); - // ctx.arc(left + imagesize / 2, 505 * unit, imagesize / 2, 0, 2 * Math.PI); - // ctx.setLineWidth(1); - // ctx.setStrokeStyle('red'); - 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(dynamic[i].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("2019.06.26 - 2019.07.02!", 37 * unit, 620 * unit); - ctx.setFillStyle("rgb(255,255,255)"); - ctx.setFontSize(size); - ctx.fillText("长按识别二维码,可帮我助力!", 37 * unit, 660 * unit); - ctx.drawImage(images[5], 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 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) + }) + }) + } + }) + + + }, + + preview: function() { var th = this; var shareImgPath = th.data.shareImgPath; @@ -819,197 +761,80 @@ Page({ } }) }, + //把固定的图片加载到本地 - imageinfo: function() { - var th = this; - var images = th.data.images; - var iurl = th.data.iurl; - wx.getImageInfo({ - src: iurl + images[0], - success: function(res) { - //res.path是网络图片的本地地址 - images[0] = res.path; - }, - fail: function(res) { - - } - }); - wx.getImageInfo({ - src: iurl + images[1], - success: function(res) { - //res.path是网络图片的本地地址 - images[1] = res.path; - }, - fail: function(res) { - - } - }); - wx.getImageInfo({ - src: iurl + images[2], - success: function(res) { - //res.path是网络图片的本地地址 - images[2] = res.path; - }, - fail: function(res) { - - } - }); - wx.getImageInfo({ - src: iurl + images[3], - success: function(res) { - - //res.path是网络图片的本地地址 - images[3] = res.path; - }, - fail: function(res) { - - } - }); - wx.getImageInfo({ - src: iurl + images[4], - success: function(res) { - - //res.path是网络图片的本地地址 - images[4] = res.path; - }, - fail: function(res) { - - } - }); - wx.getImageInfo({ - src: iurl + images[5], - success: function(res) { - - //res.path是网络图片的本地地址 - images[5] = res.path; - }, - fail: function(res) { - - } - }); - th.setData({ - images: images - }) - - }, - //好友猜一猜 - save_share: function(e) { - var th = this; - var aitem = this.data.aitem; //任务的数据集 - var sw_index = this.data.sw_index; //轮播的下标 - //任务id - var taskid = aitem[sw_index].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.setData({ - // dynamic: data - // }) - // th.info_head(function() { - th.shareFrends(); - // }); - //th.imageinfo(); - - } - } else { - wx.hideLoading(); - getApp().my_warnning(res.data.msg, 0, th); - } - }) - }, - //把已助力好友头像下载到本地 - info_head: function(e) { - var th = this; - var images = th.data.dynamic; - if (images[0] != null && images[0] != "" && images[0] != undefined) { - wx.getImageInfo({ - src: images[0].headPic, - success: function(res) { - //res.path是网络图片的本地地址 - images[0].headPic = res.path; - }, - fail: function(res) { - - } - }); - } - if (images[1] != null && images[1] != "" && images[1] != undefined) { - wx.getImageInfo({ - src: images[1].headPic, - success: function(res) { - //res.path是网络图片的本地地址 - images[1].headPic = res.path; - }, - fail: function(res) { - - } - }); - } - if (images[2] != null && images[2] != "" && images[2] != undefined) { - wx.getImageInfo({ - src: images[2].headPic, - success: function(res) { - //res.path是网络图片的本地地址 - images[2].headPic = res.path; - }, - fail: function(res) { - - } - }); - } - if (images[3] != null && images[3] != "" && images[3] != undefined) { - wx.getImageInfo({ - src: images[3].headPic, - success: function(res) { - //res.path是网络图片的本地地址 - images[3].headPic = res.path; - }, - fail: function(res) { - - } - }); - } - // if (images[4] != null && images[4] != "" && images[4] != undefined) { - // wx.getImageInfo({ - // src: images[4].headPic, - // success: function(res) { - // //res.path是网络图片的本地地址 - // images[4].headPic = res.path; - // }, - // fail: function(res) { - - // } - // }); - // } - // if (images[5] != null && images[5] != "" && images[5] != undefined) { - // wx.getImageInfo({ - // src: images[5].headPic, - // success: function (res) { - // //res.path是网络图片的本地地址 - // images[5].headPic = res.path; - // }, - // fail: function (res) { - - // } - // }); - //} - th.setData({ - dynamic: images - }) - - }, + 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(); + }, + + + //礼包的详情 轮播图 libao_details: function(e) { var th = this;