Blame view

public/js/home/card-detail.page.js 3.17 KB
王水玲 authored
1 2 3 4 5 6
/**
 * 银行卡详情
 * @author: wsl<shuiling.wang@yoho.cn>
 * @date: 2016/10/25
 */
陈峰 authored
7
let $ = require('yoho-jquery');
8 9 10
let tip = require('plugin/tip');
let dialog = require('plugin/dialog');
let yohoApp = require('yoho-app');
陈峰 authored
11
let cardDetail = {
王水玲 authored
12
    init: function() {
陈峰 authored
13
        let self = this,
王水玲 authored
14
            $relieveBtn = $('.relieve-btn'),
王水玲 authored
15 16
            $changeBtn = $('.change-btn'),
            asyncMode = yohoApp.isiOS;
王水玲 authored
17
王水玲 authored
18
        self.asyncMode = asyncMode;
王水玲 authored
19 20
        self.cardIdNo = $('.card-detail').data('cardId');
王水玲 authored
21 22
        $('body').attr('ontouchstart', true);
王水玲 authored
23 24 25 26 27 28 29
        $relieveBtn.on('click', function() {
            self.dialogAction({
                text: '你确定要解除绑定此卡吗?解除绑定后该银行卡将不出现在还款银行卡列表中。',
                url: '/home/installment/delBankCard',
                errorText: '解除失败',
                successAction: function() {
                    tip.show('解除成功!');
王水玲 authored
30 31 32 33 34 35 36
                    setTimeout(function() {
                        if (asyncMode) {
                            yohoApp.invokeMethod('go.relieveCardSuccess');
                        } else {
                            window.location.href = location.href + '&openby:yohobuy={"action":"go.relieveCardSuccess"}';
                        }
                    }, 1000);
王水玲 authored
37 38 39 40 41 42 43 44 45 46
                }
            });
        });

        $changeBtn.on('click', function() {
            self.dialogAction({
                text: '你确定要设置该银行卡为主卡吗?确定设置后原主卡将自动修改为副卡。',
                url: '/home/installment/setMasterCard',
                errorText: '切换失败',
                successAction: function() {
王水玲 authored
47
                    tip.show('切换成功!');
王水玲 authored
48 49 50 51
                    setTimeout(function() {
                        if (asyncMode) {
                            yohoApp.invokeMethod('go.instalmentMyCardList');
                        } else {
陈峰 authored
52 53
                            window.location.href = location.href +
                                '&openby:yohobuy={"action":"go.instalmentMyCardList"}';
王水玲 authored
54
                        }
王水玲 authored
55
                    }, 1000);
王水玲 authored
56 57 58 59 60
                }
            });
        });
    },
    dialogAction: function(params) {
陈峰 authored
61
        let self = this;
王水玲 authored
62
王水玲 authored
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
        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;
                }
            });
        });
    }
};
94
require('common');
王水玲 authored
95 96 97 98

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