//@ sourceURL=receipt.js
$(function (){
    $.ajax({
        type: "GET",
        contentType: "application/json;charset=UTF-8",
        url: "/thmz/getReceiptByCurrentUser",
        headers:{'Accept': 'application/json','Authorization':'Bearer '+ localStorage.getItem("token")},
        dataType: 'json',
        success: function(result) {
            if(result=='401' || result==401){
                window.location.href='/thmz/login/view'
                return;
            }
            if(result.code == 0) {
                var data = result.data;
                $("#receiptBegin").val(data.receiptBegin);
                $("#receiptCurrent").val(data.receiptCurrent);
                $("#receiptEnd").val(data.receiptEnd);
                $("#zyReceiptBegin").val(data.zyReceiptBegin);
                $("#zyReceiptCurrent").val(data.zyReceiptCurrent);
                $("#zyReceiptEnd").val(data.zyReceiptEnd);
            } else {
                errorMesage(result);
            }
        }
    });

    /**
     * 提交按钮点击事件
     */
    $("#send").on("click",function (t) {
        $.ajax({
            type: "POST",
            contentType: "application/json;charset=UTF-8",
            url: "/thmz/saveReceipt",
            dataType: 'json',
            data: JSON.stringify({"receiptBegin": $("#receiptBegin").val(),"receiptEnd":$("#receiptEnd").val(),"zyReceiptBegin": $("#zyReceiptBegin").val(),"zyReceiptEnd":$("#zyReceiptEnd").val()}),
            headers:{'Accept': 'application/json','Authorization':'Bearer '+ localStorage.getItem("token")},
            success: function(result) {
                if(result=='401' || result==401){
                    window.location.href='/thmz/login/view'
                    return;
                }
                if(result.code == 0) {
                    successMesage(result);
                    $("#receiptCurrent").val($("#receiptBegin").val());
                } else {
                    errorMesage(result);
                }
            }
        });
    });

});
