payCode1.vue 11 KB

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