//查询报价单
function getQuotation(page, limit, startTime, endTime){
    layer.load(3);
    var url = "";
    if(idVal == "0"){ //未审核
        url = "/wxRefund/getUserRefund";
    } else { //已审核
        url = "/wxRefund/getAuditRefund";
    }
    $.ajax({
        url: url,
        type: "get",
        data: {
            "page": page,
            "limit": limit,
            "startTime": startTime,
            "endTime": endTime,
            "refundState": idVal
        },
        headers: {"token": localStorage.getItem("token")},
        dataType: "json",
        success: (data) => {
            if(data.msg == "200"){
                $(".content_div div").remove();
                $.each(data.data, (index, item) => {
                    //状态显示
                    var buttonElem = "";
                    if(item.refundState == "0"){ //未审核
                        buttonElem = "<button class=\"ignore_button button_div_head\" onclick='ignoreClick(this)'><img src=\"/images/demandForSingle/ban.png\"/><span data-locale=\"jujue\">"+ paramReturn("拒绝", parent.type) +"</span></button>\n" +
                            "<button class=\"offer_button button_div_head\" onclick='offerClick(this)'><img src=\"/images/refund/tongyi.png\"/><span data-locale=\"tongyituikuan\">"+ paramReturn("同意退款", parent.type) +"</span></button>\n";
                    } else if(item.refundState == "1"){ //已同意
                        buttonElem = "<button class=\"offer_button button_div_head audit_refund\"><img src=\"/images/refund/yitongyi.png\"/><span data-locale=\"yitongyi\">"+ paramReturn("已同意", parent.type) +"</span></button>\n";
                    } else if(item.refundState == "2"){ //拒绝
                        buttonElem = "<button class=\"ignore_button button_div_head audit_refund\"><img src=\"/images/refund/refused.png\"/><span data-locale=\"yijujue\">"+ paramReturn("已拒绝", parent.type) +"</span></button>\n" +
                            "<button class=\"offer_button button_div_head\" onclick='offerClick(this)'><img src=\"/images/refund/tongyi.png\"/><span data-locale=\"tongyituikuan\">"+ paramReturn("同意退款", parent.type) +"</span></button>\n";
                    }
                    $(".content_div").append("<div uuid="+ AES_ECB_encrypt(AES_ECB_encrypt(item.releaseUuid, null), null) +" class=\"content_column\">\n" +
                        "<div class=\"content_div_input\">\n" +
                        "<div class=\"head_name\" style=\"width: 5%;\">"+ (index + 1) +"</div>\n" +
                        "<div class=\"head_name\" style=\"width: 20%;\">"+ item.offerName +"</div>\n" +
                        "<div class=\"head_name\" style=\"width: 15%;\">"+ item.uuid +"</div>\n" +
                        "<div class=\"head_name\" style=\"width: 10%;\">"+ item.jdrq.split(" ")[0] +"</div>\n" +
                        "<div class=\"head_name\" style=\"width: 10%;\">"+ (item.refundType == "1"  ? ""+ paramReturn("部分退款", parent.type) +"" : ""+ paramReturn("全部退款", parent.type) +"") +"</div>\n" +
                        "<div class=\"head_name\" style=\"width: 10%;\">"+ item.refundReason.split(",")[0] +"</div>\n" +
                        "<div class=\"head_name\" style=\"width: 10%;\">"+ item.refundFee +"</div>\n" +
                        "<div class=\"head_name\" style=\"width: 20%;\">\n" +
                        buttonElem +
                        "</div>\n" +
                        "</div>\n" +
                        "</div>")
                });
                //自定义样式分页
                laypage.render({
                    elem: 'demo2'
                    ,count: data.count
                    ,theme: '#1E9FFF'
                    , limit: limit
                    , curr: page
                    , jump: function (obj,first) {
                        if (!first) {
                            getQuotation(obj.curr,obj.limit, startTime, endTime);
                        }
                    }
                    , prev: '<em><i class="layui-icon">&#xe603;</i></em>'
                    , next: '<em><i class="layui-icon">&#xe602;</i></em>'
                });
            }
            layer.closeAll("loading");
        },
        error: () => {
            layer.alert(paramReturn("服务器异常，请联系管理员", parent.type), {icon: 2});
            layer.closeAll("loading");
        }
    });
}
//同意退款
function offerClick(obj){
    layer.load(3);
    var uuid = $(obj).parent().parent().parent().attr("uuid");
    $.ajax({
        url: "/wxRefund/refusedRefund",
        type: "put",
        data: {
            "refundState": "1",
            "releaseUuid": AES_ECB_decrypt(AES_ECB_decrypt(uuid, null), null)
        },
        headers: {"token": localStorage.getItem("token")},
        dataType: "json",
        success: (data) => {
            if(data.msg == "200"){
                layer.msg(data.data, {icon: 1});
            } else {
                layer.msg(data.data, {icon: 2});
            }
            getQuotation(1, 7, startTime, endTime);//查询报价单数据渲染
            layer.closeAll("loading");
        },
        error: () => {
            layer.alert(paramReturn("服务器异常，请联系管理员", parent.type), {icon: 2});
            layer.closeAll("loading");
        }
    });
}
//拒绝
function ignoreClick(obj){
    layer.load(3);
    var uuid = $(obj).parent().parent().parent().attr("uuid");
    $.ajax({
        url: "/wxRefund/refusedRefund",
        type: "put",
        data: {
            "refundState": "2",
            "releaseUuid": AES_ECB_decrypt(AES_ECB_decrypt(uuid, null), null)
        },
        headers: {"token": localStorage.getItem("token")},
        dataType: "json",
        success: (data) => {
            layer.closeAll("loading");
            if(data.msg == "200"){
                layer.msg(data.data, {icon: 1});
                getQuotation(1, 7, startTime, endTime);//查询报价单数据渲染
            }
        },
        error: () => {
            layer.alert(paramReturn("服务器异常，请联系管理员", parent.type), {icon: 2});
            layer.closeAll("loading");
        }
    });
}