certificate - 副本.vue 6.4 KB

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