payCode1.vue 10 KB

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