//提现明细

window.onload = function () {
    ifLogin(function (flag) {
        $('body').show();
        httpLoadInfo();
    });
}

function httpLoadInfo() {
    $.ajax({
        type: "post",
        url: base_api + 'user/fx-user/apply-commission-detail',
        dataType: 'json',
        success: function (res_data) {
            ZZLog(res_data);
            if (false == res_data['flag']) {
                if (codeNotLogin == res_data['code']) {
                    alert(infoNotLogin);
                    var URL = '/web/fx/withdrawal_list.html';
                    URL = encodeURI(URL);
                    location.href = res_data['url'] + URL;
                } else if (codeNotRegister == res_data['code']) {
                    location.href = 'register.html';
                } else {
                    alert(res_data['msg']);
                }
            } else {
                //..
                var data = res_data['data'];
                var apply_list = data['apply_list'];
                var HTML = '';
                var total_balance = 0;
                if (apply_list.length != 0)
//				total_balance = apply_list.map(c => c['apply_money']).reduce(function(a, b) { return parseInt(a) + parseInt(b) });
                    total_balance = apply_list.map(function (c) {
                        c['apply_money']
                    }).reduce(function (a, b) {
                        return ((100 * parseFloat(a) + 100 * parseFloat(b)) / 100);
                    });

                for (var i = 0, m = apply_list.length; i < m; i++) {
                    var dict = apply_list[i];
                    var tempHTML = getHTMLWithParam(dict);
                    HTML += tempHTML;
                }
//				$('#total_balance').text(`提现金额（累计${total_balance}元）`);
//				`提现金额（累计${total_balance}元）`
                $('#total_balance').text('提现金额（累计' + total_balance + '元）');
                $('.list_info').html(HTML);
                if (apply_list.length == 0) {
                    $('#no_info').show();
                }

            }
        },
        error: function () {
            alert(infoApiError);
        }
    });
}

function getHTMLWithParam(dict) {
    //1:待审核   2:已审核
    if ('1' == dict['status']) {
        var html1 = '<li class="ub tx-c ui_p_t13 ui_p_b13">' +
            '<div class="ub-f2 li_font_dark" style="width: 1%;">' + dict['create_date'] + '</div>' +
            '<div class="ub-f4 li_font_dark" style="width: 1%;">¥' + dict['apply_money'] + '</div>' +
            '<div class="ub-f2 li_font_red" style="width: 1%;">' + dict['status_desc'] + '</div>' +
            '</li>';
        return html1;
    } else {
        var html2 = '<li class="ub tx-c ui_p_t13 ui_p_b13">' +
            '<div class="ub-f2 li_font_dark" style="width: 1%;">' + dict['create_date'] + '</div>' +
            '<div class="ub-f4 li_font_dark" style="width: 1%;">¥' + dict['apply_money'] + '</div>' +
            '<div class="ub-f2 li_font_gray" style="width: 1%;">' + dict['status_desc'] + '</div>' +
            '</li>';
        return html2;
    }

}