paymentCode.vue 7.7 KB

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