//点击列表弹出框
function contentHide(obj){
    if($(obj).find(".hide_content").hasClass("show_content")){
        init();
    } else {
        init();
        $(obj).find(".hide_content").addClass("show_content");
        $(obj).find("i").addClass("layui-icon-triangle-d");
        $(obj).find(".content_div_input").addClass("content_div_input_click");
    }
}
//列表恢复初始化
function init(){
    $(".hide_content").removeClass("show_content");
    $(".content_div_input i").removeClass("layui-icon-triangle-d");
    $(".content_column i").addClass("layui-icon-triangle-r");
    $(".content_div_input").removeClass("content_div_input_click");
}
//查询报价单
function getQuotation(page, limit, startTime, endTime, destination){
    layer.load(3);
    $.ajax({
        url: "/privateOrder/getPrivateOrder",
        type: "get",
        data: {
            "page": page,
            "limit": limit,
            "startTime": startTime,
            "endTime": endTime,
            "destination": destination,
            "orderType": idVal
        },
        headers: {"token": token},
        dataType: "json",
        success: (data) => {
            if(data.msg == "200"){
                $(".content_div div").remove();
                $.each(data.data, (index, item) => {
                    var type = "待回答";
                    var buttonElem = "<button class=\"ignore_button button_div_head\" onclick='ignoreClick(this)'><img src=\"/images/demandForSingle/ban.png\"/><span data-locale=\"hulue\">"+ paramReturn("忽略", parent.type) +"</span></button>\n" +
                        "<button class=\"offer_button button_div_head\" onclick='offerClick(this)'><img src=\"/images/demandForSingle/offer.png\"/><span data-locale=\"tigongbaojia\">"+ paramReturn("提供报价", parent.type) +"</span></button>\n"
                    if(item.orderType == 0){
                        type = "待回答";
                    }else if(item.orderType == 1){
                        type = "已回答";
                        buttonElem = "<button class=\"offer_button button_div_head\" onclick='offerClick(this)'><img src=\"/images/demandForSingle/offer.png\"/><span data-locale=\"xiugai\">"+ paramReturn("修改报价", parent.type) +"</span></button>\n";
                    }else if(item.orderType == 5){
                        type = "已完成";
                        buttonElem = "<button class=\"offer_button button_div_head\" onclick='offerClick(this)'><img src=\"/images/demandForSingle/offer.png\"/><span data-locale=\"chakan\">"+ paramReturn("查看", parent.type) +"</span></button>\n";
                    }else if(item.orderType == 3){
                        type = "行程开始";
                        buttonElem = "<button class=\"offer_button button_div_head\" onclick='offerClick(this)'><img src=\"/images/demandForSingle/offer.png\"/><span data-locale=\"chakan\">"+ paramReturn("查看", parent.type) +"</span></button>\n" +
                            "<button class=\"offer_button button_div_head\" onclick='offerClick(this)' name='交通信息'><img src=\"/images/demandForSingle/offer.png\"/><span data-locale=\"jiaotongxinxi\">"+ paramReturn("交通信息", parent.type) +"</span></button>\n";
                    }else if(item.orderType == 2){
                        type = "已付费";
                        buttonElem = "<button class=\"offer_button button_div_head\" onclick='offerClick(this)'><img src=\"/images/demandForSingle/offer.png\"/><span data-locale=\"chakan\">"+ paramReturn("查看", parent.type) +"</span></button>\n" +
                            "<button class=\"offer_button button_div_head\" onclick='offerClick(this)' name='交通信息'><img src=\"/images/demandForSingle/offer.png\"/><span data-locale=\"jiaotongxinxi\">"+ paramReturn("交通信息", parent.type) +"</span></button>\n";
                    }else if(item.orderType == 4){
                        type = "行程结束";
                        buttonElem = "<button class=\"offer_button button_div_head\" onclick='offerClick(this)'><img src=\"/images/demandForSingle/offer.png\"/><span data-locale=\"chakan\">"+ paramReturn("查看", parent.type) +"</span></button>\n" +
                            "<button class=\"offer_button button_div_head\" onclick='offerClick(this)'  name='交通信息'><img src=\"/images/demandForSingle/offer.png\"/><span data-locale=\"jiaotongxinxi\">"+ paramReturn("交通信息", parent.type) +"</span></button>\n";
                    }else if(item.orderType == 6){
                        type = "不感兴趣";
                    }else if(item.orderType == 9){
                        type = "取消行程";
                        buttonElem = "<button class=\"offer_button button_div_head\" onclick='offerClick(this)'><img src=\"/images/demandForSingle/offer.png\"/><span data-locale=\"chakan\">"+ paramReturn("查看", parent.type) +"</span></button>\n";
                    } else if(item.orderType == 12){
                        type = "已上传交通信息";
                        buttonElem = "<button class=\"offer_button button_div_head\" onclick='offerClick(this)'><img src=\"/images/demandForSingle/offer.png\"/><span data-locale=\"chakan\">"+ paramReturn("查看", parent.type) +"</span></button>\n" +
                            "<button class=\"offer_button button_div_head\" onclick='offerClick(this)' name='交通信息'><img src=\"/images/demandForSingle/offer.png\"/><span data-locale=\"jiaotongxinxi\">"+ paramReturn("交通信息", parent.type) +"</span></button>\n";
                    }
                    $(".content_div").append("<div uuid="+ item.uuid +" 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: 5%;\">\n" +
                        // "<i class=\"layui-icon layui-icon-triangle-r\"></i>\n" +
                        // "</div>\n" +
                        "<div class=\"head_name\" style=\"width: 15%;\">"+ item.origin +"</div>\n" +
                        "<div class=\"head_name\" style=\"width: 10%;\">"+ item.destination +"</div>\n" +
                        "<div class=\"head_name\" style=\"width: 15%;\">"+ item.startTime +" - "+ item.endTime +"</div>\n" +
                        "<div class=\"head_name\" style=\"width: 15%;\">"+ fixedReturn("peopleNum", item.peopleNum) +"</div>\n" +
                        "<div class=\"head_name\" style=\"width: 10%;\">"+ item.budgetMin +" - "+ item.budgetMax +"</div>\n" +
                        "<div class=\"head_name\" style=\"width: 10%;\">"+ type +"</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>'
                });
                if(idVal == 0){
                    if(data.count != 0){
                        parent.$(".layui-nav-child .message_num").html(data.count).show();
                    } else {
                        parent.$(".layui-nav-child .message_num").html(0).hide();
                    }
                }
            }
            layer.closeAll("loading");
        },
        error: () => {
            layer.alert(paramReturn("服务器异常，请联系管理员", parent.type), {icon: 2});
            layer.closeAll("loading");
        }
    });
}
//忽略
function ignoreClick(obj){
    var uuid = $(obj).parent().parent().parent().attr("uuid");
    window.event.cancelBubble = true;//阻止冒泡
    layer.confirm('确认忽略吗?', function (index) {
        layer.load(3);
        $.ajax({
            url: "/privateOrder/addIgnore",
            type: "post",
            data: {
                "orderingUuid": uuid
            },
            headers: {"token": token},
            dataType: "json",
            success: (data) => {
                layer.msg(paramReturn("忽略成功", parent.type), {icon: 1});
                getQuotation(0, 7, startTime, endTime);//查询报价单数据渲染
                layer.closeAll("loading");
            },
            error: () => {
                layer.alert(paramReturn("服务器异常，请联系管理员", parent.type), {icon: 2});
                layer.closeAll("loading");
            }
        });
    })
}
//提供报价
function offerClick(obj){
    var uuid = $(obj).parent().parent().parent().attr("uuid");
    var name = $(obj).attr("name");
    if(idVal == "2" && name != "交通信息"){
        window.location.href="planLook?uuid=" + uuid
    } else if(idVal == "2" && name == "交通信息"){
        window.location.href="trafficUpload?uuid=" + uuid
    } else {
        var count = getDemandCount(uuid);
        if(count >= 11){
            layer.msg("此订单已超出最大报价次数", {icon: 2});
            return false;
        }
        window.location.href="demandForSingleOffer?uuid=" + uuid
    }
}
//查询当前定制单是否超过十个人报价
function getDemandCount(uuid){
    var count = 0;
    $.ajax({
        async: false,
        url: "/privateOrder/getDemandCount",
        type: "get",
        data: {
            "uuid": uuid
        },
        headers: {"token": token},
        dataType: "json",
        success: (data) => {
            count = data.data;
        },
        error: () => {
            layer.alert(paramReturn("服务器异常，请联系管理员", parent.type), {icon: 2});
            layer.closeAll("loading");
        }
    });
    return count;
}