card-detail.page.js 3.14 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 yohoApp = require('../yoho-app');
var cardDetail = {
    init: function() {
        var self = this,
            $relieveBtn = $('.relieve-btn'),
            $changeBtn = $('.change-btn'),
            asyncMode = yohoApp.isiOS;

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

        $('body').attr('ontouchstart', true);

        $relieveBtn.on('click', function() {
            self.dialogAction({
                text: '你确定要解除绑定此卡吗?解除绑定后该银行卡将不出现在还款银行卡列表中。',
                url: '/home/installment/delBankCard',
                errorText: '解除失败',
                successAction: function() {
                    tip.show('解除成功!');
                    setTimeout(function() {
                        if (asyncMode) {
                            yohoApp.invokeMethod('go.relieveCardSuccess');
                        } else {
                            window.location.href = location.href + '&openby:yohobuy={"action":"go.relieveCardSuccess"}';
                        }
                    }, 1000);
                }
            });
        });

        $changeBtn.on('click', function() {
            self.dialogAction({
                text: '你确定要设置该银行卡为主卡吗?确定设置后原主卡将自动修改为副卡。',
                url: '/home/installment/setMasterCard',
                errorText: '切换失败',
                successAction: function() {
                    tip.show('切换成功!');
                    setTimeout(function() {
                        if (asyncMode) {
                            yohoApp.invokeMethod('go.instalmentMyCardList');
                        } else {
                            window.location.href = location.href + '&openby:yohobuy={"action":"go.instalmentMyCardList"}';
                        }
                    }, 1000)
                }
            });
        });
    },
    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();
});