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, vrtype: '', vrurl: '', employee_uid: "", agent_id: "", bType: "", fromType: "" }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { let that = this; this.setData({ type: options.type, aid: options.aid, listshare: options.listshare ? true : false, vrtype: options.vrtype ? options.vrtype : '', vrurl: options.turl ? options.turl : '' }) if (!!options.tp) { this.setData({ aType: options.tp }) } if (!!options.ty) { this.setData({ bType: options.ty }) } if (!!options.f) { this.setData({ fromType: options.f }) } 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; } } if (this.data.type == 'shareArticle') { this.addsharetap(); } else { this.sharelogtap(); } }, addsharetap: function () { let that = this; utils.$post({ url: app.globalData.webUrl + 'api/agentsWork/agent_sharelog', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { type: "AgentArticle", article_id: that.data.aid, }, success: function (r) { } }) }, 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 == 'vr' ? (that.data.vrtype + '_vr') : that.data.type, other_data: that.data.type == 'vr' ? that.data.vrurl : '' }, 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 == 'shareArticle') { utils.$post({ url: app.globalData.webUrl + 'api/agentsWork/share_article_details', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { from: that.data.fromType, id: that.data.aid }, success: function (res) { wx.hideLoading(); if (res.data.code == '0') { let imgUrl = ''; if (that.data.fromType == 2) { if (res.data.data.type == 1) { imgUrl = res.data.data.file[0] + '?x-oss-process=video/snapshot,t_100,f_jpg,w_200,m_fast'; } else if (res.data.data.type == 3) { imgUrl = res.data.data.file_img; } else { imgUrl = res.data.data.file[0]; } } else { if (res.data.data.type == 1) { imgUrl = res.data.data.file[0] + '?x-oss-process=video/snapshot,t_100,f_jpg,w_200,m_fast'; } else { imgUrl = res.data.data.file[0]; } } that.setData({ posterimg: imgUrl, title: res.data.data.title }) 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 == 'buildingProgress') { utils.$post({ url: app.globalData.webUrl + 'client/building/progress_detail', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { id: that.data.aid }, success: function (res) { if (res.data.code == '0') { let data = res.data.data; if (data.type == 'video') { if (data.img && data.img.length) { that.setData({ posterimg: data.img[0], title: `${data.building_name}-${data.name}` }) } else { that.setData({ posterimg: `${data.video}?x-oss-process=video/snapshot,t_100,f_jpg,w_200,m_fast`, title: `${data.building_name}-${data.name}` }) } } else if (data.type == 'img') { that.setData({ posterimg: data.img[0], title: `${data.building_name}-${data.name}` }) } else { that.setData({ posterimg: data.vr[0]['vrfirstImg'], title: `${data.building_name}-${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() } }) } if (this.data.type == 'vr') { let title, imgurl; if (this.data.vrtype == 'company') { title = "在线逛展厅-" + app.globalData.companyobj.company_name; imgurl = app.globalData.imgUrl + 'xcx/aaa/vrcover.png'; that.setData({ posterimg: imgurl, title: title }) that.getcodeimg() } else if (this.data.vrtype == 'employeeCard') { title = app.globalData.companyobj.company_name + 'VR寻址'; imgurl = app.globalData.imgUrl + "/xcx/sharenamecard.png"; that.setData({ posterimg: imgurl, title: title }) that.getcodeimg() } else if (this.data.vrtype == 'materialCase') { utils.$get({ url: app.globalData.webUrl + 'client/casedetail', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { id: this.data.aid, share: '146' }, success: function (res) { if (res.data.code == '0') { title = res.data.data.title + '的VR'; imgurl = res.data.data.cover_img; that.setData({ posterimg: imgurl, title: title }) that.getcodeimg() } } }) } else if (this.data.vrtype == 'building') { utils.$get({ url: app.globalData.webUrl + 'client/building/view', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { id: this.data.aid, share: '146' }, success: function (res) { if (res.data.code == '0') { title = res.data.data.name + '的VR'; imgurl = res.data.data.cover; that.setData({ posterimg: Array.isArray(imgurl) && imgurl.length ? imgurl[0] : imgurl, title: title }) that.getcodeimg() } } }) } else if (this.data.vrtype == 'construction') { utils.$post({ url: app.globalData.webUrl + 'client/construction/view', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { id: this.data.aid, share: '146' }, success: function (res) { if (res.data.code == '0') { title = res.data.data.name + '的VR'; imgurl = res.data.data.cover; that.setData({ posterimg: imgurl, title: title }) that.getcodeimg() } } }) } } if (this.data.type == 'housetype') { utils.$post({ url: app.globalData.webUrl + 'api/building/housetype_detail', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { id: that.data.aid }, success: function (res) { if (res.data.code == '0') { let data = res.data.data; let posterCover = ""; if (data.house_img && Array.isArray(data.house_img) && data.house_img.length) { posterCover = data.house_img[0]; } else { posterCover = data.vr_link_img; } if (data.room == 9) { data.shareTitle = "别墅"; } else { data.shareTitle = `${data.room}室${data.hall}厅${data.bathroom}卫`; } that.setData({ posterimg: posterCover, title: data.shareTitle }) } 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') { if (this.data.bType == 'b') { query = 'a=' + that.data.aid + '&u=' + app.globalData.agentEmployeEid + '&c=' + app.globalData.clientype + "&g=" + app.globalData.brokeruserId; path = 'share/pages/materialcase/materialcase'; } else { query = 'cid=' + that.data.aid + '&uid=' + app.globalData.personMsg.id + '&ctp=' + app.globalData.clientype; path = 'share/pages/materialcase/materialcase'; } } if (this.data.type == 'materialEvidence') { if (this.data.bType == 'b') { query = 'e=' + that.data.aid + '&u=' + app.globalData.agentEmployeEid + '&c=' + app.globalData.clientype + "&g=" + app.globalData.brokeruserId; path = 'share/pages/publicpraisemsg/publicpraisemsg'; } else { query = 'eid=' + that.data.aid + '&uid=' + app.globalData.personMsg.id + '&ctp=' + app.globalData.clientype; path = 'share/pages/publicpraisemsg/publicpraisemsg'; } } if (this.data.type == 'CompanyStrength') { if (this.data.bType == 'b') { query = 'e=' + that.data.aid + '&u=' + app.globalData.agentEmployeEid + '&c=' + app.globalData.clientype + "&g=" + app.globalData.brokeruserId; path = 'share/pages/companystrengthmsg/companystrengthmsg'; } else { query = 'eid=' + that.data.aid + '&uid=' + app.globalData.personMsg.id + '&ctp=' + app.globalData.clientype; path = 'share/pages/companystrengthmsg/companystrengthmsg'; } } if (this.data.type == 'video') { if (this.data.bType == 'b') { query = 'v=' + that.data.aid + '&u=' + app.globalData.agentEmployeEid + '&c=' + app.globalData.clientype + "&g=" + app.globalData.brokeruserId; path = 'share/pages/videoshare/videoshare'; } else { query = 'vid=' + that.data.aid + '&userid=' + app.globalData.personMsg.id + '&ctp=' + app.globalData.clientype; path = 'share/pages/videoshare/videoshare'; } } if (this.data.type == 'article') { if (this.data.bType == 'b') { query = 'a=' + that.data.aid + '&u=' + app.globalData.agentEmployeEid + '&c=' + app.globalData.clientype + "&g=" + app.globalData.brokeruserId; path = 'share/pages/articleshare/articleshare'; } else { 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') { if (this.data.bType == 'b') { query = 'u=' + app.globalData.agentEmployeEid + '&c=' + that.data.aid + '&t=' + app.globalData.clientype + "&g=" + app.globalData.brokeruserId; path = 'share/pages/buildprogress/buildprogress'; } else { 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'; } } if (this.data.type == 'buildingProgress') { query = 'u=' + app.globalData.personMsg.id + '&c=' + that.data.aid + '&e=' + app.globalData.personMsg.binded.id + '&t=' + app.globalData.clientype; path = 'share/pages/buildShare/buildShare'; } if (this.data.type == 'vr') { query = 'c=' + app.globalData.clientype + '&u=' + app.globalData.personMsg.id + '&a=' + this.data.aid + '&y=' + this.data.vrtype + '&l=' + this.data.vrurl; path = 'pages/other/other'; } if (this.data.type == 'shareArticle') { query = 'c=' + this.data.aid + '&u=' + app.globalData.agentEmployeEid + '&ct=' + app.globalData.clientype + '&ag=' + app.globalData.brokeruserId + '&f='+this.data.fromType; path = 'share/pages/brokershareinfo/brokershareinfo'; } if (this.data.type == 'housetype') { if (this.data.bType == 'b') { query = 'd=' + that.data.aid + '&u=' + app.globalData.agentEmployeEid + '&c=' + app.globalData.clientype + "&g=" + app.globalData.brokeruserId; path = 'share/pages/housetype/housetype'; } else { query = 'd=' + that.data.aid + '&u=' + app.globalData.personMsg.id + '&c=' + app.globalData.clientype; path = 'share/pages/housetype/housetype'; } } } 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.binded&&app.globalData.personMsg.binded.name?app.globalData.personMsg.binded.name: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 () { // } })