//点击列表弹出框
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){
    layer.load(3);
    $.ajax({
        url: "/privateOrder/getPrivateOrder",
        type: "get",
        data: {
            "page": page,
            "limit": limit,
            "startTime": startTime,
            "endTime": endTime,
            "orderType": idVal
        },
        headers: {"token": token},
        dataType: "json",
        success: (data) => {
            if(data.msg == "200"){
                $(".content_div div").remove();
                $.each(data.data, (index, item) => {
                    var type = "待回答";
                    if(item.orderType == 0){
                        type = "待回答";
                    }else if(item.orderType == 1){
                        type = "已回答";
                    }else if(item.orderType == 2){
                        type = "已付费";
                    }else if(item.orderType == 3){
                        type = "行程开始";
                    }else if(item.orderType == 4){
                        type = "行程结束";
                    }else if(item.orderType == 5){
                        type = "已查看详情";
                    }else if(item.orderType == 6){
                        type = "不感兴趣";
                    }else if(item.orderType == 9){
                        type = "取消行程";
                    }
                    $(".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%;\">"+ 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" +
                        "<button class=\"ignore_button button_div_head\" onclick='ignoreClick(this)'><img src=\"/images/demandForSingle/ban.png\"/>忽略</button>\n" +
                        "<button class=\"offer_button button_div_head\" onclick='offerClick(this)'><img src=\"/images/demandForSingle/offer.png\"/>提供报价</button>\n" +
                        "</div>\n" +
                        "</div>\n" +
                        // "<!-- 隐藏内容 -->\n" +
                        // "<div class=\"hide_content\">\n" +
                        // "<div class=\"message_div_input\" title="+ item.rhythm +">\n" +
                        // "<span>游玩节奏：</span>\n" +
                        // "<span name=\"rhythm\">"+ item.rhythm +"</span>\n" +
                        // "</div>\n" +
                        // "<div class=\"message_div_input\" title="+ item.resourcesNeeded +">\n" +
                        // "<span>所需资源：</span>\n" +
                        // "<span name=\"resourcesNeeded\">"+ item.resourcesNeeded +"</span>\n" +
                        // "</div>\n" +
                        // "<div class=\"message_div_input last_div_message\" title="+ item.flight +">\n" +
                        // "<span>航班时间：</span>\n" +
                        // "<span name=\"flight\">"+ item.flight +"</span>\n" +
                        // "</div>\n" +
                        // "<br/>\n" +
                        // "<div class=\"message_div_input\" title="+ item.hotelScale +">\n" +
                        // "<span>酒店档次：</span>\n" +
                        // "<span name=\"hotelScale\">"+ item.hotelScale +"</span>\n" +
                        // "</div>\n" +
                        // "<div class=\"message_div_input\">\n" +
                        // "<span>制定景点：</span>\n" +
                        // "<span name=\"rhythm\">暂无</span>\n" +
                        // "</div>\n" +
                        // "<div class=\"message_div_input last_div_message\" title="+ item.remarks +">\n" +
                        // "<span>其他备注：</span>\n" +
                        // "<span name=\"remarks\">"+ item.remarks +"</span>\n" +
                        // "</div>\n" +
                        // "</div>\n" +
                        "</div>")
                });
                //自定义样式分页
                laypage.render({
                    elem: 'demo2'
                    ,count: data.data.length
                    ,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("服务器异常，请联系管理员", {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("忽略成功", {icon: 1});
                getQuotation(0, 7, startTime, endTime);//查询报价单数据渲染
                layer.closeAll("loading");
            },
            error: () => {
                layer.alert("服务器异常，请联系管理员", {icon: 2});
                layer.closeAll("loading");
            }
        });
    })
}
//提供报价
function offerClick(obj){
    var uuid = $(obj).parent().parent().parent().attr("uuid");
    window.location.href="demandForSingleOffer?uuid=" + uuid
}