paymentCode1.vue 12 KB

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