index.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <template>
  2. <view class="bg">
  3. <app-layout :haveBackground="haveBackground">
  4. <view v-if="userInfo" class="main dir-top-nowrap main-center cross-center">
  5. <image class="avatar" :src="userInfo.avatar"></image>
  6. <view>会员付款码</view>
  7. <view style="color: #ff4544;">{{pay_code}}</view>
  8. <image class="qr" :src="file_path"></image>
  9. <view style="color: #999999;">5分钟过期,过期后自动刷新</view>
  10. <view>请提供二维码给店员扫码即可进行支付</view>
  11. <view class="balance main-between cross-center" @click="toBalance">
  12. <view class="dir-left-nowrap cross-center">
  13. <view class="icon main-center cross-center">
  14. <image src="/static/image/icon/cash/icon-balance.png"></image>
  15. </view>
  16. <view>账户余额</view>
  17. </view>
  18. <image class="right" src="/static/image/icon/arrow-right.png"></image>
  19. </view>
  20. </view>
  21. </app-layout>
  22. </view>
  23. </template>
  24. <script>
  25. import { mapState } from "vuex";
  26. export default {
  27. data() {
  28. return {
  29. haveBackground: false,
  30. pay_code: '',
  31. file_path: '',
  32. expiry_date: '',
  33. check: null,
  34. reload: null
  35. }
  36. },
  37. computed: {
  38. ...mapState({
  39. userInfo: state => state.user.info,
  40. })
  41. },
  42. onHide() {
  43. clearInterval(this.check);
  44. clearInterval(this.reload);
  45. },
  46. onUnload() {
  47. clearInterval(this.check);
  48. clearInterval(this.reload);
  49. },
  50. methods: {
  51. toBalance() {
  52. uni.navigateTo({
  53. url: `/pages/balance/balance`,
  54. });
  55. },
  56. checkTime() {
  57. let that = this;
  58. let timestamp = Date.parse(new Date()) /1000;
  59. let time = (that.expiry_date - timestamp) * 1000;
  60. this.reload = setTimeout(()=>{
  61. that.getList();
  62. },time)
  63. },
  64. getCode(pay_code) {
  65. let that = this;
  66. that.$request({
  67. url: that.$api.teller.search,
  68. data: {
  69. pay_code: pay_code
  70. },
  71. method: 'post'
  72. }).then(response=>{
  73. that.$hideLoading();
  74. if(response.code == 0 && this.userInfo) {
  75. if(response.data.is_use) {
  76. clearInterval(this.check);
  77. clearInterval(this.reload);
  78. uni.navigateTo({
  79. url: `/plugins/teller/result/result?code=` + pay_code,
  80. });
  81. }else {
  82. this.check = setTimeout(()=>{
  83. that.getCode(pay_code);
  84. },1000)
  85. }
  86. }
  87. }).catch(response => {
  88. that.$hideLoading();
  89. });
  90. },
  91. getList() {
  92. let that = this;
  93. that.$request({
  94. url: that.$api.teller.code,
  95. }).then(response=>{
  96. that.$hideLoading();
  97. if(response.code == 0) {
  98. that.pay_code = response.data.pay_code;
  99. that.file_path = response.data.file_path;
  100. that.expiry_date = response.data.expiry_date;
  101. that.getCode(response.data.pay_code);
  102. that.checkTime();
  103. }else {
  104. uni.showToast({
  105. title: response.msg,
  106. icon: 'none',
  107. duration: 1000
  108. });
  109. }
  110. }).catch(response => {
  111. that.$hideLoading();
  112. });
  113. },
  114. },
  115. onShow(options) {
  116. this.$showLoading({
  117. type: 'global',
  118. text: '加载中...'
  119. });
  120. this.getList();
  121. }
  122. }
  123. </script>
  124. <style scoped lang="scss">
  125. .bg {
  126. position: absolute;
  127. top: 0;
  128. left: 0;
  129. width: 100%;
  130. height: 100%;
  131. background: linear-gradient(to bottom, #495aff, #0ab6fe);
  132. }
  133. .main {
  134. margin: #{96rpx} auto;
  135. background-color: #fff;
  136. width: #{690rpx};
  137. height: #{980rpx};
  138. border-radius: #{16rpx};
  139. padding-bottom: #{110rpx};
  140. position: relative;
  141. view {
  142. margin: #{8rpx} 0;
  143. font-size: #{26rpx};
  144. }
  145. .avatar {
  146. position: absolute;
  147. left: 50%;
  148. top: #{-65rpx};
  149. border-radius: 50%;
  150. margin-left: #{-65rpx};
  151. z-index: 10;
  152. width: #{128rpx};
  153. height: #{128rpx};
  154. border: #{2rpx} solid #ffffff;
  155. }
  156. .qr {
  157. width: #{430rpx};
  158. height: #{430rpx};
  159. border-radius: #{16rpx};
  160. border: #{2rpx} solid #e2e2e2;
  161. margin-top: #{38rpx};
  162. margin-bottom: #{12rpx};
  163. }
  164. .balance {
  165. position: absolute;
  166. bottom: #{56rpx};
  167. background-color: #f0f0f0;
  168. height: #{120rpx};
  169. width: 100%;
  170. padding: 0 #{19rpx};
  171. color: #353535;
  172. .icon {
  173. width: #{72rpx};
  174. height: #{72rpx};
  175. border-radius: 50%;
  176. background-color: #fff;
  177. margin-right: #{19rpx};
  178. image {
  179. width: #{40rpx};
  180. height: #{40rpx};
  181. }
  182. }
  183. .right {
  184. width: #{12rpx};
  185. height: #{22rpx};
  186. }
  187. }
  188. }
  189. </style>