移动系统liao
2024-05-09 5d6cb15ac86d9174393cb9d1538d69b567e2c26c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<template>
    <view>
        <u-toast ref="uToast" /><u-no-network></u-no-network>
        <u-navbar title="我的银行卡" safeAreaInsetTop fixed placeholder>
            <view class="coreshop-navbar-left-slot" slot="left">
                <u-icon name="arrow-left" size="19" @click="goNavigateBack"></u-icon>
                <u-line direction="column" :hairline="false" length="16" margin="0 8px"></u-line>
                <u-icon name="home" size="22" @click="goHome"></u-icon>
            </view>
            <view slot="right">
            </view>
        </u-navbar>
        <view class="coreshop-tabbar-height" v-if="cards.length">
            <view class="card-item" v-for="(item, index) in cards" :key="index">
                <view class="card-item-tip" v-if="item.isdefault">
                    <view class="cit-bg"></view>
                    <view class="cit-text">默</view>
                </view>
                <view class="card-item-body">
                    <view class="cib-left">
                        <image class="bank-logo" :src="item.bankLogo" mode=""></image>
                    </view>
                    <view class="cib-right">
                        <view class="cibr-t color-3">
                            {{ item.bankName }} - {{ item.cardTypeName }}
                        </view>
                        <view class="cibr-b ">
                            {{ item.cardNumber }}
                        </view>
                    </view>
                </view>
                <view class="mr-card" v-if="item.isdefault === false">
                    <u-button @click="setDefault(item.id)" size="mini" :disabled='submitStatus' :loading='submitStatus' type="success">设为默认</u-button>
                </view>
                <view class="del-card" v-if="mold">
                    <u-button @click="selected(index)" size="mini" type="primary">选择</u-button>
                </view>
                <view class="del-card" v-else>
                    <u-button @click="removeCard(item.id)" size="mini" type="error" :disabled='delSubmitStatus' :loading='delSubmitStatus'>删除</u-button>
                </view>
            </view>
        </view>
        <!-- 无数据时默认显示 -->
        <view class="coreshop-emptybox" v-else>
            <u-empty :icon="$globalConstVars.apiFilesUrl+'/static/images/empty/coupon.png'" icon-size="150" text="暂无银行卡" mode="list"></u-empty>
        </view>
 
        <!--按钮-->
        <view class="coreshop-bg-white coreshop-footer-fixed coreshop-foot-padding-bottom">
            <u-button type="error" size="normal" @click="goAddcard()">添加银行卡</u-button>
        </view>
    </view>
</template>
 
<script>
    export default {
        data() {
            return {
                mold: '',
                cards: [],// 我的银行卡列表
                submitStatus: false,
                delSubmitStatus: false
            }
        },
        onLoad(options) {
            if (options.mold && options.mold == 'select') {
                this.mold = options.mold
            }
        },
        onShow() {
            this.getBankCards()
        },
        methods: {
            // 获取我的银行卡列表
            getBankCards() {
                this.$u.api.getBankCardList().then(res => {
                    if (res.status) {
                        this.cards = res.data
                    }
                })
            },
            // 删除银行卡
            removeCard(cardId) {
                let _that = this;
                this.$common.modelShow('提示', '确定删除该银行卡?', res => {
                    _that.delSubmitStatus = true;
                    let data = {
                        id: cardId
                    }
                    _that.$u.api.removeBankCard(data).then(res => {
                        if (res.status) {
                            _that.$refs.uToast.show({
                                message: res.msg, type: 'success', complete: function () {
                                    _that.delSubmitStatus = false;
                                    _that.getBankCards();
                                }
                            })
                        } else {
                            _that.$u.toast(res.msg);
                            _that.delSubmitStatus = false;
                        }
                    })
                })
            },
            // 设置默认卡
            setDefault(id) {
                let _that = this;
                _that.submitStatus = true;
                let data = {
                    id: id
                }
                _that.$u.api.setDefaultBankCard(data).then(res => {
                    _that.submitStatus = false;
                    if (res.status) {
                        _that.$refs.uToast.show({
                            message: res.msg, type: 'success', complete: function () {
                                _that.getBankCards();
                            }
                        })
                    } else {
                        _that.$u.toast(res.msg);
                    }
                });
            },
            // 添加新的银行卡
            goAddcard() {
                this.$u.route({ url: '/pages/member/balance/addBankCard/addBankCard' })
            },
            selected(index) {
                let pages = getCurrentPages();//当前页
                let beforePage = pages[pages.length - 2];//上个页面
 
                // #ifdef APP-PLUS || APP-PLUS-NVUE
                beforePage.cardInfo = this.cards[index]
                // #endif
 
                // #ifdef MP-WEIXIN
                beforePage.$vm.cardInfo = this.cards[index]
                // #endif
 
                // #ifdef MP-ALIPAY || MP-TOUTIAO
                this.$db.set('userCardInfo', this.cards[index], true);
                // #endif
 
                uni.navigateBack({
                    delta: 1
                })
            }
        }
    }
</script>
 
<style lang="scss" scoped>
    @import "bankcard.scss";
</style>