paymentCode.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  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 v-if="userInfo.headImg" :src="userInfo.headImg" alt="">
  11. <u-avatar v-else size="48"></u-avatar>
  12. </view>
  13. <view class="name">
  14. {{userInfo.name}}
  15. </view>
  16. </view>
  17. <view class="balance">
  18. <view class="title">
  19. 饭卡余额:
  20. </view>
  21. <view class="value">
  22. {{balance}} 元
  23. </view>
  24. </view>
  25. </view>
  26. <!-- 二维码 -->
  27. <view class="qr-code ">
  28. <div class="img" ref="qrCodeDiv"></div>
  29. <!-- <view class="img">
  30. <img src="../../assets/img/qrCode.png" alt="">
  31. <view class="qr-logo">
  32. <img src="../../assets/img/qrLogo.png" alt="">
  33. </view>
  34. </view> -->
  35. <view class="hint">
  36. 将二维码对准摄像头,即可付款就餐
  37. </view>
  38. </view>
  39. <!-- 付款中 -->
  40. <view class="paying" v-if="isPaying">
  41. <view class="loading-img">
  42. <img src="../../assets/img/if-spinner@1x.png" alt="">
  43. </view>
  44. <view class="">
  45. 付款中...
  46. </view>
  47. </view>
  48. <!-- 我的消费记录 -->
  49. <view class="consumption-record" @click="gotoUrl('pages/mine/myMealCard')">
  50. <view class="icon">
  51. <img src="../../assets/img/riLine-file-list-3-line@1x.png" alt="">
  52. </view>
  53. <view class="text">
  54. 我的消费记录
  55. </view>
  56. <view class="right">
  57. <u-icon name="arrow-right" color="#999999"></u-icon>
  58. </view>
  59. </view>
  60. </view>
  61. </view>
  62. </template>
  63. <script>
  64. import * as mineAPI from '@/apis/pagejs/mine.js'
  65. import QRCode from 'qrcodejs2'
  66. export default {
  67. data() {
  68. return {
  69. userInfo: {},
  70. balance: '',
  71. isPaying: false,
  72. card: '',
  73. time: ''
  74. }
  75. },
  76. onReady() {
  77. this.userInfo=this.carhelp.getPersonInfo();
  78. this.getLoadCardData();
  79. this.getCardAndTime();
  80. },
  81. methods: {
  82. getCardAndTime() {
  83. uni.showLoading({
  84. title: "加载中",
  85. mask: true,
  86. })
  87. mineAPI.getCardInfo().then((response) => {
  88. uni.hideLoading();
  89. this.card = response.data.cardId;
  90. var date = new Date();
  91. var year = date.getFullYear();
  92. var month = date.getMonth() + 1;
  93. var day = date.getDate();
  94. var hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
  95. var minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
  96. var second = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
  97. month >= 1 && month <= 9 ? (month = "0" + month) : "";
  98. day >= 0 && day <= 9 ? (day = "0" + day) : "";
  99. this.time = year + month + day + hour + minute + second;
  100. this.getQrcode();
  101. }).catch(error => {
  102. uni.showToast({
  103. title: error,
  104. icon: "none"
  105. })
  106. })
  107. },
  108. getPayAmount() {
  109. uni.showLoading({
  110. title: "加载中",
  111. mask: true,
  112. })
  113. mineAPI.payAmount().then((response) => {
  114. uni.hideLoading();
  115. }).catch(error => {
  116. uni.showToast({
  117. title: error,
  118. icon: "none"
  119. })
  120. })
  121. },
  122. getLoadCardData() {
  123. uni.showLoading({
  124. title: "加载中",
  125. mask: true,
  126. })
  127. mineAPI.loadCardData().then((response) => {
  128. uni.hideLoading();
  129. this.balance = response.data.balance;
  130. }).catch(error => {
  131. uni.showToast({
  132. title: error,
  133. icon: "none"
  134. })
  135. })
  136. },
  137. getQrcode() {
  138. this.$nextTick(() => {
  139. let div = document.createElement('div');// 创建一个div,用来生成二维码
  140. // 生成二维码
  141. let qrcode = new QRCode(div, {
  142. text: 'card='+this.card+'&time='+this.time, // 你的扫码内容,填网址
  143. width: 200, // 二维码宽度
  144. height: 200, // 二维码高度
  145. colorDark: "#333333", //二维码颜色
  146. colorLight: "#ffffff", //二维码背景色
  147. correctLevel: QRCode.CorrectLevel.H, //从上至下生成码密度越来越高 L - M - Q - H
  148. // 容错率越高,越复杂
  149. })
  150. let logo = new Image();
  151. logo.crossOrigin = 'Anonymous';
  152. logo.src = require("@/assets/img/qrLogo.png") // 填入你本地log图片
  153. // 生成log图
  154. logo.onload = () => {
  155. let container = this.$refs['qrCodeDiv'];
  156. // 获取页面上的div,可以使用document.querySelector()等等方法,不类推了
  157. if (container.innerHTML != "") {
  158. // 获取页面div , 有则清空已存在的
  159. container.innerHTML = ""
  160. }
  161. let qrImg = qrcode._el.getElementsByTagName('img')[0]; // 获取二维码
  162. let canvas = qrcode._el.getElementsByTagName('canvas')[0]; // 获取canvas
  163. let ctx = canvas.getContext("2d");
  164. ctx.drawImage(logo, 200 * 0.5 - 22, 200 * 0.5 - 22, 56, 56); // 写入log
  165. qrImg.src = canvas.toDataURL();
  166. container.appendChild(qrcode._el);
  167. }
  168. })
  169. }
  170. }
  171. }
  172. </script>
  173. <style lang="scss" scoped>
  174. .loading-img{
  175. animation: rotation 2s linear infinite;
  176. }
  177. @keyframes rotation{
  178. from {transform: rotate(0deg)}
  179. to {transform: rotate(360deg)}
  180. }
  181. page {
  182. background-color: #2A8EFB;
  183. font-family: 'PingFang Regular';
  184. }
  185. /deep/.u-navbar {
  186. background-color: #2A8EFB !important;
  187. }
  188. /deep/.u-title {
  189. color: #fff !important;
  190. font-weight: bold !important;
  191. }
  192. /deep/.uicon-nav-back {
  193. color: #fff !important
  194. }
  195. /deep/.u-border-bottom:after {
  196. border-bottom-width: 0px;
  197. }
  198. .content {
  199. border-radius: 24rpx;
  200. background-color: rgba(255, 255, 255, 1);
  201. margin: 48rpx 32rpx;
  202. // 饭卡信息
  203. .head {
  204. padding: 32rpx 0;
  205. margin: 0 32rpx;
  206. display: flex;
  207. justify-content: space-between;
  208. align-items: center;
  209. border-bottom: 1px solid rgba(232, 232, 232, 1);
  210. .person {
  211. display: flex;
  212. align-items: center;
  213. .photo {
  214. width: 48rpx;
  215. height: 48rpx;
  216. border-radius: 100rpx;
  217. overflow: hidden;
  218. img {
  219. width: 100%;
  220. height: 100%;
  221. }
  222. }
  223. .name {
  224. color: rgba(51, 51, 51, 1);
  225. font-size: 36rpx;
  226. margin-left: 16rpx;
  227. }
  228. }
  229. .balance {
  230. display: flex;
  231. align-items: center;
  232. color: rgba(16, 16, 16, 1);
  233. font-size: 32rpx;
  234. font-weight: bold;
  235. }
  236. }
  237. // 二维码
  238. .qr-code {
  239. padding: 80rpx 0;
  240. .img {
  241. width: 400rpx;
  242. height: 400rpx;
  243. position: relative;
  244. margin: 0 144rpx;
  245. img {
  246. width: 100%;
  247. height: 100%;
  248. }
  249. }
  250. .qr-logo {
  251. width: 112rpx;
  252. height: 112rpx;
  253. position: absolute;
  254. top: 0;
  255. left: 0;
  256. right: 0;
  257. bottom: 0;
  258. margin: auto;
  259. img {
  260. width: 100%;
  261. height: 100%;
  262. }
  263. }
  264. // 付款中
  265. }
  266. .hint {
  267. margin-top: 16rpx;
  268. color: rgba(51, 51, 51, 1);
  269. text-align: center;
  270. }
  271. //我的消费记录
  272. .consumption-record {
  273. display: flex;
  274. align-items: center;
  275. padding: 32rpx 0;
  276. margin: 0 32rpx;
  277. border-top: 1px solid rgba(232, 232, 232, 1);
  278. .icon {
  279. width: 40rpx;
  280. height: 40rpx;
  281. img {
  282. width: 100%;
  283. height: 100%;
  284. }
  285. }
  286. .text {
  287. color: rgba(51, 51, 51, 1);
  288. font-size: 32rpx;
  289. margin-left: 8rpx;
  290. }
  291. .right {
  292. margin-left: auto;
  293. }
  294. }
  295. }
  296. // 付款中
  297. .paying {
  298. width: 160rpx;
  299. height: 160rpx;
  300. border-radius: 8px;
  301. background-color: rgba(0, 0, 0, 1);
  302. color: #fff;
  303. padding: 22rpx 0;
  304. text-align: center;
  305. position: absolute;
  306. top: 440rpx;
  307. left: 0;
  308. right: 0;
  309. margin: auto;
  310. img {
  311. width: 72rpx;
  312. height: 72rpx;
  313. }
  314. }
  315. // 透明
  316. .opacity {
  317. opacity: 0.3;
  318. }
  319. </style>