Files
youfang-app/fangija-zsyf/js/user/myMessage.js
T
2018-05-23 15:41:44 +08:00

133 lines
4.1 KiB
JavaScript

String.prototype.startWith=function(str){
var reg=new RegExp("^"+str);
return reg.test(this);
}
//加载flag
var mm_loading = false;
//最多可加载的条目
//var maxItems = 100;
//每次加载添加多少条目
var mm_itemsPerLoad = 10;
var mm_totalCount = 0;
function addMessage(loadNum,startNum){
axios.get(BASE_PATH + "/rest/message/loadMessages",{
params:{
loadNum:loadNum,
startNum:startNum
}
}).then(function(response){
var messageList = response.data.data.list;
if(messageList != null && messageList.length == 0){
// 删除加载提示符
$('#loadTip4').remove();
// 加载完毕,则注销无限加载事件,以防不必要的加载
//$.detachInfiniteScroll($('.infinite-scroll'));
return;
}
mm_totalCount = response.data.data.totalCount;
var unReadNum = response.data.data.unReadNum;
// tab.mm_num = mm_totalCount;
$("#mm_num").html("消息("+unReadNum+")")
var html="";
$.each(messageList,function(){
// var clickStr = "";
// if(this.operation==0){//打开详情
// href = '<a href="../message/detail?mid='+this.midStr+'"';
// }
// if(this.operation==1){打开页面
// href = '<a href="../'+this.operationPage+'"';
// }
// if(this.operation==2){打开Url
// href = '<a target="_blank" href="'+this.operationPage+'"';
// }
html+='<li>'+
'<a class="item-content message01 '+(this.readStatus==0?'message01-new':'')+'" onclick="messageGoto(this,\''+this.operation+'\',\''+this.operationPage+'\',\''+this.midStr+'\')">'+
'<div class="item-media"><i class="icon icon-message01"></i></div>'+
'<div class="item-inner">'+
'<div class="item-title-row">'+
'<div class="item-title">'+(this.title.length>20?this.title.substring(0,19):this.title)+'</div>'+
'</div>'+
'<div class="item-subtitle">'+this.addTimeStr+'</div>'+
'</div>'+
'</a>'+
'</li>';
})
$("#messageUl").append(html);
if(mm_totalCount<mm_itemsPerLoad){
// 加载完毕,则注销无限加载事件,以防不必要的加载
// $.detachInfiniteScroll($('.infinite-scroll'));
// 删除加载提示符
$('#loadTip4').remove();
}
}).catch(function(error){
console.log(error);
});
}
function messageGoto(_this,operation,operationPage,mid){
var subpage_style = {
top: '0',
bottom: '50px',
};
axios.post('/rest/message/readMesage',{mid:mid}).then(function(response){
if(response.status){
var unReadNum = response.data.data;
$("#mm_num").html("消息("+unReadNum+")")
}
}).catch(function(error){
console.log(error)
});
$(_this).removeClass("message01-new")
if(operation==0){
clicked('/views/message/detail.html',true,false,{},{mid:mid},function(){})
}
if(operation==1){
var pages = operationPage+'.html';
// if(plus.webview.getWebviewById(pages)==null){
// plus.webview.create(pages, pages, subpage_style);
// }
// plus.webview.show(pages);
if(plus.webview.getWebviewById('H5693FF3D')==null){
mui.fire(plus.webview.getWebviewById('HBuilder'),'switchView',{
name:pages
});
}else{
mui.fire(plus.webview.getWebviewById('H5693FF3D'),'switchView',{
name:pages
});
}
}
if(operation==2){
if (operationPage != null && operationPage != "") {
if (operationPage.startWith("http")) {
clicked('../webview_embed.html', true,false,{},{url:operationPage})
} else {
// 处理打开app中的二级页面,一级页面在type=1中已经处理了,如果有http的地址就是打开外部页面
// 否则就是打开app内部页面
var url = operationPage;
var sindex = url.indexOf('?') == -1 ? url.length : url.indexOf('?');
var openUrl = url.substring(0, sindex);
var paramStr = url.substring(sindex+1);
var jsonData = {};
var parray = paramStr.split('&')
for(var i=0;i<parray.length;i++){
var subArray = parray[i].split('=')
if(parray[i] != ""){
if(subArray.length > 0) {
jsonData[subArray[0]] = subArray[1];
}
}
}
clicked(openUrl,true,false,{},jsonData)
}
}
}
}