payCode1.vue 12 KB

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