payCode1.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  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. case "紫金财险":
  129. case "国任财险":
  130. case "中国人寿":
  131. this.paycodeimg = QR.createQrCodeImg(res.data.paymentLink, {
  132. size: parseInt(300) //二维码大小
  133. })
  134. break;
  135. case "恒邦财险":
  136. this.paycodeimg = res.data.paymentLink;
  137. break;
  138. }
  139. } else {
  140. uni.showModal({
  141. showCancel: false,
  142. title: "未查询到该订单"
  143. })
  144. }
  145. },
  146. methods: {
  147. ...mapMutations(['setOrderType', 'setOrderStage']),
  148. async tpcodeconfirm() { //输入验证码,获取支付二维码
  149. let tpcode = {
  150. issueCode: this.tpcodevalue,
  151. orderno: this.orderno,
  152. }
  153. let tpcoderes = await this.$http.post('/API/insCBIT/taiPingPay', tpcode); //太平
  154. this.paycodeimg = QR.createQrCodeImg(JSON.parse(tpcoderes.data).payUrl, {
  155. size: parseInt(300) //二维码大小
  156. })
  157. },
  158. //发送收款码到微信
  159. sendPayCode() {
  160. // var that = this;
  161. // this.canvasPayImage();
  162. if (this.payImg) {
  163. uni.share({
  164. provider: "weixin",
  165. scene: "WXSceneSession",
  166. type: 2,
  167. imageUrl: this.payImg
  168. })
  169. }
  170. },
  171. // canvasPayImage() {
  172. // let myCanvas = uni.createCanvasContext('mycanvas', this);
  173. // var ww = '1080px';
  174. // var hh = '1680px';
  175. // //画布尺寸
  176. // // 坐标(0,0) 表示从此处开始绘制,相当于偏移。
  177. // //背景
  178. // myCanvas.drawImage('/static/image/car-insure/payBg.jpg', 0, 0, ww, hh);
  179. // // 失效时间
  180. // // if (!this.arr) {
  181. // // myCanvas.setFillStyle('#f00') //文字样式
  182. // // myCanvas.font = `40px Arial,sans-serif`; //绘制文字
  183. // // myCanvas.setTextAlign('center') //设置对于坐标点的对齐方式
  184. // // myCanvas.fillText('该二维码将于 ' + this.endDateTime + ' 失效', 540, 355);
  185. // // }
  186. // //二维码
  187. // myCanvas.drawImage(this.paycodeimg, 315, 415, 435, 435);
  188. // //个人信息
  189. // myCanvas.setFillStyle('#000') //文字样式
  190. // myCanvas.font = `44px Arial,sans-serif`; //绘制文字
  191. // myCanvas.setTextAlign('left')
  192. // myCanvas.fillText(this.applyName, 535, 965);
  193. // myCanvas.fillText(this.licenseNo, 535, 1085);
  194. // myCanvas.fillText(this.companyName, 535, 1205);
  195. // myCanvas.setFillStyle('#f00') //文字样式
  196. // myCanvas.font = `bold 48px Arial,sans-serif`; //绘制文字
  197. // myCanvas.fillText('¥' + this.sumPermium, 535, 1328);
  198. // //开始绘画,必须调用这一步,才会把之前的一些操作实施
  199. // myCanvas.draw(true, () => {
  200. // uni.hideLoading();
  201. // uni.canvasToTempFilePath({
  202. // canvasId: 'mycanvas',
  203. // success: (res) => {
  204. // // 在H5平台下,tempFilePath 为 base64
  205. // this.payImg = res.tempFilePath;
  206. // console.log(this.payImg)
  207. // },
  208. // fail: () => {
  209. // uni.showToast({
  210. // title: '生成支付码海报失败',
  211. // duration: 2000
  212. // });
  213. // }
  214. // });
  215. // });
  216. // },
  217. navOrder() {
  218. this.navigate({
  219. url: "/pages/orders/orders"
  220. }, "switchTab", true);
  221. },
  222. //页面截图转路径
  223. receiveRenderData(val) {
  224. this.posterUrl = val.replace(/[\r\n]/g, ''); // 去除base64位中的空格
  225. const imageStr = this.posterUrl;
  226. // 将base64转化为临时地址
  227. base64ToPath(imageStr).then(path => {
  228. this.payImg = path
  229. }).catch(error => {});
  230. },
  231. showLoading() {
  232. uni.showLoading({
  233. title: '正在生成图片'
  234. });
  235. },
  236. hideLoading() {
  237. uni.hideLoading();
  238. },
  239. }
  240. }
  241. </script>
  242. <script module="canvasImage" lang="renderjs">
  243. import html2canvas from 'html2canvas'
  244. export default {
  245. data() {
  246. return {
  247. }
  248. },
  249. mounted() {
  250. setTimeout(() => {
  251. this.canvasImage.generateImage()
  252. }, 1000);
  253. },
  254. methods: {
  255. generateImage() {
  256. setTimeout(() => {
  257. this.$ownerInstance.callMethod('showLoading')
  258. const dom = document.getElementById('panelcanvas') // 需要生成图片内容的 dom 节点
  259. html2canvas(dom, {
  260. width: dom.clientWidth, //dom 原始宽度
  261. height: dom.clientHeight,
  262. scrollY: 0, // html2canvas默认绘制视图内的页面,需要把scrollY,scrollX设置为0
  263. scrollX: 0,
  264. useCORS: true, //支持跨域
  265. // allowTaint: false,
  266. scale: 2, // 设置生成图片的像素比例,默认是1,如果生成的图片模糊的话可以开启该配置项
  267. }).then((canvas) => {
  268. // 生成成功
  269. this.$ownerInstance.callMethod('hideLoading')
  270. this.$ownerInstance.callMethod('receiveRenderData', canvas.toDataURL('image/png'))
  271. }).catch(err => {
  272. // 生成失败 弹出提示弹窗
  273. this.$ownerInstance.callMethod('_errAlert', `【生成图片失败,请重试】${err}`)
  274. })
  275. }, 300)
  276. }
  277. },
  278. }
  279. </script>
  280. <style lang="scss" scoped>
  281. @import '@/style/mixin.scss';
  282. .page {
  283. display: flex;
  284. flex-direction: column;
  285. justify-content: center;
  286. align-items: center;
  287. background-color: rgba($themeColor, 0.6);
  288. }
  289. .container {
  290. box-sizing: border-box;
  291. }
  292. .panel {
  293. display: flex;
  294. flex-direction: column;
  295. justify-content: space-between;
  296. align-items: stretch;
  297. box-sizing: border-box;
  298. width: 660upx;
  299. border-radius: 10upx;
  300. background-color: #fff;
  301. }
  302. .header {
  303. height: 100upx;
  304. background-color: #f0f0f0;
  305. border-radius: 10upx 10upx 0 0;
  306. text-align: center;
  307. line-height: 100upx;
  308. font-weight: bold;
  309. letter-spacing: 2px;
  310. margin-bottom: 20upx;
  311. color: rgba($themeColor, 0.6);
  312. }
  313. .row {
  314. height: 80upx;
  315. margin: 0upx 30upx;
  316. border-bottom: 1px solid #ddd;
  317. display: flex;
  318. justify-content: space-between;
  319. }
  320. .row>view {
  321. line-height: 80upx;
  322. font-size: 32upx;
  323. }
  324. .qrcode {
  325. margin: 10upx 0 20upx;
  326. }
  327. .qrcode image {
  328. width: 300upx;
  329. }
  330. .tip {
  331. width: 660upx;
  332. height: 90upx;
  333. background-color: #FFFFFF;
  334. margin-top: 30upx;
  335. border-radius: 10upx;
  336. font-size: 32upx;
  337. font-weight: bold;
  338. }
  339. #mycanvas {
  340. position: absolute;
  341. top: -10000px;
  342. left: -10000px;
  343. }
  344. </style>