payCode1.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. <template>
  2. <view class="container page" :style="getHeight">
  3. <!-- 公共组件-每个页面必须引入 -->
  4. <public-module></public-module>
  5. <view class="panel" id="panelcanvas">
  6. <view class="header">请扫描下方二维码进行付款</view>
  7. <view class="d-flex a-center j-center" style="margin-bottom: 20upx;color: #f00;" v-show="paycodeimg">
  8. <!-- <text>该二维码将于 {{endDateTime}} 失效</text> -->
  9. </view>
  10. <view class="d-flex a-center j-center qrcode">
  11. <image :src="paycodeimg" mode="widthFix"></image>
  12. </view>
  13. <view class="row d-flex">
  14. <view>投保人</view>
  15. <view>{{applyName}}</view>
  16. </view>
  17. <view class="row d-flex">
  18. <view>车牌号</view>
  19. <view>{{licenseNo}}</view>
  20. </view>
  21. <view class="row d-flex">
  22. <view>保险公司</view>
  23. <view>{{companyName}}</view>
  24. </view>
  25. <view v-if="jqpremium" class="row d-flex">
  26. <view>交强</view>
  27. <view>{{jqpremium}}</view>
  28. </view>
  29. <view class="row d-flex">
  30. <view>车船税</view>
  31. <view>{{taxamount}}</view>
  32. </view>
  33. <view v-if="jypremium" class="row d-flex">
  34. <view>驾意险</view>
  35. <view>{{jypremium}}</view>
  36. </view>
  37. <view v-if="sypremium" class="row d-flex">
  38. <view>商业</view>
  39. <view>{{sypremium}}</view>
  40. </view>
  41. <view class="row d-flex">
  42. <view>保费合计</view>
  43. <view style="font-size: 34upx;color: red;font-weight: bold;">¥{{sumPermium}}</view>
  44. </view>
  45. <view v-if="jqStartDate" class="row d-flex">
  46. <view>交强起保日期</view>
  47. <view>{{jqStartDate}}</view>
  48. </view>
  49. <view v-if="syStartDate" class="row d-flex">
  50. <view>商业起保日期</view>
  51. <view>{{syStartDate}}</view>
  52. </view>
  53. </view>
  54. <!-- #ifdef APP-PLUS -->
  55. <view class="tip d-flex a-center j-center" @tap="sendPayCode">发送到微信</view>
  56. <!-- #endif -->
  57. <view class="tip d-flex a-center j-center" @tap="navOrder">返回订单</view>
  58. <canvas id="mycanvas" ref="mycanvas" canvas-id="mycanvas" style="width: 1080px;height: 1680px;"></canvas>
  59. </view>
  60. </template>
  61. <script>
  62. import {
  63. mapState,
  64. mapMutations
  65. } from "vuex"
  66. import {
  67. pathToBase64,
  68. base64ToPath
  69. } from '@/common/pdf.js'
  70. import QR from "@/common/wxqrcode.js"
  71. export default {
  72. data() {
  73. return {
  74. paycodeimg: "",
  75. payImg: "",
  76. endDateTime: "",
  77. companyId: "",
  78. companyName: "", //保险公司名称
  79. sumPermium: "", //保费合计
  80. licenseNo: "", //车牌号
  81. applyName: "", //车主名字
  82. mobile: "", //车主手机号
  83. jqpremium: "",
  84. sypremium: "",
  85. taxamount: "",
  86. jypremium: "",
  87. jqStartDate: "",
  88. syStartDate: "",
  89. arr: false,
  90. posterUrl: "",
  91. }
  92. },
  93. computed: {
  94. ...mapState(['userInfo', 'token']),
  95. getHeight() {
  96. let height = uni.getSystemInfoSync().windowHeight;
  97. return `height: ${height}px;`;
  98. }
  99. },
  100. async onLoad(data) {
  101. if (!!data.companyId) {
  102. let params = {
  103. companyId: data.companyId
  104. };
  105. let res = await this.$http.get('/order/qrCode/getQrCode?areaCompanyId=' + data.companyId);
  106. //获取前一个页面传过来的信息(车辆信息,人员信息,险种信息)
  107. if (res.code == '200') {
  108. this.companyName = res.data.inscompany;
  109. this.sumPermium = res.data.sumpremium;
  110. this.licenseNo = res.data.cPlateNo;
  111. this.applyName = res.data.cInsuredNme;
  112. this.jqpremium = res.data.jqpremium; // 交强
  113. this.sypremium = res.data.sypremium; // 商业
  114. this.taxamount = res.data.taxamount; // 车船税
  115. this.jypremium = res.data.jypremium; // 驾意险
  116. this.jqStartDate = res.data.jqStartDate; // 交强起保日期
  117. this.syStartDate = res.data.syStartDate; // 商业起保日期
  118. this.paycodeimg = QR.createQrCodeImg(res.data.qrCodeUrl, {
  119. size: parseInt(300) //二维码大小
  120. })
  121. } else {
  122. uni.showModal({
  123. showCancel: false,
  124. title: res.msg
  125. })
  126. }
  127. } else {
  128. uni.showModal({
  129. showCancel: false,
  130. title: "未查询到该订单"
  131. })
  132. }
  133. },
  134. methods: {
  135. ...mapMutations(['setOrderType', 'setOrderStage']),
  136. async tpcodeconfirm() { //输入验证码,获取支付二维码
  137. let tpcode = {
  138. issueCode: this.tpcodevalue,
  139. orderno: this.orderno,
  140. }
  141. let tpcoderes = await this.$http.post('/API/insCBIT/taiPingPay', tpcode); //太平
  142. this.paycodeimg = QR.createQrCodeImg(JSON.parse(tpcoderes.data).payUrl, {
  143. size: parseInt(300) //二维码大小
  144. })
  145. },
  146. //发送收款码到微信
  147. sendPayCode() {
  148. // var that = this;
  149. // this.canvasPayImage();
  150. if (this.payImg) {
  151. uni.share({
  152. provider: "weixin",
  153. scene: "WXSceneSession",
  154. type: 2,
  155. imageUrl: this.payImg
  156. })
  157. }
  158. },
  159. // canvasPayImage() {
  160. // let myCanvas = uni.createCanvasContext('mycanvas', this);
  161. // var ww = '1080px';
  162. // var hh = '1680px';
  163. // //画布尺寸
  164. // // 坐标(0,0) 表示从此处开始绘制,相当于偏移。
  165. // //背景
  166. // myCanvas.drawImage('/static/image/car-insure/payBg.jpg', 0, 0, ww, hh);
  167. // // 失效时间
  168. // // if (!this.arr) {
  169. // // myCanvas.setFillStyle('#f00') //文字样式
  170. // // myCanvas.font = `40px Arial,sans-serif`; //绘制文字
  171. // // myCanvas.setTextAlign('center') //设置对于坐标点的对齐方式
  172. // // myCanvas.fillText('该二维码将于 ' + this.endDateTime + ' 失效', 540, 355);
  173. // // }
  174. // //二维码
  175. // myCanvas.drawImage(this.paycodeimg, 315, 415, 435, 435);
  176. // //个人信息
  177. // myCanvas.setFillStyle('#000') //文字样式
  178. // myCanvas.font = `44px Arial,sans-serif`; //绘制文字
  179. // myCanvas.setTextAlign('left')
  180. // myCanvas.fillText(this.applyName, 535, 965);
  181. // myCanvas.fillText(this.licenseNo, 535, 1085);
  182. // myCanvas.fillText(this.companyName, 535, 1205);
  183. // myCanvas.setFillStyle('#f00') //文字样式
  184. // myCanvas.font = `bold 48px Arial,sans-serif`; //绘制文字
  185. // myCanvas.fillText('¥' + this.sumPermium, 535, 1328);
  186. // //开始绘画,必须调用这一步,才会把之前的一些操作实施
  187. // myCanvas.draw(true, () => {
  188. // uni.hideLoading();
  189. // uni.canvasToTempFilePath({
  190. // canvasId: 'mycanvas',
  191. // success: (res) => {
  192. // // 在H5平台下,tempFilePath 为 base64
  193. // this.payImg = res.tempFilePath;
  194. // console.log(this.payImg)
  195. // },
  196. // fail: () => {
  197. // uni.showToast({
  198. // title: '生成支付码海报失败',
  199. // duration: 2000
  200. // });
  201. // }
  202. // });
  203. // });
  204. // },
  205. navOrder() {
  206. this.navigate({
  207. url: "/pages/orders/orders"
  208. }, "switchTab", true);
  209. },
  210. //页面截图转路径
  211. receiveRenderData(val) {
  212. this.posterUrl = val.replace(/[\r\n]/g, ''); // 去除base64位中的空格
  213. const imageStr = this.posterUrl;
  214. // 将base64转化为临时地址
  215. base64ToPath(imageStr).then(path => {
  216. this.payImg = path
  217. }).catch(error => {});
  218. },
  219. showLoading() {
  220. uni.showLoading({
  221. title: '正在生成图片'
  222. });
  223. },
  224. hideLoading() {
  225. uni.hideLoading();
  226. },
  227. }
  228. }
  229. </script>
  230. <script module="canvasImage" lang="renderjs">
  231. import html2canvas from 'html2canvas'
  232. export default {
  233. data() {
  234. return {
  235. }
  236. },
  237. mounted() {
  238. setTimeout(() => {
  239. this.canvasImage.generateImage()
  240. }, 1000);
  241. },
  242. methods: {
  243. generateImage() {
  244. setTimeout(() => {
  245. this.$ownerInstance.callMethod('showLoading')
  246. const dom = document.getElementById('panelcanvas') // 需要生成图片内容的 dom 节点
  247. html2canvas(dom, {
  248. width: dom.clientWidth, //dom 原始宽度
  249. height: dom.clientHeight,
  250. scrollY: 0, // html2canvas默认绘制视图内的页面,需要把scrollY,scrollX设置为0
  251. scrollX: 0,
  252. useCORS: true, //支持跨域
  253. // allowTaint: false,
  254. scale: 2, // 设置生成图片的像素比例,默认是1,如果生成的图片模糊的话可以开启该配置项
  255. }).then((canvas) => {
  256. // 生成成功
  257. this.$ownerInstance.callMethod('hideLoading')
  258. this.$ownerInstance.callMethod('receiveRenderData', canvas.toDataURL('image/png'))
  259. }).catch(err => {
  260. // 生成失败 弹出提示弹窗
  261. this.$ownerInstance.callMethod('_errAlert', `【生成图片失败,请重试】${err}`)
  262. })
  263. }, 300)
  264. }
  265. },
  266. }
  267. </script>
  268. <style lang="scss" scoped>
  269. @import '@/style/mixin.scss';
  270. .page {
  271. display: flex;
  272. flex-direction: column;
  273. justify-content: center;
  274. align-items: center;
  275. background-color: rgba($themeColor, 0.6);
  276. }
  277. .container {
  278. box-sizing: border-box;
  279. }
  280. .panel {
  281. display: flex;
  282. flex-direction: column;
  283. justify-content: space-between;
  284. align-items: stretch;
  285. box-sizing: border-box;
  286. width: 660upx;
  287. border-radius: 10upx;
  288. background-color: #fff;
  289. }
  290. .header {
  291. height: 100upx;
  292. background-color: #f0f0f0;
  293. border-radius: 10upx 10upx 0 0;
  294. text-align: center;
  295. line-height: 100upx;
  296. font-weight: bold;
  297. letter-spacing: 2px;
  298. margin-bottom: 20upx;
  299. color: rgba($themeColor, 0.6);
  300. }
  301. .row {
  302. height: 80upx;
  303. margin: 0upx 30upx;
  304. border-bottom: 1px solid #ddd;
  305. display: flex;
  306. justify-content: space-between;
  307. }
  308. .row>view {
  309. line-height: 80upx;
  310. font-size: 32upx;
  311. }
  312. .qrcode {
  313. margin: 10upx 0 20upx;
  314. }
  315. .qrcode image {
  316. width: 300upx;
  317. }
  318. .tip {
  319. width: 660upx;
  320. height: 90upx;
  321. background-color: #FFFFFF;
  322. margin-top: 30upx;
  323. border-radius: 10upx;
  324. font-size: 32upx;
  325. font-weight: bold;
  326. }
  327. #mycanvas {
  328. position: absolute;
  329. top: -10000px;
  330. left: -10000px;
  331. }
  332. </style>