setposter.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  1. const app = getApp();
  2. var utils = require("../../../utils/http");
  3. const util = require("../../../utils/util");
  4. let winwidth = 0,allquery='';
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. imgUrl: app.globalData.imgUrl,
  11. src: '',
  12. type: '',
  13. aid: '',
  14. cangth: 0,
  15. shareImg: '',
  16. posterimg: '',
  17. qrcodeimg: '',
  18. title: '',
  19. aType: '',
  20. listshare: false,
  21. openSet:false
  22. },
  23. /**
  24. * 生命周期函数--监听页面加载
  25. */
  26. onLoad: function (options) {
  27. let that=this;
  28. this.setData({
  29. type: options.type,
  30. aid: options.aid,
  31. listshare: options.listshare ? true : false
  32. })
  33. if (!!options.tp) {
  34. this.setData({
  35. aType: options.tp
  36. })
  37. }
  38. wx.showLoading({
  39. title: '加载中...',
  40. })
  41. wx.getSystemInfo({
  42. success: (res) => {
  43. winwidth = res.windowWidth;
  44. }
  45. })
  46. if (that.data.listshare) {
  47. if (this.data.type == 'materialCase') {
  48. allquery='&u='+app.globalData.personMsg.id +'&c=' + options.c + '&s=' + options.s + '&st=' + options.st + '&e=' + options.e + '&h=' + options.h;
  49. }
  50. if (this.data.type == 'materialEvidence') {
  51. allquery='uid='+app.globalData.personMsg.id+'&cate='+options.cate;
  52. }
  53. if (this.data.type == 'video') {
  54. allquery="uid="+app.globalData.personMsg.id+"&ftext="+options.ftext+"&nText="+options.nText;
  55. }
  56. }
  57. this.sharelogtap();
  58. },
  59. sharelogtap: function (e) {
  60. var that = this;
  61. utils.$post({
  62. url: app.globalData.webUrl + 'api/share/addlog',
  63. header: {
  64. 'Authorization': 'bearer ' + app.globalData.token
  65. },
  66. data: {
  67. id: that.data.aid,
  68. type: that.data.type
  69. },
  70. success: function (r) {
  71. }
  72. })
  73. },
  74. postermsg: function () {
  75. let that = this;
  76. if (that.data.listshare) {
  77. if (this.data.type == 'materialCase') {
  78. that.setData({
  79. posterimg: app.globalData.imgUrl+'xcx/caseposter.jpg',
  80. title: "案例列表"
  81. })
  82. }
  83. if (this.data.type == 'materialEvidence') {
  84. that.setData({
  85. posterimg: app.globalData.imgUrl+'xcx/praiseimg.jpg',
  86. title: "客户好评"
  87. })
  88. }
  89. if (this.data.type == 'video') {
  90. that.setData({
  91. posterimg: app.globalData.imgUrl+'xcx/videoposter.png',
  92. title: "拓客视频"
  93. })
  94. }
  95. that.getcodeimg()
  96. return false;
  97. }
  98. if (that.data.type == 'activity') {
  99. if (that.data.aType && that.data.aType == 'broker') {
  100. utils.$post({
  101. url: app.globalData.webUrl + 'api/agents_work/activity_detail',
  102. header: {
  103. 'Authorization': 'bearer ' + app.globalData.token
  104. },
  105. data: {
  106. id: that.data.aid,
  107. uid: app.globalData.personMsg.id
  108. },
  109. success: function (res) {
  110. if (res.data.code == '0') {
  111. that.setData({
  112. posterimg: res.data.data.cover,
  113. title: res.data.data.title
  114. })
  115. }
  116. that.getcodeimg()
  117. }
  118. })
  119. } else {
  120. utils.$post({
  121. url: app.globalData.webUrl + 'api/activity/details',
  122. header: {
  123. 'Authorization': 'bearer ' + app.globalData.token
  124. },
  125. data: {
  126. id: that.data.aid,
  127. uid: app.globalData.personMsg.id
  128. },
  129. success: function (res) {
  130. if (res.data.code == '0') {
  131. that.setData({
  132. posterimg: res.data.data.poster,
  133. title: res.data.data.title
  134. })
  135. }
  136. that.getcodeimg()
  137. }
  138. })
  139. }
  140. }
  141. if (this.data.type == 'materialCase') {
  142. utils.$get({
  143. url: app.globalData.webUrl + 'api/casedetail',
  144. header: {
  145. 'Authorization': 'bearer ' + app.globalData.token
  146. },
  147. data: {
  148. id: this.data.aid,
  149. uid: app.globalData.personMsg.id,
  150. },
  151. success: function (res) {
  152. if (res.data.code == '0') {
  153. res.data.data.cover_img=res.data.data.cover_img.replace('http://o.nczyzs.com/','https://o.nczyzs.com/');
  154. that.setData({
  155. posterimg: res.data.data.cover_img,
  156. title: res.data.data.title
  157. })
  158. }
  159. that.getcodeimg()
  160. }
  161. })
  162. }
  163. if (this.data.type == 'materialEvidence') {
  164. utils.$get({
  165. url: app.globalData.webUrl + 'api/evidencedetail',
  166. header: {
  167. 'Authorization': 'bearer ' + app.globalData.token
  168. },
  169. data: {
  170. id: that.data.aid,
  171. uid: app.globalData.personMsg.id,
  172. },
  173. success: function (res) {
  174. if (res.data.code == '0') {
  175. 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];
  176. img=img.replace('http://o.nczyzs.com/','https://o.nczyzs.com/');
  177. that.setData({
  178. posterimg:img,
  179. title: res.data.data.title
  180. })
  181. }
  182. that.getcodeimg()
  183. }
  184. })
  185. }
  186. if (this.data.type == 'video') {
  187. utils.$post({
  188. url: app.globalData.webUrl + 'api/video/info',
  189. header: {
  190. 'Authorization': 'bearer ' + app.globalData.token
  191. },
  192. data: {
  193. video_id: that.data.aid
  194. },
  195. success: function (rs) {
  196. if (rs.data.code == '0') {
  197. that.setData({
  198. 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'),
  199. title: rs.data.data.title
  200. })
  201. }
  202. that.getcodeimg()
  203. }
  204. })
  205. }
  206. if (this.data.type == 'article') {
  207. utils.$post({
  208. url: app.globalData.webUrl + 'api/article/info',
  209. header: {
  210. 'Authorization': 'bearer ' + app.globalData.token
  211. },
  212. data: {
  213. article_id: that.data.aid
  214. },
  215. success: function (res) {
  216. if (res.data.code == '0') {
  217. that.setData({
  218. posterimg: res.data.data.cover_img,
  219. title: res.data.data.title
  220. })
  221. }
  222. that.getcodeimg()
  223. }
  224. })
  225. }
  226. if(this.data.type=='Construction'){
  227. utils.$post({
  228. url: app.globalData.webUrl + 'api/construction/view',
  229. header: {
  230. 'Authorization':'bearer '+app.globalData.token
  231. },
  232. data:{
  233. id:that.data.aid
  234. },
  235. success: function (res) {
  236. if(res.data.code=='0'){
  237. that.setData({
  238. posterimg: res.data.data.cover,
  239. title: res.data.data.name
  240. })
  241. }
  242. that.getcodeimg()
  243. }
  244. })
  245. }
  246. if(this.data.type=='building'){
  247. utils.$post({
  248. url: app.globalData.webUrl + 'api/building/view',
  249. header: {
  250. 'Authorization':'bearer '+app.globalData.token
  251. },
  252. data:{
  253. id:that.data.aid
  254. },
  255. success: function (res) {
  256. if(res.data.code=='0'){
  257. that.setData({
  258. posterimg: res.data.data.cover[0],
  259. title: res.data.data.name
  260. })
  261. }
  262. that.getcodeimg()
  263. }
  264. })
  265. }
  266. if(this.data.type=='CompanyStrength'){
  267. utils.$post({
  268. url: app.globalData.webUrl + 'api/company_strength/read',
  269. header: {
  270. 'Authorization':'bearer '+app.globalData.token
  271. },
  272. data:{
  273. id:that.data.aid
  274. },
  275. success: function (res) {
  276. if(res.data.code=='0'){
  277. 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;
  278. img=img.replace('http://o.nczyzs.com/','https://o.nczyzs.com/');
  279. that.setData({
  280. posterimg:img,
  281. title: res.data.data.title
  282. })
  283. }
  284. that.getcodeimg()
  285. }
  286. })
  287. }
  288. },
  289. getcodeimg: function () {
  290. let that = this,query='',path='';
  291. if (that.data.listshare) {
  292. if (this.data.type == 'materialCase') {
  293. query=allquery+'&ctp='+app.globalData.clientype;
  294. path='share/pages/caselist/caselist'
  295. }
  296. if (this.data.type == 'materialEvidence') {
  297. query=allquery+'&ctp='+app.globalData.clientype;
  298. path='share/pages/praiselist/praiselist'
  299. }
  300. if (this.data.type == 'video') {
  301. query=allquery+'&ctp='+app.globalData.clientype;
  302. path='share/pages/videolist/videolist'
  303. }
  304. }else{
  305. if (that.data.type == 'activity') {
  306. if (that.data.aType && that.data.aType == 'broker') {
  307. query='aid=' + this.data.aid + '&bid=' + app.globalData.brokeruserId+'&ctp='+app.globalData.clientype+'&t=b';
  308. path='share/pages/activitymsg/activitymsg';
  309. } else {
  310. query='aid=' + this.data.aid + '&uid=' + app.globalData.personMsg.id+'&ctp='+app.globalData.clientype;
  311. path='share/pages/activitymsg/activitymsg';
  312. }
  313. }
  314. if (this.data.type == 'materialCase') {
  315. query='cid='+that.data.aid+'&uid='+app.globalData.personMsg.id+'&ctp='+app.globalData.clientype;
  316. path='share/pages/materialcase/materialcase';
  317. }
  318. if (this.data.type == 'materialEvidence') {
  319. query='eid='+that.data.aid+'&uid='+app.globalData.personMsg.id+'&ctp='+app.globalData.clientype;
  320. path='share/pages/publicpraisemsg/publicpraisemsg';
  321. }
  322. if (this.data.type == 'CompanyStrength') {
  323. query='eid='+that.data.aid+'&uid='+app.globalData.personMsg.id+'&ctp='+app.globalData.clientype;
  324. path='share/pages/companystrengthmsg/companystrengthmsg';
  325. }
  326. if (this.data.type == 'video') {
  327. query='vid='+that.data.aid +'&userid='+app.globalData.personMsg.id+'&ctp='+app.globalData.clientype;
  328. path='share/pages/videoshare/videoshare';
  329. }
  330. if (this.data.type == 'article') {
  331. query='aid='+that.data.aid +'&userid='+app.globalData.personMsg.id+'&ctp='+app.globalData.clientype;
  332. path='share/pages/articleshare/articleshare';
  333. }
  334. if (this.data.type == 'spellgroup') {
  335. query='a='+that.data.aid +'&u='+app.globalData.personMsg.id+'&t='+'&e='+app.globalData.personMsg.binded.id+'&p='+app.globalData.clientype;
  336. path='share/pages/collagemsg/collagemsg';
  337. }
  338. if (this.data.type == 'Construction') {
  339. query='cid='+that.data.aid +'&uid='+app.globalData.personMsg.id+'&ctp='+app.globalData.clientype;
  340. path='share/pages/constructsite/constructsite';
  341. }
  342. if(this.data.type=='building'){
  343. query='u=' + app.globalData.personMsg.id + '&c=' + that.data.aid + '&e=' + app.globalData.personMsg.binded.id+'&t='+app.globalData.clientype;
  344. path='share/pages/buildprogress/buildprogress';
  345. }
  346. }
  347. utils.$post({
  348. url: app.globalData.webUrl + 'api/share/qrcode',
  349. header: {
  350. 'Authorization': 'bearer ' + app.globalData.token
  351. },
  352. data: {
  353. query: query,
  354. path: path
  355. },
  356. success: function (res) {
  357. if (res.data.code == "0") {
  358. that.setData({
  359. qrcodeimg:res.data.data
  360. })
  361. setTimeout(function(){
  362. that.createdCode();
  363. },300)
  364. }
  365. },
  366. fail() {
  367. }
  368. })
  369. },
  370. //开始绘图
  371. createdCode: function () {
  372. let that = this;
  373. if(that.data.title.length>15){
  374. that.setData({
  375. title:that.data.title.substring(0,13)+'...'
  376. })
  377. }
  378. let topwidth = winwidth * 710 / 750,topheight = '';
  379. const ctx = wx.createCanvasContext('myCanvas'); //绘图上下文
  380. wx.getImageInfo({
  381. src: that.data.posterimg,
  382. success(res) {
  383. wx.getImageInfo({
  384. src: that.data.qrcodeimg,
  385. success(rs) {
  386. topheight = topwidth * res.height / res.width;
  387. that.setData({
  388. cangth: topheight + 110
  389. })
  390. ctx.save();
  391. ctx.drawImage(res.path, 0, 0, topwidth, topheight);
  392. ctx.rect(0, topheight, topwidth, 110);
  393. ctx.setFillStyle('#FFFFFF');
  394. ctx.fill();
  395. ctx.restore()
  396. ctx.setFontSize(14);
  397. ctx.fillText("@" + app.globalData.personMsg.nickname, 12, topheight + 44, topwidth - 70);
  398. ctx.fillText(that.data.title, 12, topheight + 66, topwidth - 70);
  399. ctx.drawImage(rs.path, topwidth - 100, topheight + 12, 88, 88);
  400. ctx.draw();
  401. wx.hideLoading();
  402. setTimeout(() => {
  403. wx.canvasToTempFilePath({
  404. x: 0,
  405. y: 0,
  406. canvasId: 'myCanvas',
  407. success: function (res) {
  408. let shareImg = res.tempFilePath;
  409. that.setData({
  410. shareImg: shareImg,
  411. })
  412. },
  413. fail: function (res) {}
  414. })
  415. },500)
  416. },fail(res){
  417. console.log(res)
  418. },
  419. })
  420. },fail(res){
  421. console.log(res)
  422. }
  423. })
  424. },
  425. saveimgtap: function () {
  426. let that = this;
  427. // 获取用户是否开启用户授权相册
  428. wx.getSetting({
  429. success(res) {
  430. // 如果没有则获取授权
  431. if (!res.authSetting['scope.writePhotosAlbum']) {
  432. wx.authorize({
  433. scope: 'scope.writePhotosAlbum',
  434. success() {
  435. wx.saveImageToPhotosAlbum({
  436. filePath: that.data.shareImg,
  437. success() {
  438. wx.showToast({
  439. title: '保存成功'
  440. })
  441. },
  442. fail() {
  443. wx.showToast({
  444. title: '保存失败',
  445. icon: 'none'
  446. })
  447. }
  448. })
  449. },
  450. fail() {
  451. // 如果用户拒绝过或没有授权,则再次打开授权窗口
  452. //(ps:微信api又改了现在只能通过button才能打开授权设置,以前通过openSet就可打开,下面有打开授权的button弹窗代码)
  453. that.setData({
  454. openSet: true
  455. })
  456. }
  457. })
  458. } else {
  459. // 有则直接保存
  460. wx.saveImageToPhotosAlbum({
  461. filePath: that.data.shareImg,
  462. success() {
  463. wx.showToast({
  464. title: '保存成功'
  465. })
  466. },
  467. fail() {
  468. wx.showToast({
  469. title: '保存失败',
  470. icon: 'none'
  471. })
  472. }
  473. })
  474. }
  475. }
  476. })
  477. },
  478. cancleSet() {
  479. this.setData({
  480. openSet: false
  481. })
  482. },
  483. /**
  484. * 生命周期函数--监听页面初次渲染完成
  485. */
  486. onReady: function () {
  487. },
  488. /**
  489. * 生命周期函数--监听页面显示
  490. */
  491. onShow: function () {
  492. let that = this;
  493. that.postermsg();
  494. },
  495. /**
  496. * 生命周期函数--监听页面隐藏
  497. */
  498. onHide: function () {
  499. },
  500. /**
  501. * 生命周期函数--监听页面卸载
  502. */
  503. onUnload: function () {
  504. },
  505. /**
  506. * 页面相关事件处理函数--监听用户下拉动作
  507. */
  508. onPullDownRefresh: function () {
  509. },
  510. /**
  511. * 页面上拉触底事件的处理函数
  512. */
  513. onReachBottom: function () {
  514. },
  515. /**
  516. * 用户点击右上角分享
  517. */
  518. // onShareAppMessage: function () {
  519. // }
  520. })