<template>
    <view>
        <view class="mt16">
            <view class="bgTest va-center">
                <image src="http://matripe.oss-cn-beijing.aliyuncs.com/dagouAgency/wx.png" style="width: 46px; height: 46px; margin-left: 20px"></image>
                <text class="cardName">微信零钱</text>
            </view>

            <view @tap="toCardDetail" :data-item="item" class="cardbgTest va-center mt10" hover-class="thover" v-for="(item, index) in bankArray" :key="index">
                <view class="flex-1 va-center">
                    <view class="cardlogo">
                        <image :src="item.bankLogo"></image>
                    </view>
                    <text class="cardName">{{ item.bankName }}</text>
                </view>

                <view class="fr cf fw500 f18 mr16">{{ item.bankNo }}</view>
            </view>

            <!-- <view wx:if="{{user.idauth == 0}}" class="addcard v-center mt16" hover-class="thover" bindtap="showDialog">
    <i class="iconfont icon-tianjia mr8"></i>
    绑定银行卡
  </view>
  <navigator wx:if="{{user.idauth == 1}}" url="/pages/bindBankCard/index" class="addcard mt16 v-center" hover-class="thover">
    <i class="iconfont icon-tianjia mr8"></i>
    绑定银行卡
  </navigator> -->
        </view>
        <scroll-view class="fadeIn" v-if="iosDialog1" style="position: relative; z-index: 999">
            <view class="weui-mask"></view>
            <view class="weui-dialog">
                <view class="weui-dialog__hd"><strong class="weui-dialog__title">实名认证</strong></view>
                <view class="weui-dialog__bd">
                    <view>实名认证后才可以绑定银行卡，现在去实名吗?</view>
                </view>

                <view class="display-flex pb20">
                    <view class="flex-1 lflex v-center" @tap="close" hover-class="thover">取消</view>
                    <view class="rflex">
                        <button class="" type="" hover-class="thover" @click.stop="emptyMethod">去实名</button>
                    </view>
                </view>
            </view>
        </scroll-view>
    </view>
</template>

<script>
// pages/addCard/index.js
const app = getApp();
export default {
    data() {
        return {
            iosDialog1: false,
            user: {},
            bankArray: []
        };
    }
    /**
     * 生命周期函数--监听页面加载
     */,
    onLoad: function (options) {},
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {},
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        this.setData({
            user: app.globalData.user
        });
        this.getUserBankList();
    },
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {
        this.setData({
            iosDialog1: false
        });
    },
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {},
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {},
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {},
    methods: {
        showDialog() {
            this.setData({
                iosDialog1: true
            });
        },

        close: function () {
            this.setData({
                iosDialog1: false
            });
        },

        emptyMethod: function () {
            uni.navigateTo({
                url: '/pages/realName1/index'
            });
        },

        getUserBankList: function () {
            var that = this;
            uni.request({
                url: app.globalData.ip + '/user/bank/getUserBankList',
                data: {},
                header: app.globalData.headers,
                method: 'GET',
                success: function (res) {
                    console.log(res);
                    if (res.data.status == 200) {
                        if (app.globalData.isNotEmptyCheck(res.data.data) && res.data.data.length > 0) {
                            res.data.data.forEach((item) => {
                                if (app.globalData.isNotEmptyCheck(item.bankNo) && item.bankNo.length > 4) {
                                    item.bankNo = '****' + item.bankNo.substring(item.bankNo.length - 4);
                                } else {
                                    item.bankNo = '';
                                }
                                if (app.globalData.isEmptyCheck(item.bankLogo)) {
                                    item.bankLogo = 'http://matripe.oss-cn-beijing.aliyuncs.com/bankCard.png';
                                }
                            });
                        }
                        that.setData({
                            bankArray: res.data.data
                        });
                    } else {
                        app.globalData.showTips(that, res.data.msg);
                    }
                }
            });
        },

        toCardDetail: function (e) {
            var item = e.currentTarget.dataset.item;
            try {
                uni.setStorageSync('storageSyncBankDetail', item);
            } catch (e) {
                console.log('CatchClause', e);
                console.log('CatchClause', e);
                console.log('设置银行卡详情缓存错误', e);
            }
            uni.navigateTo({
                url: '/pages/cardDetail/index'
            });
        },

        /**
         * 用户点击右上角分享
         */
        onShareAppMessage1: function () {}
    }
};
</script>
<style>
@import './index.css';
</style>
