123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545 |
- 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 () {
- // }
- })
|