pay-qrcode.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <template>
  2. <view class="code-container">
  3. <view class="title center">{{isPayment? "向商家付款":"扫一扫,向我付款"}}</view>
  4. <view class="main-content">
  5. <view v-if="isPayment">
  6. <!-- 占位 -->
  7. <view style="height: 50rpx;"></view>
  8. <!-- 条形码 -->
  9. <view class="bar-code center">
  10. <tki-barcode
  11. ref="barcode"
  12. :val="content"
  13. onval=true
  14. :opations="barOption"
  15. /></view>
  16. <!-- 付款码 -->
  17. <view class="qr-code center">
  18. <tki-qrcode
  19. cid="2"
  20. ref="qrcode"
  21. :val="content"
  22. size="300"
  23. :onval="true"
  24. :loadMake="true"
  25. :usingComponents="true"
  26. />
  27. </view>
  28. </view>
  29. <!-- 收款码 -->
  30. <view v-else class="charge-code center">
  31. <tki-qrcode
  32. cid="1"
  33. ref="qrcode-charge"
  34. :val="id"
  35. size="420"
  36. :onval="true"
  37. :loadMake="true"
  38. :usingComponents="true"
  39. />
  40. </view>
  41. </view>
  42. <view class="footer center">
  43. <text class="text-xl text-bold">{{shopDetail.name}}</text>
  44. <!-- <view @click="isPayment=!isPayment" class="cu-btn round cuIcon-qrcode" style="font-size: 50rpx;height: 100rpx;" :style="{color: isPayment? 'orange':'green' }">
  45. <view class="text-black text-xl margin-left-30">{{ isPayment? " 切换收款码":"切换付款码"}}</view>
  46. </view> -->
  47. </view>
  48. </view>
  49. </template>
  50. <script>
  51. import tkiQrcode from "tki-qrcode"
  52. import tkiBarcode from "@/components/tki-barcode/tki-barcode.vue"
  53. import totp from "@/utils/totp.js"
  54. export default {
  55. components: { tkiBarcode,tkiQrcode},
  56. computed:{
  57. content(){
  58. let transformStr = (this.id*this.$global.TRANSFORM_PARAMS)*2
  59. return transformStr+this.secret
  60. }
  61. },
  62. data() {
  63. return {
  64. id: "",
  65. shopDetail:{},//商户详情
  66. avatar: "",
  67. secret: '000000',
  68. isPayment: false,
  69. timer: '',
  70. barOption: {
  71. width: 3,
  72. height: 130,
  73. displayValue: false
  74. }
  75. }
  76. },
  77. methods: {
  78. refreshCode(){
  79. this.timer = setInterval(()=>{
  80. this.secret = totp.getSecret(this.id);
  81. },1000)
  82. },
  83. async initAvatat(url){
  84. return new Promise((reslove,reject)=>{
  85. uni.downloadFile({
  86. url,
  87. success: (res)=> {
  88. reslove(res);
  89. },
  90. fail: (err) => {
  91. reject(err)
  92. }
  93. })
  94. })
  95. }
  96. },
  97. async mounted(option){
  98. let res=await this.$api.shop.detail({id:this.vuex_shopId})
  99. this.shopDetail=res.data
  100. let avatar=res.data.cover
  101. // this.avatar =(await this.initAvatat(avatar)).tempFilePath;
  102. //获取用户ID
  103. this.id = this.$global.QR_PATH+this.vuex_shopId
  104. //生成动态密码
  105. },
  106. beforeDestroy() {
  107. clearInterval(this.timer);
  108. }
  109. }
  110. </script>
  111. <style>
  112. page {
  113. background-color: #FE9644;
  114. }
  115. </style>
  116. <style lang="scss" scoped>
  117. .code-container{
  118. background-color: #FFFFFF;
  119. border-radius: 16rpx;
  120. // min-height: 900rpx;
  121. min-height: 800rpx;
  122. margin: 60rpx 20rpx;
  123. .title{
  124. border-radius: 25rpx 25rpx 0 0;
  125. height: 100rpx;
  126. width: 100%;
  127. font-size: 35rpx;
  128. color: #FD711B;
  129. background-color: #F7F7F7;
  130. font-weight: 600;
  131. letter-spacing: 3rpx;
  132. }
  133. .footer{
  134. width: 90%;
  135. height: 120rpx;
  136. margin-left: 5%;
  137. border-top: 1rpx dashed #dddddd;
  138. }
  139. .main-content{
  140. width: 100%;
  141. height: 600rpx;
  142. scroll-margin-top: 600rpx;
  143. // overflow: hidden;
  144. .bar-code{
  145. margin-left: 5%;
  146. width: 90%;
  147. height: 150rpx;
  148. }
  149. .qr-code{
  150. width: 100%;
  151. height: 450rpx;
  152. }
  153. .charge-code{
  154. width: 100%;
  155. height: 600rpx;
  156. transition: transform 1s ease-in-out;
  157. }
  158. }
  159. }
  160. </style>