const app = getApp(); var utils = require("../../../utils/http"); const util = require("../../../utils/util"); let winwidth = 0,allquery=''; Page({ /** * 页面的初始数据 */ data: { imgUrl: app.globalData.imgUrl, src: '', type: '', aid: '', cangth: 0, shareImg: '', posterimg: '', qrcodeimg: '', title: '', aType: '', listshare: false, openSet:false }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { let that=this; this.setData({ type: options.type, aid: options.aid, listshare: options.listshare ? true : false }) if (!!options.tp) { this.setData({ aType: options.tp }) } wx.showLoading({ title: '加载中...', }) wx.getSystemInfo({ success: (res) => { winwidth = res.windowWidth; } }) if (that.data.listshare) { if (this.data.type == 'materialCase') { allquery='&u='+app.globalData.personMsg.id +'&c=' + options.c + '&s=' + options.s + '&st=' + options.st + '&e=' + options.e + '&h=' + options.h; } if (this.data.type == 'materialEvidence') { allquery='uid='+app.globalData.personMsg.id+'&cate='+options.cate; } if (this.data.type == 'video') { allquery="uid="+app.globalData.personMsg.id+"&ftext="+options.ftext+"&nText="+options.nText; } } this.sharelogtap(); }, sharelogtap: function (e) { var that = this; utils.$post({ url: app.globalData.webUrl + 'api/share/addlog', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { id: that.data.aid, type: that.data.type }, success: function (r) { } }) }, postermsg: function () { let that = this; if (that.data.listshare) { if (this.data.type == 'materialCase') { that.setData({ posterimg: app.globalData.imgUrl+'xcx/caseposter.jpg', title: "案例列表" }) } if (this.data.type == 'materialEvidence') { that.setData({ posterimg: app.globalData.imgUrl+'xcx/praiseimg.jpg', title: "客户好评" }) } if (this.data.type == 'video') { that.setData({ posterimg: app.globalData.imgUrl+'xcx/videoposter.png', title: "拓客视频" }) } that.getcodeimg() return false; } if (that.data.type == 'activity') { if (that.data.aType && that.data.aType == 'broker') { utils.$post({ url: app.globalData.webUrl + 'api/agents_work/activity_detail', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { id: that.data.aid, uid: app.globalData.personMsg.id }, success: function (res) { if (res.data.code == '0') { that.setData({ posterimg: res.data.data.cover, title: res.data.data.title }) } that.getcodeimg() } }) } else { utils.$post({ url: app.globalData.webUrl + 'api/activity/details', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { id: that.data.aid, uid: app.globalData.personMsg.id }, success: function (res) { if (res.data.code == '0') { that.setData({ posterimg: res.data.data.poster, title: res.data.data.title }) } that.getcodeimg() } }) } } if (this.data.type == 'materialCase') { utils.$get({ url: app.globalData.webUrl + 'api/casedetail', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { id: this.data.aid, uid: app.globalData.personMsg.id, }, success: function (res) { if (res.data.code == '0') { res.data.data.cover_img=res.data.data.cover_img.replace('http://o.nczyzs.com/','https://o.nczyzs.com/'); that.setData({ posterimg: res.data.data.cover_img, title: res.data.data.title }) } that.getcodeimg() } }) } if (this.data.type == 'materialEvidence') { utils.$get({ url: app.globalData.webUrl + 'api/evidencedetail', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { id: that.data.aid, uid: app.globalData.personMsg.id, }, success: function (res) { if (res.data.code == '0') { let img=res.data.data.difference==1?(res.data.data.cover?res.data.data.cover:(res.data.data.pics[0]+'?x-oss-process=video/snapshot,t_100,f_jpg,w_375,m_fast')):res.data.data.pics[0]; img=img.replace('http://o.nczyzs.com/','https://o.nczyzs.com/'); that.setData({ posterimg:img, title: res.data.data.title }) } that.getcodeimg() } }) } if (this.data.type == 'video') { utils.$post({ url: app.globalData.webUrl + 'api/video/info', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { video_id: that.data.aid }, success: function (rs) { if (rs.data.code == '0') { that.setData({ posterimg: rs.data.data.cover?rs.data.data.cover:(rs.data.data.video_url + '?x-oss-process=video/snapshot,t_100,f_jpg,w_500,m_fast'), title: rs.data.data.title }) } that.getcodeimg() } }) } if (this.data.type == 'article') { utils.$post({ url: app.globalData.webUrl + 'api/article/info', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { article_id: that.data.aid }, success: function (res) { if (res.data.code == '0') { that.setData({ posterimg: res.data.data.cover_img, title: res.data.data.title }) } that.getcodeimg() } }) } if(this.data.type=='Construction'){ utils.$post({ url: app.globalData.webUrl + 'api/construction/view', header: { 'Authorization':'bearer '+app.globalData.token }, data:{ id:that.data.aid }, success: function (res) { if(res.data.code=='0'){ that.setData({ posterimg: res.data.data.cover, title: res.data.data.name }) } that.getcodeimg() } }) } if(this.data.type=='building'){ utils.$post({ url: app.globalData.webUrl + 'api/building/view', header: { 'Authorization':'bearer '+app.globalData.token }, data:{ id:that.data.aid }, success: function (res) { if(res.data.code=='0'){ that.setData({ posterimg: res.data.data.cover[0], title: res.data.data.name }) } that.getcodeimg() } }) } if(this.data.type=='CompanyStrength'){ utils.$post({ url: app.globalData.webUrl + 'api/company_strength/read', header: { 'Authorization':'bearer '+app.globalData.token }, data:{ id:that.data.aid }, success: function (res) { if(res.data.code=='0'){ let img=res.data.data.difference==1?(res.data.data.cover?res.data.data.cover:(res.data.data.pics+'?x-oss-process=video/snapshot,t_100,f_jpg,w_375,m_fast')):res.data.data.cover; img=img.replace('http://o.nczyzs.com/','https://o.nczyzs.com/'); that.setData({ posterimg:img, title: res.data.data.title }) } that.getcodeimg() } }) } }, getcodeimg: function () { let that = this,query='',path=''; if (that.data.listshare) { if (this.data.type == 'materialCase') { query=allquery+'&ctp='+app.globalData.clientype; path='share/pages/caselist/caselist' } if (this.data.type == 'materialEvidence') { query=allquery+'&ctp='+app.globalData.clientype; path='share/pages/praiselist/praiselist' } if (this.data.type == 'video') { query=allquery+'&ctp='+app.globalData.clientype; path='share/pages/videolist/videolist' } }else{ if (that.data.type == 'activity') { if (that.data.aType && that.data.aType == 'broker') { query='aid=' + this.data.aid + '&bid=' + app.globalData.brokeruserId+'&ctp='+app.globalData.clientype+'&t=b'; path='share/pages/activitymsg/activitymsg'; } else { query='aid=' + this.data.aid + '&uid=' + app.globalData.personMsg.id+'&ctp='+app.globalData.clientype; path='share/pages/activitymsg/activitymsg'; } } if (this.data.type == 'materialCase') { query='cid='+that.data.aid+'&uid='+app.globalData.personMsg.id+'&ctp='+app.globalData.clientype; path='share/pages/materialcase/materialcase'; } if (this.data.type == 'materialEvidence') { query='eid='+that.data.aid+'&uid='+app.globalData.personMsg.id+'&ctp='+app.globalData.clientype; path='share/pages/publicpraisemsg/publicpraisemsg'; } if (this.data.type == 'CompanyStrength') { query='eid='+that.data.aid+'&uid='+app.globalData.personMsg.id+'&ctp='+app.globalData.clientype; path='share/pages/companystrengthmsg/companystrengthmsg'; } if (this.data.type == 'video') { query='vid='+that.data.aid +'&userid='+app.globalData.personMsg.id+'&ctp='+app.globalData.clientype; path='share/pages/videoshare/videoshare'; } if (this.data.type == 'article') { query='aid='+that.data.aid +'&userid='+app.globalData.personMsg.id+'&ctp='+app.globalData.clientype; path='share/pages/articleshare/articleshare'; } if (this.data.type == 'spellgroup') { query='a='+that.data.aid +'&u='+app.globalData.personMsg.id+'&t='+'&e='+app.globalData.personMsg.binded.id+'&p='+app.globalData.clientype; path='share/pages/collagemsg/collagemsg'; } if (this.data.type == 'Construction') { query='cid='+that.data.aid +'&uid='+app.globalData.personMsg.id+'&ctp='+app.globalData.clientype; path='share/pages/constructsite/constructsite'; } if(this.data.type=='building'){ query='u=' + app.globalData.personMsg.id + '&c=' + that.data.aid + '&e=' + app.globalData.personMsg.binded.id+'&t='+app.globalData.clientype; path='share/pages/buildprogress/buildprogress'; } } utils.$post({ url: app.globalData.webUrl + 'api/share/qrcode', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { query: query, path: path }, success: function (res) { if (res.data.code == "0") { that.setData({ qrcodeimg:res.data.data }) setTimeout(function(){ that.createdCode(); },300) } }, fail() { } }) }, //开始绘图 createdCode: function () { let that = this; if(that.data.title.length>15){ that.setData({ title:that.data.title.substring(0,13)+'...' }) } let topwidth = winwidth * 710 / 750,topheight = ''; const ctx = wx.createCanvasContext('myCanvas'); //绘图上下文 wx.getImageInfo({ src: that.data.posterimg, success(res) { wx.getImageInfo({ src: that.data.qrcodeimg, success(rs) { topheight = topwidth * res.height / res.width; that.setData({ cangth: topheight + 110 }) ctx.save(); ctx.drawImage(res.path, 0, 0, topwidth, topheight); ctx.rect(0, topheight, topwidth, 110); ctx.setFillStyle('#FFFFFF'); ctx.fill(); ctx.restore() ctx.setFontSize(14); ctx.fillText("@" + app.globalData.personMsg.nickname, 12, topheight + 44, topwidth - 70); ctx.fillText(that.data.title, 12, topheight + 66, topwidth - 70); ctx.drawImage(rs.path, topwidth - 100, topheight + 12, 88, 88); ctx.draw(); wx.hideLoading(); setTimeout(() => { wx.canvasToTempFilePath({ x: 0, y: 0, canvasId: 'myCanvas', success: function (res) { let shareImg = res.tempFilePath; that.setData({ shareImg: shareImg, }) }, fail: function (res) {} }) },500) },fail(res){ console.log(res) }, }) },fail(res){ console.log(res) } }) }, saveimgtap: function () { let that = this; // 获取用户是否开启用户授权相册 wx.getSetting({ success(res) { // 如果没有则获取授权 if (!res.authSetting['scope.writePhotosAlbum']) { wx.authorize({ scope: 'scope.writePhotosAlbum', success() { wx.saveImageToPhotosAlbum({ filePath: that.data.shareImg, success() { wx.showToast({ title: '保存成功' }) }, fail() { wx.showToast({ title: '保存失败', icon: 'none' }) } }) }, fail() { // 如果用户拒绝过或没有授权,则再次打开授权窗口 //(ps:微信api又改了现在只能通过button才能打开授权设置,以前通过openSet就可打开,下面有打开授权的button弹窗代码) that.setData({ openSet: true }) } }) } else { // 有则直接保存 wx.saveImageToPhotosAlbum({ filePath: that.data.shareImg, success() { wx.showToast({ title: '保存成功' }) }, fail() { wx.showToast({ title: '保存失败', icon: 'none' }) } }) } } }) }, cancleSet() { this.setData({ openSet: false }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { let that = this; that.postermsg(); }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ // onShareAppMessage: function () { // } })