//查询指定报价单内容
function getPrivateOrder(){
    $.ajax({
        url: "/privateOrder/getPrivateOrderById",
        type: "get",
        data: {
            "uuid": uuid
        },
        headers: {"token": token},
        dataType: "json",
        success: (data) => {
            if(data.msg == "200"){
                if(data.data != null){
                    console.log(data)
                    $(".destination_end").html(data.data.origin + " - " + data.data.destination);
                    $(".start_end_time").html(data.data.startTime + " — " + data.data.endTime);
                    $(".people_number").html(data.data.peopleNum);
                    $(".amount_range").html(data.data.budgetMin + " - " + data.data.budgetMax);
                    $(".hotel_scale").html(paramReturn("酒店档次", parent.type) + "：" + (data.data.hotelScale == null ? "暂无" : data.data.hotelScale));
                    $(".language_div").html(paramReturn("服务语言", parent.type) + "：" + data.data.language);
                    offerCode = data.data.userId;
                }
            } else {
                layer.alert(paramReturn("服务器异常，请联系管理员", parent.type), {icon: 2});
            }
            layer.closeAll("loading");
        },
        error: () => {
            layer.alert(paramReturn("服务器异常，请联系管理员", parent.type), {icon: 2});
            layer.closeAll("loading");
        }
    });
}
//切换文件时重新上传
function delOosFile(){
    if(fileTraffic == null){
        return false;
    }
    $.ajax({
        url: "https://www.tuyatrip.com/api/upload/delUpload",
        type: "post",
        data: {
            "fileName": fileTraffic
        },
        headers: {"token": token},
        dataType: "json",
        success: (data) => {
        },
        error: () => {
            layer.alert(paramReturn("服务器异常，请联系管理员", parent.type), {icon: 2});
            layer.closeAll("loading");
        }
    });
}
//查询订制
function getData(){
    layer.load(3);
    $.ajax({
        url: "/supplierRelease/getSupplierRelease",
        type: "get",
        data:{
            "demandUuid": uuid
        },
        headers: {"token": token},
        dataType: "json",
        success: (data) => {
            if(data.msg == "200"){
                releaseUUid = data.data[0].uuid; //赋值
                console.log(data.data[0].trafficFile)
                if(data.data[0].trafficFile != null){
                    $(".upload_traffic").find(".upload-btn").remove();
                    $("#pdf").show();
                    let myPDF = new PDFObject({ url: data.data[0].trafficFile }).embed("pdf");
                }
            }
            layer.closeAll("loading");
        },
        error: () => {
            layer.alert(paramReturn("服务器异常，请联系管理员", parent.type), {icon: 2});
            layer.closeAll("loading");
        }
    });
}
//确认上传
function updateTraffic(){
    layer.load(3);
    if(fileTraffic == null){
        layer.msg(paramReturn("请先上传文件", parent.type), {icon: 2});
        layer.closeAll("loading");
        return false;
    }
    $.ajax({
        url: "/supplierRelease/updateTraffic",
        type: "put",
        data: JSON.stringify({
            "demandUuid": uuid,
            "uuid": releaseUUid,
            "trafficFile": fileTraffic
        }),
        headers: {"token": token},
        contentType: "application/json",
        dataType: "json",
        success: (data) => {
            if(data.msg == "200"){
                console.log(123)
                sendPrivateText();//上传之后给用户发一条信息
                layer.msg(paramReturn("上传成功", parent.type), {icon: 1});
            }
            layer.closeAll("loading");
        },
        error: () => {
            layer.alert(paramReturn("服务器异常，请联系管理员", parent.type), {icon: 2});
            layer.closeAll("loading");
        }
    });
}
//注册并登录环信账号
function registerUser(){
    var options = {
        username: parent.username.toLowerCase(),
        password: '123456',
        nickname: parent.nickname,
        appKey: WebIM.config.appkey,
        success: function () { },
        error: function (err) {
            let errorData = JSON.parse(err.data);
        },
    };
    conn.registerUser(options);

    var options1 = {
        user: parent.username.toLowerCase(),
        pwd: '123456',
        appKey: WebIM.config.appkey
    };
    conn.open(options1);
    //
    setTimeout(function (){
        let options = {
            nickname: parent.nickname,
            avatarurl: parent.headImg,
        }
        //修改用户信息
        conn.updateOwnUserInfo(options);
        //查询列表
        conn.getSessionList().then((res) => {

        })
    },2000);
}
// 单聊发送文本消息
function sendPrivateText() {
    console.log(offerCode)
    if(offerCode == null){
        layer.msg("发送消息失败", {icon: 2});
        return false;
    }
    let id = conn.getUniqueId();                 // 生成本地消息id
    let msg = new WebIM.message('txt', id);      // 创建文本消息
    msg.set({
        msg: '我已上传您的交通信息，请注意查看。',                         // 消息内容
        to: offerCode,                          // 接收消息对象（用户id）
        chatType: 'singleChat',              // 设置为单聊
        success: function (id, serverMsgId) {

        },
        fail: function(e){
            console.log("失败");
        }
    });
    conn.send(msg.body);
    $(".chat__room-info-input textarea").val("");
}