'; if (sessions[i].lastMsg != undefined) { parentStr += '' + diffTime(sessions[i].lastMsg.time) + ''; } else { parentStr += ''; } parentStr += '
'; if (sessions[i].lastMsg != undefined) { if (sessions[i].lastMsg.type == "text") { parentStr += '' + sessions[i].lastMsg.text + '
'; } else if (sessions[i].lastMsg.type == "audio") { parentStr += '[語音]
'; } else if (sessions[i].lastMsg.type == "video") { parentStr += '[視頻]
'; } else if (sessions[i].lastMsg.type == "image") { parentStr += '[圖片]
'; } else if (sessions[i].lastMsg.type == "location") { parentStr += '[位置]
'; } else if (sessions[i].lastMsg.type == "tip") { parentStr += '' + sessions[i].lastMsg.tip + '
'; } else if (sessions[i].lastMsg.type == "custom") { parentStr += '' + sessions[i].lastMsg.pushContent + '
'; } else { parentStr += '' + sessions[i].lastMsg.text + '
'; } parentStr += '' + staffName + '
'; } else { if (jobId.length > 7) { if (data.flow == "in") { parentdiv += '' + staffName + '
'; } else { parentdiv += '' + userName + '
'; } } else { parentdiv += '' + userName + '
'; } } parentdiv += '' + item.BuildingTitle + '
'; if (item.Type == 1) { parentdiv += ''; } else if (item.Type == 5) { parentdiv += ''; } parentdiv += ''; } else if (item.Type == 2 || item.Type == 3 || item.Type == 4) { //房源、视频搵楼、工商铺 if (item.Type == 2) { parentdiv += ''; } else if (item.Type == 3) { parentdiv += ''; } else if (item.Type == 4) { parentdiv += ''; } parentdiv += '租HK $' + toPrice(item.Rent) + '元(租MOP $' + toPrice(item.MoRent) + '元)
'; } else if (item.SellType == "租售") { parentdiv += '售HK $' + toPrice(item.Price) + '萬(售MOP $' + toPrice(item.MoPrice) + '萬)
'; parentdiv += '租HK $' + toPrice(item.Rent) + '元(租MOP $' + toPrice(item.MoRent) + '元)
'; } else { parentdiv += '售HK $' + toPrice(item.Price) + '萬(售MOP $' + toPrice(item.MoPrice) + '萬)
'; } } parentdiv += '商鋪編號#' + item.PropertyNo + '
'; } parentdiv += ''; if (item.GrossArea != "" && item.GrossArea != 0) { parentdiv += '約' + toThousands(Math.round(item.GrossArea)) + '呎'; } if (item.CountF != null && item.CountF != 0 && item.CountT != null && item.CountT != 0) { parentdiv += ' / '; if (item.CountF != null && item.CountF != 0) { parentdiv += item.CountF + '房'; } if (item.CountT != null && item.CountT != 0) { parentdiv += item.CountT + '廳'; } } parentdiv += '
'; if (item.PropertyUsage != "") { parentdiv += ''; } parentdiv += '' + item.lastMsg.text + '
'; } else if (item.lastMsg.type == "audio") { aHtml = '[語音]
'; } else if (item.lastMsg.type == "video") { aHtml = '[視頻]
'; } else if (item.lastMsg.type == "image") { aHtml = '[圖片]
'; } else if (item.lastMsg.type == "location") { aHtml = '[位置]
'; } else if (item.lastMsg.type == "tip") { aHtml = '' + item.lastMsg.tip + '
'; } else if (item.lastMsg.type == "custom") { aHtml = '' + item.lastMsg.pushContent + '
'; } else { aHtml = '' + item.lastMsg.text + '
'; } } strHtml.append(aHtml); }); updateSessionsUI(data.sessions[0], 2); $("#chatNum").html(num); if (num == 0) { $("#chatNum").hide(); } else { $("#chatNum").show(); } pushMsg(msg); } //用户名片渲染 function onUsers(users, type, teamId, index) { if (index != 1) { data.users = nim.mergeUsers(data.users, users); staffInfo = users; var prefix = "team-"; if (type == "edit") { // editUsers(users, teamId); var $person = $("#" + prefix + teamId); if (users.alias != undefined) { $person.find(".name label").html(users.alias); $person.attr("onclick", "OpenChat('" + teamId + "',0,'" + users.alias + "')"); } else { $person.find(".name label").html(users.nick); $person.attr("onclick", "OpenChat('" + teamId + "',0,'" + users.nick + "')"); } if (users.avatar != '') { $person.find(".head_contianer").find("img").attr("src", users.avatar); } else { $person.find(".head_contianer").find("img").attr("src", "/images/User/head.png"); } $person.find(".name span").html(diffTime(users.updateTime)); } } } //push信息上云信 function pushMsg(msgs) { console.log("推入云信:"); if (!Array.isArray(msgs)) { msgs = [msgs]; } var sessionId = msgs[0].sessionId; data.msgs = data.msgs || {}; data.msgs[sessionId] = nim.mergeMsgs(data.msgs[sessionId], msgs); } function UnixToDate(unixTime, isFull, timeZone) { if (typeof (timeZone) == 'number') { unixTime = parseInt(unixTime) + parseInt(timeZone) * 60 * 60; } var time = new Date(unixTime); var ymdhis = ""; ymdhis += time.getFullYear() + "-"; if (time.getDate() < 10) { ymdhis += "0" + (time.getMonth() + 1) + "-"; } else { ymdhis += (time.getMonth() + 1) + "-"; } if (time.getDate() < 10) { ymdhis += "0" + time.getDate(); } else { ymdhis += time.getDate(); } if (isFull === true) { ymdhis += " " + time.getHours() + ":"; if (time.getMinutes() < 10) { ymdhis += "0" + time.getMinutes(); } else { ymdhis += time.getMinutes(); } } return ymdhis; } //打开聊天框 function OpenChat(Id, type, name) { teamId = Id; listArray = []; nim.getTeamMembers({ teamId: teamId, done: getTeamMembersDoneMsg }); headImg = staffInfo.avatar; if (type == 1 || type == 2 || type == 3) { sendText(type, teamId); } nim.resetSessionUnread('team-' + teamId); // localMsgs("team-" + teamId, teamId) $("#team-" + teamId).find(".head_contianer").attr("data-id", "0"); $("#team-" + teamId).find(".head_contianer span").remove(); $("#chatNum").hide(); $(".onchat > .name").html(name); $(".Contact").css("display", "block"); $(".chat").css("width", "700px"); $(".person").css("width", "280px") } //关闭聊天框 function CloseChat() { $(".Contact").css("display", "none"); $(".chat").css("width", "280px"); $(".person").css("width","280px") } function OpenPerson() { $(".chat").css("display", "flex"); } //关闭联系人列表 function ClosePerson() { $(".chat").css("display", "none"); } $("#obs").click(function () { nim.resetSessionUnread('team-' + teamId); $("#team-" + teamId).find(".head_contianer").attr("data-id", "0"); $("#team-" + teamId).find(".head_contianer span").remove(); }); //播放语音 $('.content').on('click', '.audioBox span', function () { var currentNode = $(this); var audioEle = $(this).siblings('.audio'); playAudio(currentNode, audioEle); }); function playAudio(currentNode, audioEle) { /*jquery对象转换成js对象*/ var player = audioEle[0]; if (player.paused) { /*如果已经暂停*/ $(".audioBox span").removeClass('audioPlay'); $(".audioBox span").siblings('.audio')[0].pause(); player.play(); /*播放*/ currentNode.addClass('audioPlay'); } else { player.pause();/*暂停*/ currentNode.removeClass('audioPlay'); } // 录音播放结束停止动画 player.addEventListener('ended', function () { currentNode.removeClass('audioPlay'); }, false); } function getBase64(img) {//传入图片路径,返回base64 function getBase64Image(img, width, height) {//width、height调用时传入具体像素值,控制大小 ,不传则默认图像大小 var canvas = document.createElement("canvas"); canvas.width = width ? width : img.width; canvas.height = height ? height : img.height; var ctx = canvas.getContext("2d"); ctx.drawImage(img, 0, 0, canvas.width, canvas.height); var dataURL = canvas.toDataURL(); return dataURL; } var image = new Image(); image.crossOrigin = ''; image.src = img; var deferred = $.Deferred(); if (img) { image.onload = function () { deferred.resolve(getBase64Image(image));//将base64传给done上传处理 } return deferred.promise();//问题要让onload完成后再return sessionStorage['imgTest'] } } }