paymentCode.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. <template>
  2. <view>
  3. <u-navbar title="付款码">
  4. </u-navbar>
  5. <view class="content">
  6. <!-- 饭卡信息 -->
  7. <view class="head">
  8. <view class="person">
  9. <view class="photo">
  10. <img src="../../assets/img/shareP.png" alt="">
  11. </view>
  12. <view class="name">
  13. 王泽
  14. </view>
  15. </view>
  16. <view class="balance">
  17. <view class="title">
  18. 饭卡余额:
  19. </view>
  20. <view class="value">
  21. 330 元
  22. </view>
  23. </view>
  24. </view>
  25. <!-- 二维码 -->
  26. <view class="qr-code ">
  27. <div class="img" ref="qrCodeDiv"></div>
  28. <!-- <view class="img">
  29. <img src="../../assets/img/qrCode.png" alt="">
  30. <view class="qr-logo">
  31. <img src="../../assets/img/qrLogo.png" alt="">
  32. </view>
  33. </view> -->
  34. <view class="hint">
  35. 将二维码对准摄像头,即可付款就餐
  36. </view>
  37. </view>
  38. <!-- 付款中 -->
  39. <!-- <view class="paying">
  40. <img src="../../assets/img/if-spinner@1x.png" alt="">
  41. <view class="">
  42. 付款中...
  43. </view>
  44. </view> -->
  45. <!-- 我的消费记录 -->
  46. <view class="consumption-record" @click="gotoUrl('pages/mine/myMealCard')">
  47. <view class="icon">
  48. <img src="../../assets/img/riLine-file-list-3-line@1x.png" alt="">
  49. </view>
  50. <view class="text">
  51. 我的消费记录
  52. </view>
  53. <view class="right">
  54. <u-icon name="arrow-right" color="#999999"></u-icon>
  55. </view>
  56. </view>
  57. </view>
  58. </view>
  59. </template>
  60. <script>
  61. import QRCode from 'qrcodejs2'
  62. export default {
  63. data() {
  64. return {
  65. }
  66. },
  67. onReady() {
  68. this.getQrcode();
  69. },
  70. methods: {
  71. getQrcode() {
  72. this.$nextTick(() => {
  73. let div = document.createElement('div');// 创建一个div,用来生成二维码
  74. // 生成二维码
  75. let qrcode = new QRCode(div, {
  76. text: '123456789', // 你的扫码内容,填网址
  77. width: 200, // 二维码宽度
  78. height: 200, // 二维码高度
  79. colorDark: "#333333", //二维码颜色
  80. colorLight: "#ffffff", //二维码背景色
  81. correctLevel: QRCode.CorrectLevel.H, //从上至下生成码密度越来越高 L - M - Q - H
  82. // 容错率越高,越复杂
  83. })
  84. let logo = new Image();
  85. logo.crossOrigin = 'Anonymous';
  86. logo.src = require("@/assets/img/qrLogo.png") // 填入你本地log图片
  87. // 生成log图
  88. logo.onload = () => {
  89. let container = this.$refs['qrCodeDiv'];
  90. // 获取页面上的div,可以使用document.querySelector()等等方法,不类推了
  91. if (container.innerHTML != "") {
  92. // 获取页面div , 有则清空已存在的
  93. container.innerHTML = ""
  94. }
  95. let qrImg = qrcode._el.getElementsByTagName('img')[0]; // 获取二维码
  96. let canvas = qrcode._el.getElementsByTagName('canvas')[0]; // 获取canvas
  97. let ctx = canvas.getContext("2d");
  98. ctx.drawImage(logo, 200 * 0.5 - 22, 200 * 0.5 - 22, 56, 56); // 写入log
  99. qrImg.src = canvas.toDataURL();
  100. container.appendChild(qrcode._el);
  101. }
  102. })
  103. }
  104. }
  105. }
  106. </script>
  107. <style lang="scss" scoped>
  108. page {
  109. background-color: #2A8EFB;
  110. }
  111. /deep/.u-navbar {
  112. background-color: #2A8EFB !important;
  113. }
  114. /deep/.u-title {
  115. color: #fff !important;
  116. font-weight: bold !important;
  117. }
  118. /deep/.uicon-nav-back {
  119. color: #fff !important
  120. }
  121. /deep/.u-border-bottom:after {
  122. border-bottom-width: 0px;
  123. }
  124. .content {
  125. border-radius: 24rpx;
  126. background-color: rgba(255, 255, 255, 1);
  127. margin: 48rpx 32rpx;
  128. // 饭卡信息
  129. .head {
  130. padding: 32rpx 0;
  131. margin: 0 32rpx;
  132. display: flex;
  133. justify-content: space-between;
  134. align-items: center;
  135. border-bottom: 1px solid rgba(232, 232, 232, 1);
  136. .person {
  137. display: flex;
  138. align-items: center;
  139. .photo {
  140. width: 48rpx;
  141. height: 48rpx;
  142. border-radius: 100rpx;
  143. overflow: hidden;
  144. img {
  145. width: 100%;
  146. height: 100%;
  147. }
  148. }
  149. .name {
  150. color: rgba(51, 51, 51, 1);
  151. font-size: 36rpx;
  152. margin-left: 16rpx;
  153. }
  154. }
  155. .balance {
  156. display: flex;
  157. align-items: center;
  158. color: rgba(16, 16, 16, 1);
  159. font-size: 32rpx;
  160. font-weight: bold;
  161. }
  162. }
  163. // 二维码
  164. .qr-code {
  165. padding: 80rpx 0;
  166. .img {
  167. width: 400rpx;
  168. height: 400rpx;
  169. position: relative;
  170. margin: 0 144rpx;
  171. img {
  172. width: 100%;
  173. height: 100%;
  174. }
  175. }
  176. .qr-logo {
  177. width: 112rpx;
  178. height: 112rpx;
  179. position: absolute;
  180. top: 0;
  181. left: 0;
  182. right: 0;
  183. bottom: 0;
  184. margin: auto;
  185. img {
  186. width: 100%;
  187. height: 100%;
  188. }
  189. }
  190. // 付款中
  191. }
  192. .hint {
  193. margin-top: 16rpx;
  194. color: rgba(51, 51, 51, 1);
  195. text-align: center;
  196. }
  197. //我的消费记录
  198. .consumption-record {
  199. display: flex;
  200. align-items: center;
  201. padding: 32rpx 0;
  202. margin: 0 32rpx;
  203. border-top: 1px solid rgba(232, 232, 232, 1);
  204. .icon {
  205. width: 40rpx;
  206. height: 40rpx;
  207. img {
  208. width: 100%;
  209. height: 100%;
  210. }
  211. }
  212. .text {
  213. color: rgba(51, 51, 51, 1);
  214. font-size: 32rpx;
  215. margin-left: 8rpx;
  216. }
  217. .right {
  218. margin-left: auto;
  219. }
  220. }
  221. }
  222. // 付款中
  223. .paying {
  224. width: 160rpx;
  225. height: 160rpx;
  226. border-radius: 8px;
  227. background-color: rgba(0, 0, 0, 1);
  228. color: #fff;
  229. padding: 22rpx 0;
  230. text-align: center;
  231. position: absolute;
  232. top: 440rpx;
  233. left: 0;
  234. right: 0;
  235. margin: auto;
  236. img {
  237. width: 72rpx;
  238. height: 72rpx;
  239. }
  240. }
  241. // 透明
  242. .opacity {
  243. opacity: 0.3;
  244. }
  245. </style>