payCode1.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. <template>
  2. <view class="container page" :style="getHeight">
  3. <!-- 公共组件-每个页面必须引入 -->
  4. <public-module></public-module>
  5. <view class="panel">
  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="d-flex a-center j-center" style="margin-bottom: 20upx;color: #A0A7AF;">
  14. <text @tap="savePayCodeImg" v-show="payImg">保存收款码</text>
  15. </view>
  16. <view class="row d-flex">
  17. <view>投保人</view>
  18. <view>{{applyName}}</view>
  19. </view>
  20. <view class="row d-flex">
  21. <view>车牌号</view>
  22. <view>{{licenseNo}}</view>
  23. </view>
  24. <view class="row d-flex">
  25. <view>保险公司</view>
  26. <view>{{companyName}}</view>
  27. </view>
  28. <view class="row d-flex" style="margin-bottom: 20upx;border: none;">
  29. <view>保费合计</view>
  30. <view style="font-size: 34upx;color: red;font-weight: bold;">¥{{sumPermium}}</view>
  31. </view>
  32. </view>
  33. <!-- #ifdef APP-PLUS -->
  34. <view class="tip d-flex a-center j-center" @tap="sendPayCode">发送到微信</view>
  35. <!-- #endif -->
  36. <view class="tip d-flex a-center j-center" @tap="navOrder">返回订单</view>
  37. <canvas id="mycanvas" ref="mycanvas" canvas-id="mycanvas" style="width: 1080px;height: 1680px;"></canvas>
  38. </view>
  39. </template>
  40. <script>
  41. import {
  42. mapState,
  43. mapMutations
  44. } from "vuex"
  45. import {
  46. pathToBase64,
  47. base64ToPath
  48. } from '@/common/pdf.js'
  49. import QR from "@/common/wxqrcode.js"
  50. export default {
  51. data() {
  52. return {
  53. paycodeimg: "",
  54. payImg: "",
  55. endDateTime: "",
  56. orderno: "",
  57. companyName: "", //保险公司名称
  58. sumPermium: "", //保费合计
  59. licenseNo: "", //车牌号
  60. applyName: "", //车主名字
  61. mobile: "",
  62. }
  63. },
  64. computed: {
  65. ...mapState(['userInfo', 'token']),
  66. getHeight() {
  67. let height = uni.getSystemInfoSync().windowHeight;
  68. return `height: ${height}px;`;
  69. }
  70. },
  71. async onLoad(params) {
  72. if (!!params.orderno) {
  73. this.orderno = params.orderno;
  74. let res = await this.$http.get('/insOrder/queryOrder?orderno=' + params.orderno);
  75. if ((res.code == 200) && (res.data.orderstatus === '5')) {
  76. //获取前一个页面传过来的信息(车辆信息,人员信息,险种信息)
  77. var submitTime = new Date(res.data.submittime);
  78. this.endDateTime = submitTime.getFullYear() + "/" + (submitTime.getMonth() + 1) + "/" + submitTime
  79. .getDate() + " 23:00";
  80. this.companyName = res.data.inscompany;
  81. this.sumPermium = res.data.sumpremium;
  82. this.licenseNo = res.data.carinfo.licenseNo;
  83. this.applyName = res.data.applyinfo.name;
  84. this.mobile = res.data.applyinfo.mobile;
  85. //跳转永安支付
  86. switch (this.companyName) {
  87. case "永安财险":
  88. this.paycodeimg = QR.createQrCodeImg(this.$base.h5BaseUrl +
  89. "/#/pages/carInsure1/yonganCode?orderno=" + this.orderno + '&mobile=' + this
  90. .mobile, {
  91. size: parseInt(300) //二维码大小
  92. })
  93. break;
  94. case "中煤财险":
  95. let result = res.data.paymenttype.replace(/[\r\n]/g, "");
  96. let imgBase64 = `data:image/png;base64,${result}`;
  97. base64ToPath(imgBase64)
  98. .then(path => {
  99. this.paycodeimg = path;
  100. })
  101. break;
  102. case "人保财险":
  103. this.paycodeimg = QR.createQrCodeImg(res.data.paymenttype, {
  104. size: parseInt(300) //二维码大小
  105. })
  106. break;
  107. case "恒邦财险":
  108. this.paycodeimg = res.data.paymenttype;
  109. break;
  110. case "永诚财险":
  111. this.paycodeimg = QR.createQrCodeImg(res.data.paymenttype, {
  112. size: parseInt(300) //二维码大小
  113. })
  114. break;
  115. }
  116. } else {
  117. uni.showModal({
  118. showCancel: false,
  119. title: "该订单无效或已支付"
  120. })
  121. }
  122. } else {
  123. uni.showModal({
  124. showCancel: false,
  125. title: "未查询到该订单"
  126. })
  127. }
  128. },
  129. methods: {
  130. ...mapMutations(['setOrderType', 'setOrderStage']),
  131. async tpcodeconfirm() { //输入验证码,获取支付二维码
  132. let tpcode = {
  133. issueCode: this.tpcodevalue,
  134. orderno: this.orderno,
  135. }
  136. let tpcoderes = await this.$http.post('/API/insCBIT/taiPingPay', tpcode); //太平
  137. this.paycodeimg = QR.createQrCodeImg(JSON.parse(tpcoderes.data).payUrl, {
  138. size: parseInt(300) //二维码大小
  139. })
  140. },
  141. // 保存收款码
  142. savePayCodeImg() {
  143. var that = this;
  144. uni.saveImageToPhotosAlbum({
  145. filePath: that.payImg, // 图片文件路径,可以是临时文件路径也可以是永久文件路径,不支持网络图片路径
  146. success: () => {
  147. uni.showToast({
  148. title: '保存收款码成功',
  149. icon: "none",
  150. duration: 2000
  151. });
  152. },
  153. fail: (err) => {
  154. uni.showToast({
  155. title: '保存收款码失败',
  156. icon: "none",
  157. duration: 2000
  158. });
  159. }
  160. });
  161. },
  162. //发送收款码到微信
  163. sendPayCode() {
  164. var that = this;
  165. this.canvasPayImage();
  166. uni.share({
  167. provider: "weixin",
  168. scene: "WXSceneSession",
  169. type: 2,
  170. imageUrl: that.payImg
  171. })
  172. },
  173. canvasPayImage() {
  174. let myCanvas = uni.createCanvasContext('mycanvas', this);
  175. var ww = '1080px';
  176. var hh = '1680px';
  177. //画布尺寸
  178. // 坐标(0,0) 表示从此处开始绘制,相当于偏移。
  179. //背景
  180. myCanvas.drawImage('/static/image/car-insure/payBg.jpg', 0, 0, ww, hh);
  181. // 失效时间
  182. myCanvas.setFillStyle('#f00') //文字样式
  183. myCanvas.font = `40px Arial,sans-serif`; //绘制文字
  184. myCanvas.setTextAlign('center') //设置对于坐标点的对齐方式
  185. myCanvas.fillText('该二维码将于 ' + this.endDateTime + ' 失效', 540, 355);
  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. },
  207. fail: () => {
  208. uni.showToast({
  209. title: '生成支付码海报失败',
  210. duration: 2000
  211. });
  212. }
  213. });
  214. });
  215. },
  216. navOrder() {
  217. this.setOrderType(0);
  218. this.setOrderStage(3)
  219. this.navigate({
  220. url: "/pages/orders/orders"
  221. }, "switchTab", true);
  222. }
  223. }
  224. }
  225. </script>
  226. <style lang="scss" scoped>
  227. @import '@/style/mixin.scss';
  228. .page {
  229. display: flex;
  230. flex-direction: column;
  231. justify-content: center;
  232. align-items: center;
  233. background-color: rgba($themeColor, 0.6);
  234. }
  235. .container {
  236. padding: 100upx 0;
  237. box-sizing: border-box;
  238. }
  239. .panel {
  240. display: flex;
  241. flex-direction: column;
  242. justify-content: space-between;
  243. align-items: stretch;
  244. box-sizing: border-box;
  245. width: 660upx;
  246. border-radius: 10upx;
  247. background-color: #fff;
  248. }
  249. .header {
  250. height: 100upx;
  251. background-color: #f0f0f0;
  252. border-radius: 10upx 10upx 0 0;
  253. text-align: center;
  254. line-height: 100upx;
  255. font-weight: bold;
  256. letter-spacing: 2px;
  257. margin-bottom: 20upx;
  258. color: rgba($themeColor, 0.6);
  259. }
  260. .row {
  261. height: 80upx;
  262. margin: 0upx 30upx;
  263. border-bottom: 1px solid #ddd;
  264. display: flex;
  265. justify-content: space-between;
  266. }
  267. .row>view {
  268. line-height: 80upx;
  269. font-size: 32upx;
  270. }
  271. .qrcode {
  272. margin: 10upx 0 20upx;
  273. }
  274. .qrcode image {
  275. width: 300upx;
  276. }
  277. .tip {
  278. width: 660upx;
  279. height: 90upx;
  280. background-color: #FFFFFF;
  281. margin-top: 30upx;
  282. border-radius: 10upx;
  283. font-size: 32upx;
  284. font-weight: bold;
  285. }
  286. #mycanvas {
  287. position: absolute;
  288. top: -10000px;
  289. left: -10000px;
  290. }
  291. </style>