//查询路线
function getQuotation(page, limit, startTime, endTime, destination){
    layer.load(3);
    $.ajax({
        url: "/releaseCotroller/getRelease",
        type: "get",
        data: {
            "page": page,
            "limit": limit,
            "startTime": startTime,
            "endTime": endTime,
            "destination": destination
        },
        headers: {"token": token},
        dataType: "json",
        success: (data) => {
            if(data.msg == "200"){
                $(".content_div div").remove();
                $.each(data.data, (index, item) => {
                    $(".content_div").append("<div uuid="+ item.uuid +" class=\"content_column\">\n" +
                        "<div class=\"content_div_input\">\n" +
                        "<div class=\"head_name\" style=\"width: 10%;\">"+ (index + 1) +"</div>\n" +
                        "<div class=\"head_name\" style=\"width: 15%;\">"+ item.origin +"</div>\n" +
                        "<div class=\"head_name\" style=\"width: 15%;\">"+ item.destination +"</div>\n" +
                        "<div class=\"head_name\" style=\"width: 20%;\">"+ item.startTime +" - "+ item.endTime +"</div>\n" +
                        "<div class=\"head_name\" style=\"width: 15%;\">"+ item.peopleNum +"</div>\n" +
                        "<div class=\"head_name\" style=\"width: 25%;\">\n" +
                        "<button class=\"offer_button button_div_head\" onclick='offerClick(this)' data-locale=\"xiugai\"><img src=\"/images/demandForSingle/offer.png\"/>"+ paramReturn("修改", parent.type) +"</button>\n" +
                        "<button class=\"delete_button button_div_head\" onclick='deleteClick(this)'><img src=\"/images/demandForSingle/offer.png\"/>"+ (item.stateType == "0" ? "未上架" : "已上架") +"</button>\n" +
                        "</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, destination);
                        }
                    }
                    , prev: '<em><i class="layui-icon">&#xe603;</i></em>'
                    , next: '<em><i class="layui-icon">&#xe602;</i></em>'
                });
            }
            layer.closeAll("loading");
        },
        error: () => {
            layer.alert("服务器异常，请联系管理员", {icon: 2});
            layer.closeAll("loading");
        }
    });
}
//修改
function offerClick(obj){
    let uuid = $(obj).parent().parent().parent().attr("uuid");
    window.location.href = "/page/releaseModel?type=updateReleaseVal&uuid=" + uuid;
}
//删除路线
function deleteClick(obj){
    var buttonName = $(obj).text();
    let messageName = buttonName == "已上架" ? "下架": "上架";
    parent.layer.confirm("确认要"+ messageName +"此路线吗?",{
        btn: ['确认', '取消'],
        title: false,
        skin: 'layclass'
    }, function () {
        layer.load(3);
        var uuid = $(obj).parent().parent().parent().attr("uuid");
        let stateType = buttonName == "已上架" ? "0": "1";
        $.ajax({
            async: false,
            url: "/releaseCotroller/delRelease",
            type: "delete",
            data: {
                "uuid": uuid,
                "stateType": stateType
            },
            headers: {"token": localStorage.getItem("token")},
            dataType: "json",
            success: (data) => {
                if(data.msg == "200"){
                    getQuotation(1, 7, startTime, endTime, destination);//查询报价单数据渲染
                    parent.layer.msg("修改成功", {icon: 1});
                }
                parent.layer.closeAll("loading");
            },
            error: () => {
                parent.layer.alert("服务器异常，请联系管理员", {icon: 2});
                parent.layer.closeAll("loading");
            }
        });
    }, function (){
        parent.layer.closeAll();
    })
}
//查询供应商信息
function getCompany(){
    var company = null;
    $.ajax({
        async: false,
        url: "/personal/getPresonalMessage",
        type: "get",
        data: {},
        headers: {"token": localStorage.getItem("token")},
        dataType: "json",
        success: (data) => {
            company = data.data.company;
            layer.closeAll("loading");
        },
        error: () => {
            layer.alert("服务器异常，请联系管理员", {icon: 2});
            layer.closeAll("loading");
        }
    });
    return company;
}