certificate.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. <template>
  2. <view class="pages">
  3. <!-- <web-view src="http://172.16.90.6:8080"></web-view> -->
  4. <!-- 画板 -->
  5. <l-painter ref="painter" :board="base"/>
  6. <view class="bottom-btn-wrap">
  7. <view class="bottom-btn-wrap-bg">
  8. <view class="bottom-btn btn" @click="download">
  9. 下载图片
  10. </view>
  11. </view>
  12. </view>
  13. <!-- <button class="generate-btn" id="mycanvas" @click="download()"></button> -->
  14. <!-- <view class="container" id="wrapper">
  15. <view class="image-wrapper draw">
  16. <image :src="$getimg+'cqtanhui-cert.jpg'" class="draw page-bg" mode="scaleToFill"></image>
  17. </view>
  18. <view class="draw cart-no">证书编号:{{item.credentialNo}}</view>
  19. <view class="cart-text cart-name">
  20. 尊敬的 {{item.customerName}}:
  21. </view>
  22. <view class="cart-text">
  23. 感谢您对“碳汇+”生态产品价值实现的支持,您购买了{{item.year}}年度碳汇量{{item.carbonAmount}}kg,您购碳资金{{item.orderAmount}}元,已全额转入{{item.farmerName}}的银行账户。
  24. </view>
  25. <view class="cart-text">
  26. 该笔碳汇可用于抵消您的碳排放
  27. </view>
  28. <view class="cart-text">
  29. 感谢您为生态文明建设和全球应对气候变化所做出的贡献
  30. </view>
  31. </view> -->
  32. </view>
  33. </template>
  34. <script>
  35. import lPainter from '@/components/lime-painter/index.vue';
  36. export default {
  37. components:{
  38. lPainter
  39. },
  40. data() {
  41. return {
  42. $getimg:this.$getimg,
  43. thetoken:'',
  44. orderid:'',
  45. item:[],
  46. path:'',
  47. params:{
  48. },
  49. base: {
  50. width: '750rpx',
  51. height: '1130rpx',
  52. views: [
  53. {
  54. type: 'image',
  55. src: 'http://fqn.hongweisoft.com/cqcarbon/wxapp/cqtanhui-cert.jpg',
  56. css: {
  57. left: '0rpx',
  58. top: '0rpx',
  59. width: '100%',
  60. height: '1130rpx'
  61. }
  62. },
  63. {
  64. type: 'text',
  65. text: '',
  66. css: {
  67. left: '100rpx',
  68. top: '350rpx',
  69. width: '550rpx',
  70. color:'#26D18B',
  71. textAlign: 'center',
  72. display:'block',
  73. }
  74. },
  75. {
  76. type: 'text',
  77. text: '',
  78. css: {
  79. left: '100rpx',
  80. top: '398rpx',
  81. width: '550rpx',
  82. fontSize: '28rpx',
  83. lineHeight: '36rpx',
  84. color:'#333',
  85. textAlign: 'left',
  86. }
  87. },
  88. {
  89. type: 'text',
  90. text: '',
  91. css: {
  92. width: '550rpx',
  93. left: '100rpx',
  94. top: '446rpx',
  95. fontSize: '28rpx',
  96. lineHeight: '36rpx',
  97. color:'#333',
  98. textAlign: 'left',
  99. textIndent: '2em'
  100. }
  101. },
  102. {
  103. type: 'text',
  104. text: '该笔碳汇可用于抵消您的碳排放',
  105. css: {
  106. width: '550rpx',
  107. left: '100rpx',
  108. top: '566rpx',
  109. fontSize: '28rpx',
  110. lineHeight: '36rpx',
  111. color:'#333',
  112. textAlign: 'left',
  113. textIndent: '2em'
  114. }
  115. },
  116. {
  117. type: 'text',
  118. text: '感谢您为生态文明建设和全球应对气候变化所做出的贡献',
  119. css: {
  120. width: '550rpx',
  121. left: '100rpx',
  122. top: '614rpx',
  123. fontSize: '28rpx',
  124. lineHeight: '36rpx',
  125. color:'#333',
  126. textAlign: 'left',
  127. textIndent: '2em'
  128. }
  129. },
  130. ]
  131. }
  132. }
  133. },
  134. onShow() {
  135. },
  136. onLoad(e) {
  137. this.thetoken = 'Bearer' + ' ' + this.$store.state.token;
  138. this.orderid = e.orderid;
  139. uni.showLoading({
  140. title: '正在获取证书信息'
  141. });
  142. this.$api.http.get(this.config.apiBaseurl + '/carbon-h5/wap/order/getCredentialByOrderId?orderId='+this.orderid,{
  143. header: {
  144. Accept:'application/json',
  145. Authorization: this.thetoken,
  146. },
  147. }).then(res => {
  148. uni.hideLoading();
  149. // this.info = Object.assign(this.info, data);
  150. // this.info.url = '/static/html2canvas/index.html?key=' + this.orderid;
  151. this.item = res.data.retBody;
  152. console.log('this.base.views',this.base.views);
  153. this.base.views[1].text = `证书编号:${res.data.retBody.credentialNo}`;
  154. this.base.views[2].text = `尊敬的 ${res.data.retBody.customerName}:`;
  155. this.base.views[3].text = `感谢您对“碳汇+”生态产品价值实现的支持,您购买了 ${res.data.retBody.year}年度碳汇量${res.data.retBody.carbonAmount}kg,您购碳资金${res.data.retBody.orderAmount}元,已全额转入${res.data.retBody.farmerName}的银行账户。`;
  156. console.log('res',JSON.parse(JSON.stringify(res.data.retBody)));
  157. }).catch(err =>{
  158. console.log('err',err)
  159. });
  160. },
  161. methods: {
  162. onRender() {
  163. // 支持通过调用render传入参数
  164. const painter = this.$refs.painter
  165. painter.render(this.base)
  166. },
  167. // canvasToTempFilePath() {
  168. // const painter = this.$refs.painter
  169. // // 支持通过调用canvasToTempFilePath方法传入参数 调取生成图片
  170. // painter.canvasToTempFilePath().then(res => this.path = res.tempFilePath)
  171. // },
  172. // // 支持通过调用canvasToTempFilePath方法传入参数 调取生成图片
  173. // onCanvasToTempFilePath() {
  174. // const painter = this.$refs.custom
  175. // painter.canvasToTempFilePath({dpr:2}).then(res => this.path = res.tempFilePath)
  176. // },
  177. download(){
  178. let self = this;
  179. const painter = this.$refs.painter;
  180. painter.canvasToTempFilePath().then(res => this.path = res.tempFilePath);
  181. console.log('this.path',this.path);
  182. uni.showLoading({
  183. title: '生成中'
  184. });
  185. setTimeout(this.saveImg,500);
  186. },
  187. saveImg(){
  188. let self = this;
  189. uni.saveImageToPhotosAlbum({
  190. filePath:this.path,
  191. success:function(res){
  192. uni.hideLoading();
  193. self.$api.msg('生成成功');
  194. },
  195. fail:function(err){
  196. uni.hideLoading();
  197. if(err.errMsg =="saveImageToPhotosAlbum:fail cancel"){
  198. return true;
  199. }
  200. self.$api.msg('生成失败请重试!');
  201. // self.$api.msg(err.errMsg);
  202. // if(err.errMsg == 'saveImageToPhotosAlbum:fail The "path" argument must be of type string. Received type object'){
  203. // self.$api.msg('生成失败请重试!')
  204. // }
  205. console.log('err',err)
  206. }
  207. });
  208. }
  209. }
  210. }
  211. </script>
  212. <style>
  213. @import url("./certificate.css");
  214. </style>