certificate.vue 6.0 KB

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