123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 |
- <template>
- <view class="bg">
- <app-layout :haveBackground="haveBackground">
- <view v-if="userInfo" class="main dir-top-nowrap main-center cross-center">
- <image class="avatar" :src="userInfo.avatar"></image>
- <view>会员付款码</view>
- <view style="color: #ff4544;">{{pay_code}}</view>
- <image class="qr" :src="file_path"></image>
- <view style="color: #999999;">5分钟过期,过期后自动刷新</view>
- <view>请提供二维码给店员扫码即可进行支付</view>
- <view class="balance main-between cross-center" @click="toBalance">
- <view class="dir-left-nowrap cross-center">
- <view class="icon main-center cross-center">
- <image src="/static/image/icon/cash/icon-balance.png"></image>
- </view>
- <view>账户余额</view>
- </view>
- <image class="right" src="/static/image/icon/arrow-right.png"></image>
- </view>
- </view>
- </app-layout>
- </view>
- </template>
- <script>
- import { mapState } from "vuex";
- export default {
- data() {
- return {
- haveBackground: false,
- pay_code: '',
- file_path: '',
- expiry_date: '',
- check: null,
- reload: null
- }
- },
- computed: {
- ...mapState({
- userInfo: state => state.user.info,
- })
- },
- onHide() {
- clearInterval(this.check);
- clearInterval(this.reload);
- },
- onUnload() {
- clearInterval(this.check);
- clearInterval(this.reload);
- },
- methods: {
- toBalance() {
- uni.navigateTo({
- url: `/pages/balance/balance`,
- });
- },
- checkTime() {
- let that = this;
- let timestamp = Date.parse(new Date()) /1000;
- let time = (that.expiry_date - timestamp) * 1000;
- this.reload = setTimeout(()=>{
- that.getList();
- },time)
- },
- getCode(pay_code) {
- let that = this;
- that.$request({
- url: that.$api.teller.search,
- data: {
- pay_code: pay_code
- },
- method: 'post'
- }).then(response=>{
- that.$hideLoading();
- if(response.code == 0 && this.userInfo) {
- if(response.data.is_use) {
- clearInterval(this.check);
- clearInterval(this.reload);
- uni.navigateTo({
- url: `/plugins/teller/result/result?code=` + pay_code,
- });
- }else {
- this.check = setTimeout(()=>{
- that.getCode(pay_code);
- },1000)
- }
- }
- }).catch(response => {
- that.$hideLoading();
- });
- },
- getList() {
- let that = this;
- that.$request({
- url: that.$api.teller.code,
- }).then(response=>{
- that.$hideLoading();
- if(response.code == 0) {
- that.pay_code = response.data.pay_code;
- that.file_path = response.data.file_path;
- that.expiry_date = response.data.expiry_date;
- that.getCode(response.data.pay_code);
- that.checkTime();
- }else {
- uni.showToast({
- title: response.msg,
- icon: 'none',
- duration: 1000
- });
- }
- }).catch(response => {
- that.$hideLoading();
- });
- },
- },
- onShow(options) {
- this.$showLoading({
- type: 'global',
- text: '加载中...'
- });
- this.getList();
- }
- }
- </script>
- <style scoped lang="scss">
- .bg {
- position: absolute;
- top: 0;
- left: 0;
- width: 100%;
- height: 100%;
- background: linear-gradient(to bottom, #495aff, #0ab6fe);
- }
- .main {
- margin: #{96rpx} auto;
- background-color: #fff;
- width: #{690rpx};
- height: #{980rpx};
- border-radius: #{16rpx};
- padding-bottom: #{110rpx};
- position: relative;
- view {
- margin: #{8rpx} 0;
- font-size: #{26rpx};
- }
- .avatar {
- position: absolute;
- left: 50%;
- top: #{-65rpx};
- border-radius: 50%;
- margin-left: #{-65rpx};
- z-index: 10;
- width: #{128rpx};
- height: #{128rpx};
- border: #{2rpx} solid #ffffff;
- }
- .qr {
- width: #{430rpx};
- height: #{430rpx};
- border-radius: #{16rpx};
- border: #{2rpx} solid #e2e2e2;
- margin-top: #{38rpx};
- margin-bottom: #{12rpx};
- }
- .balance {
- position: absolute;
- bottom: #{56rpx};
- background-color: #f0f0f0;
- height: #{120rpx};
- width: 100%;
- padding: 0 #{19rpx};
- color: #353535;
- .icon {
- width: #{72rpx};
- height: #{72rpx};
- border-radius: 50%;
- background-color: #fff;
- margin-right: #{19rpx};
- image {
- width: #{40rpx};
- height: #{40rpx};
- }
- }
- .right {
- width: #{12rpx};
- height: #{22rpx};
- }
- }
- }
- </style>
|