let excel = {
    download_trade_order_excel: function () {
        let startTime = $("#startTime").val();
        let endTime = $("#endTime").val();
        let payType = $("#payType").val();
        let uStatus = $("#uStatus").val();
        $.ajax({
            type: "GET",
            url: "/excel/make_order_excel/",
            data: {
                start: startTime,
                end: endTime,
                pay_type: payType,
                status: uStatus,
            },
            xhrFields: {
                responseType: "blob"
            },
            success: function (res) {
                // 下载二进制流
                const blob = new Blob([res], {
                    type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
                })
                const url = window.URL.createObjectURL(blob)
                let a = document.createElement("a");
                a.href = url;
                a.download = "订单记录.xlsx";
                a.target = "_blank";
                a.click();
                a.remove();
            },
            error: function (res) {
                toastr.info('something is wrong, code: ' + res.status)
            },
        })
    },
    download_complaint_record_excel: function () {
        let startTime = $("#startTime").val();
        let endTime = $("#endTime").val();
        let payType = $("#payType").val();
        let uStatus = $("#uStatus").val();
        $.ajax({
            type: "GET",
            url: "/excel/make_complaint_record_excel/",
            data: {
                start: startTime,
                end: endTime,
                pay_type: payType,
                status: uStatus,
            },
            cache: true,
            success: function (res) {
                if (res.code === 9) {
                    let $form = $("<form method='get'></form>");
                    $form.attr("action", "/excel/download_excel/" + res.msg);
                    $(document.body).append($form);
                    $form.submit()
                } else {
                    toastr.error(res.msg)
                }
            },
            error: function (XMLHttpRequest) {
                toastr.info('something is wrong, code: ' + XMLHttpRequest.status)
            }
        })
    },
    download_withdraw_record_excel: function () {
        let startTime = $("#startTime").val();
        let endTime = $("#endTime").val();
        let uStatus = $("#uStatus").val();
        $.ajax({
            type: "GET",
            url: "/excel/make_withdraw_record_excel/",
            data: {
                start: startTime,
                end: endTime,
                status: uStatus,
            },
            cache: true,
            success: function (res) {
                if (res.code === 9) {
                    let $form = $("<form method='get'></form>");
                    $form.attr("action", "/excel/download_excel/" + res.msg);
                    $(document.body).append($form);
                    $form.submit()
                } else {
                    toastr.error(res.msg)
                }
            },
            error: function (XMLHttpRequest) {
                toastr.info('something is wrong, code: ' + XMLHttpRequest.status)
            }
        })
    },
    download_recharge_record_excel: function () {
        let startTime = $("#startTime").val();
        let endTime = $("#endTime").val();
        let uStatus = $("#uStatus").val();
        $.ajax({
            type: "GET",
            url: "/excel/make_recharge_record_excel/",
            data: {
                start: startTime,
                end: endTime,
                status: uStatus,
            },
            cache: true,
            success: function (res) {
                if (res.code === 9) {
                    let $form = $("<form method='get'></form>");
                    $form.attr("action", "/excel/download_excel/" + res.msg);
                    $(document.body).append($form);
                    $form.submit()
                } else {
                    toastr.error(res.msg)
                }
            },
            error: function (XMLHttpRequest) {
                toastr.info('something is wrong, code: ' + XMLHttpRequest.status)
            }
        })
    }
};