bill.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. const util = require("../../../utils/util.js");
  2. Page({
  3. data: {
  4. showHarpin:true,
  5. flag:false,
  6. imgUrl:"",
  7. buttonFlag:false,
  8. info:{},
  9. imgHeight:"",
  10. imgWidth:"",
  11. Copyinfo:{
  12. posters: [],
  13. },
  14. qrcode:"",
  15. title:""
  16. },
  17. onLoad(options) {
  18. console.log(this.data.info);
  19. let info=JSON.parse(JSON.stringify(wx.getStorageSync('info')))
  20. let title=this.ellipsis(info.title)
  21. this.setData({
  22. info:info,
  23. title:title
  24. })
  25. },
  26. // 生成二维码
  27. getImage(){
  28. let obj={
  29. data:JSON.parse(wx.getStorageSync('liveId')),
  30. type:"activePhoto"
  31. }
  32. let that=this
  33. util.ajax({
  34. func: "user/qrcode/applet_code",
  35. data: obj ,
  36. method:"POST"
  37. }, function (res) {
  38. console.log(res);
  39. that.data.qrcode=res.data
  40. that.setData({
  41. qrcode:that.data.qrcode
  42. })
  43. });
  44. },
  45. // 超出部分显示省略号
  46. ellipsis(value){
  47. if (!value) return '';
  48. if (value.length > 18) {
  49. return value.slice(0,18) + '...'
  50. }
  51. return value
  52. },
  53. // 保存图片
  54. cetaInvite() {
  55. let title=this.ellipsis(this.data.info.title)
  56. console.log(title);
  57. let info=JSON.parse(JSON.stringify(wx.getStorageSync('info')))
  58. console.log(info);
  59. let that = this, view = [];
  60. console.log(info.title);
  61. wx.showLoading({
  62. title: '海报生成中'
  63. });
  64. let width=this.data.imgWidth
  65. let height=this.data.imgHeight
  66. // if(width>height){
  67. // if(width>800){
  68. // width=800
  69. // // height=800
  70. // }
  71. // }
  72. let polHeight=241.8
  73. let botHeight=296
  74. view.push(
  75. {
  76. type: 'image',
  77. url: that.data.imgUrl,
  78. top:polHeight*0.88,
  79. left: 0,
  80. width: 1080,
  81. height:height/width*1080,
  82. },
  83. {
  84. type:"image",
  85. url:"https://img.bbztx.com/image_test/upload/thumbs/20221010/logo/1665382575784052492.png",
  86. top:0,
  87. left:0,
  88. width:1080,
  89. height:polHeight
  90. },{
  91. type:"image",
  92. url:"https://img.bbztx.com/image_test/upload/thumbs/20221010/logo/1665382948396029740.png",
  93. top:20,
  94. left:30,
  95. width:150,
  96. height:40
  97. },{
  98. type:"text",
  99. content:`「${title}」`,
  100. top:polHeight/5*2,
  101. left:1080/2,
  102. fontSize:35,
  103. breakWord:true,
  104. MaxLineNumber:104,
  105. wordBreak:"break-all",
  106. wordWrap: "break-word",
  107. whiteSpace:"pre-wrap",
  108. textAlign:"center",
  109. fontWeight:900
  110. },{
  111. type:"text",
  112. content:`${info.policyName!=null?info.policyName:""} ${info.sname}`,
  113. top:polHeight/3*2,
  114. color: '#282828',
  115. textAlign:"center",
  116. left:1080/2,
  117. fontSize:30
  118. },{
  119. type: 'image',
  120. url: "https://img.bbztx.com/image_test/upload/thumbs/20221031/logo/1667201351273024921.png",
  121. top:height/width*1080+polHeight*0.76,
  122. width: 1080,
  123. height:botHeight,
  124. left:0,
  125. },{
  126. type: 'image',
  127. url: that.data.qrcode, //上线使用的二维码
  128. // url:"https://img.bbztx.com/applet/code/test/41c3584c894eedbdde42bc4c.png", //测试使用的二维码
  129. top:height/width*1080+polHeight*0.89,
  130. width: 1080/6,
  131. height:1080/6,
  132. left:1080/12*5,
  133. },{
  134. type: 'rect',
  135. content: '',
  136. top: polHeight-4,
  137. left: 1080/2-23,
  138. width: 60,
  139. height: 8,
  140. background:'#EE3A43',
  141. borderRadius: 50
  142. },{
  143. type: 'rect',
  144. content: '',
  145. top: height/width*1080+polHeight*0.76-2,
  146. left: 1080/2-30,
  147. width: 60,
  148. height: 9,
  149. background:'#EE3A43',
  150. borderRadius: 50
  151. },
  152. )
  153. this.setData({
  154. painting: {
  155. width: 1080,
  156. height: height/width*1080+botHeight+polHeight*0.76,
  157. clear: true,
  158. views: view
  159. }
  160. });
  161. },
  162. eventGetImage(event){
  163. const { tempFilePath, errMsg } = event.detail
  164. if (errMsg === 'canvasdrawer:ok') {
  165. wx.saveImageToPhotosAlbum({
  166. filePath: tempFilePath,
  167. success(res) {
  168. wx.showToast({
  169. title: '保存图片成功',
  170. icon: 'success',
  171. duration: 2000
  172. })
  173. }
  174. });
  175. wx.hideLoading();
  176. }
  177. },
  178. // 获取上传图片的宽高
  179. loadSuccess(e){
  180. console.log(e.detail);
  181. this.setData({
  182. imgHeight:e.detail.height,
  183. imgWidth:e.detail.width
  184. })
  185. },
  186. // 上传图片
  187. upImage(){
  188. this.getImage()
  189. let that=this
  190. wx.chooseImage({
  191. count: 1,
  192. sizeType: ['original', 'compressed'],
  193. sourceType: ['album', 'camera'],
  194. success (res) {
  195. console.log(res);
  196. // tempFilePath可以作为img标签的src属性显示图片
  197. const tempFilePaths = res.tempFilePaths[0]
  198. that.setData({
  199. imgUrl:tempFilePaths,
  200. flag:true,
  201. buttonFlag:true
  202. })
  203. }
  204. })
  205. },
  206. onReady() {
  207. },
  208. onShow() {
  209. },
  210. onShareAppMessage() {
  211. }
  212. })