card-detail.page.js 2.47 KB
/**
 * 银行卡详情
 * @author: wsl<shuiling.wang@yoho.cn>
 * @date: 2016/10/25
 */

var $ = require('yoho-jquery');
var tip = require('../plugin/tip');
var dialog = require('../plugin/dialog');
var cardDetail = {
    init: function() {
        var self = this,
            $relieveBtn = $('.relieve-btn'),
            $changeBtn = $('.change-btn');

        self.cardIdNo = $('.card-detail').data('cardId');

        if (window.queryString.setMaster) {
            tip.show('切换成功!');
        }

        $relieveBtn.on('click', function() {
            self.dialogAction({
                text: '你确定要解除绑定此卡吗?解除绑定后该银行卡将不出现在还款银行卡列表中。',
                url: '/home/installment/delBankCard',
                errorText: '解除失败',
                successAction: function() {
                    tip.show('解除成功!');
                    window.location.href = '/home/installment/bank-card';
                }
            });
        });

        $changeBtn.on('click', function() {
            self.dialogAction({
                text: '你确定要设置该银行卡为主卡吗?确定设置后原主卡将自动修改为副卡。',
                url: '/home/installment/setMasterCard',
                errorText: '切换失败',
                successAction: function() {
                    window.location.href = '/home/installment/card-detail?setMaster=true';
                }
            });
        });
    },
    dialogAction: function(params) {
        var self = this;

        dialog.showDialog({
            dialogText: params.text,
            hasFooter: {
                leftBtnText: '取消',
                rightBtnText: '确定'
            }
        }, function() {
            $.ajax({
                type: 'GET',
                url: params.url,
                data: {
                    cardIdNo: self.cardIdNo
                },
                success: function(data) {
                    dialog.hideDialog();
                    if (data.code === 200) {
                        params.successAction();
                    } else {
                        tip.show(params.errorText);
                    }
                    self.flag = false;
                },
                error: function() {
                    tip.show(params.errorText);
                    self.flag = false;
                }
            });
        });
    }
};

require('../common');

$(function() {
    cardDetail.init();
});