payCode1.vue 9.7 KB

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