var ocollectBtn = document.getElementById("collectBtn"); //收藏按钮
var patentId;
mui.plusReady(function() {
var userid = plus.storage.getItem('userid');
var self = plus.webview.currentWebview();
var userName = plus.storage.getItem('name');
patentId = self.patentId;
//patentId="FE95F18DDCFA4E64BF62C014D67E95FB";
getRecourceMe();/*获取资源信息*/
//关键词标签点击进去搜索
mui(".tagList").on("tap","li",function(){
var tagText = this.getElementsByTagName("span")[0].innerText;
plus.nativeUI.showWaiting();
var web = plus.webview.create("../html/searchListNew2.html?content=5", "../html/searchListNew2.html", {}, {
key: tagText,
qiFlag: 4
});
})
//点击收藏按钮
ifcollectionAbout(patentId,4);
ocollectBtn.addEventListener('tap', function() {
if(userid && userid != null && userid != "null") {
if(document.getElementById("ifCollect").className=='mui-icon iconfontnew icon-yishoucang'){
cancelCollectionAbout(patentId,4)
} else {
collectionAbout(patentId,4);
}
}else{
isLogin();
}
});
mui.ajax(baseUrl + '/ajax/ppatent/incPageViews',{
"type": "POST",
"dataType": "json",
"data": {
"id": patentId
},
"success": function(data) {
if(data.success) {}
},
"error": function() {
}
});
function getRecourceMe() {
mui.plusReady(function() {
mui.ajax(baseUrl + '/ajax/ppatent/qo', {
data: {
"id": patentId
},
dataType: 'json', //服务器返回json格式数据
type: 'get', //HTTP请求类型
timeout: 10000, //超时时间设置为10秒;
success: function(data) {
if(data.success) {
console.log(JSON.stringify(data))
patentHtml(data.data);
getpatentAuthors(data.data.id)
plus.nativeUI.closeWaiting();
plus.webview.currentWebview().show("slide-in-right", 150);
}
},
error: function(xhr, type, errorThrown) {
plus.nativeUI.toast("服务器链接超时", toastStyle);
}
});
})
}
function patentHtml($da) {
document.getElementById("patentTit").innerHTML = $da.name;
document.getElementById("patentName").innerHTML = $da.name; //名字
document.getElementById("patentAbstract").innerHTML = $da.summary; //摘要内容
document.getElementById("Znum1").innerHTML = $da.code;//专利号
if($da.pubDay){
document.getElementById("Znum2").innerHTML = TimeTr($da.pubDay);
}else{
document.getElementById("Znum2").parentNode.parentNode.style.display="none";
}
if($da.reqCode){
document.getElementById("Znum4").innerHTML = $da.reqCode;
}else{
document.getElementById("Znum4").parentNode.parentNode.style.display="none";
}
if($da.reqDay){
document.getElementById("Znum3").innerHTML = TimeTr($da.reqDay);
}else{
document.getElementById("Znum3").parentNode.parentNode.style.display="none";
}
if($da.reqDay){
document.getElementById("Znum5").innerHTML = $da.reqPerson;
}else{
document.getElementById("Znum5").parentNode.parentNode.style.display="none";
}
if($da.keywords != undefined && $da.keywords.length != 0 ){
var subs = new Array();
if($da.keywords.indexOf(',')){
subs = $da.keywords.split(',');
}else{
subs[0] = $da.keywords;
}
var pstr=""
if(subs.length>0){
for (var i = 0; i < subs.length; i++)
{
pstr+='
'+ subs[i] +''
};
document.getElementsByClassName("tagList")[0].innerHTML= pstr;
}else{
document.getElementsByClassName("tagList")[0].style.display="none";
}
}
}
/*获取论文作者信息*/
function getpatentAuthors(stritrm) {
mui.ajax(baseUrl +"/ajax/ppatent/authors",{
"type": "GET",
"success": function(data) {
if(data.success) {
console.log(JSON.stringify(data))
if(data.data.length>0){
for(var i=0;i'
oString += ''+ showPro.name +'
'
oString += '
'+ baseInfo +'
'
oString += '
关注'
liItem.innerHTML = oString;
document.getElementById("aboutAuthors").appendChild(liItem);
ifcollectionAbout1.call(liItem.getElementsByClassName("attenSpan")[0],showPro.id,1);
}
}
})
}else{
var liItem = document.createElement("li");
var otext = (userName == data.data[i].name) ? "是我本人" : "邀请ta加入";
liItem.setAttribute("data-id",data.data[i].professorId);
liItem.className = "mui-table-view-cell"
var oString = ''
oString += '
'
oString += '
'+ data.data[i].name +'
'
oString += '
' + otext + ''
liItem.innerHTML = oString;
document.getElementById("aboutAuthors").appendChild(liItem);
}
}
}
}
},
"data": {
"id": stritrm
},
dataType: "json",
'error': function(xhr, type, errorThrown) {
plus.nativeUI.toast("服务器链接超时", toastStyle);
}
});
}
//判断是否登录,登录才可咨询,关注,收藏
function isLogin() {
var userid = plus.storage.getItem('userid');
if(userid==null || userid=='null'|userid == undefined |userid == 'undefined'){
mui.openWindow({
url: '../html/login.html',
id: 'login.html',
extras: {
ourl: self.id
}
})
return 1;
}
return 0;
};
window.addEventListener("newId", function(event) {
userName = plus.storage.getItem('name');
userid = plus.storage.getItem('userid');
getRecourceMe();
ifcollectionAbout(patentId,4);
});
function leadIn(sel) {
mui.ajax(baseUrl + "/ajax/ppatent/ass", {
"type": "POST",
"data": {
id: patentId,
uid: userid,
author: userName
},
"success": function(data) {
if(data.success) {
if(data.data > 0) {
plus.nativeUI.toast("导入成功", toastStyle);
sel.style.display = "none";
}
}
}
});
}
mui("#aboutAuthors").on("tap", "li>span", function() {
var that = this;
if(this.innerHTML === "是我本人") {
if(isLogin()) {
return;
}
var btn = ["确定", "取消"];
mui.confirm("确认这是您发表的专利?", "提示", btn, function(e) {
if(e.index == 0) {
leadIn(that);
}
})
} else if(this.innerHTML === "邀请ta加入") {
var share = buildShareService("weixin");
if(share) {
shareMessage(share, "WXSceneSession", {
content: document.getElementById("paperAbstract").innerHTML.substring(0, 40),
title: document.getElementById("paperName").innerHTML,
href: baseUrl + "/e/l.html?id=" + paperId,
thumbs: [baseUrl + "/images/logo180.png"]
});
}
} else if(this.innerHTML === "关注") {
if(isLogin()) {
return;
}
collectionAbout1(this.getAttribute("data-id"), '1',this);
} else if(this.innerHTML === "已关注") {
if(isLogin()) {
return;
}
cancelCollectionAbout1(this.getAttribute("data-id"), '1',this);
}
})
/*判断是否收藏资源文章或者是否关注专家*/
function ifcollectionAbout1(watchObject,num) {
var that=this;
mui.ajax(baseUrl + '/ajax/watch/hasWatch', {
data: {
"professorId": userid,
"watchObject": watchObject
},
dataType: 'json', //数据格式类型
type: 'get', //http请求类型
timeout: 10000,
async: false,
success: function(data) {
if(data.success && data.data != null) {
if(num=="1"){//已关注专家
that.classList.add("attenedSpan");
that.innerText="已关注";
}else{//已收藏资源或文章
document.getElementById("ifCollect").classList.remove("icon-shoucang");
document.getElementById("ifCollect").classList.add("icon-yishoucang");
}
} else {
if(num=="1"){//关注专家
that.classList.remove("attenedSpan");
that.innerText="关注";
}else{//收藏资源或文章
document.getElementById("ifCollect").classList.add("icon-shoucang");
document.getElementById("ifCollect").classList.remove("icon-yishoucang");
}
}
},
error: function() {
plus.nativeUI.toast("服务器链接超时", toastStyle);
}
});
}
/*收藏资源、文章或者关注专家*/
function collectionAbout1(watchObject, num,sel) {
mui.ajax(baseUrl + '/ajax/watch', {
data: {
"professorId": userid,
"watchObject": watchObject,
"watchType": num
},
dataType: 'json', //数据格式类型
type: 'POST', //http请求类型
timeout: 10000,
async: false,
success: function(data) {
if(data.success) {
if(num=="1"){//关注专家
sel.classList.add("attenedSpan");
sel.innerText="已关注";
plus.nativeUI.toast("关注成功", toastStyle);
}else{//收藏资源或文章
document.getElementById("ifCollect").classList.remove("icon-shoucang");
document.getElementById("ifCollect").classList.add("icon-yishoucang");
plus.nativeUI.toast("收藏成功", toastStyle);
}
}
},
error: function() {
plus.nativeUI.toast("服务器链接超时", toastStyle);
}
});
}
/*取消收藏资源、文章或者取消关注专家*/
function cancelCollectionAbout1(watchObject, num,sel) {
mui.ajax({
url: baseUrl + '/ajax/watch/delete',
data: {
professorId: userid,
watchObject: watchObject
},
dataType: 'json', //数据格式类型
type: 'post', //http请求类型
timeout: 10000,
async: true,
success: function(data) {
console.log(data.success)
if(data.success) {
if(num=="1"){//关注专家
sel.classList.remove("attenedSpan");
sel.innerText="关注";
plus.nativeUI.toast("已取消关注", toastStyle);
}else{//收藏资源或文章
document.getElementById("ifCollect").classList.add("icon-shoucang");
document.getElementById("ifCollect").classList.remove("icon-yishoucang");
plus.nativeUI.toast("已取消收藏", toastStyle);
}
}
},
error: function(data) {
plus.nativeUI.toast("服务器链接超时", toastStyle);
}
});
}
/*微信及微信朋友圈分享专家*/
var auths, shares;
plus.oauth.getServices(function(services) {
auths = {};
for(var i in services) {
var t = services[i];
auths[t.id] = t;
}
}, function(e) {
alert("获取登录服务列表失败:" + e.message + " - " + e.code);
});
plus.share.getServices(function(services) {
shares = {};
for(var i in services) {
var t = services[i];
shares[t.id] = t;
}
}, function(e) {
alert("获取分享服务列表失败:" + e.message + " - " + e.code);
});
mui("#shareBlock").on("tap", "li", function() {
document.getElementById("shareBlock").style.display = "none";
document.getElementById("maskBlack").style.display = "none";
var oFen = this.getElementsByTagName("span")[0].innerHTML;
var oUrl=baseUrl + "/images/logo180.png";
if(oFen == "微信好友") {
var share = buildShareService("weixin");
if(share) {
shareMessage(share, "WXSceneSession", {
content: document.getElementById("patentAbstract").innerHTML.substring(0,40),
title: document.getElementById("patentName").innerHTML,
href: baseUrl + "/e/z.html?id=" + patentId ,
thumbs: [oUrl]
});
}
} else if(oFen == "微信朋友圈") {
var share = buildShareService("weixin");
if(share) {
shareMessage(share, "WXSceneTimeline", {
content: document.getElementById("patentAbstract").innerHTML.substring(0,40),
title: document.getElementById("patentName").innerHTML,
href: baseUrl + "/e/z.html?id=" + patentId ,
thumbs: [oUrl]
});
}
} else if(oFen == "新浪微博") {
var share = buildShareService("sinaweibo");
if(share) {
shareMessage(share, "sinaweibo", {
content: document.getElementById("patentName").innerHTML+ baseUrl + "/e/z.html?id=" + patentId ,
});
}
}
})
function buildShareService(ttt) {
var share = shares[ttt];
if(share) {
if(share.authenticated) {
console.log("---已授权---");
} else {
console.log("---未授权---");
share.authorize(function() {
console.log('授权成功...')
}, function(e) {
alert("认证授权失败:" + e.code + " - " + e.message);
return null;
});
}
return share;
} else {
alert("没有获取微信分享服务");
return null;
}
}
function shareMessage(share, ex, msg) {
msg.extra = {
scene: ex
};
share.send(msg, function() {
plus.nativeUI.closeWaiting();
if(plus.storage.getItem('userid')) {
shareAddIntegral(2);
}
}, function(e) {
plus.nativeUI.closeWaiting();
if(e.code == -2) {
plus.nativeUI.toast('已取消分享', {
verticalAlign: 'center'
});
}
});
}
/*图像预览*/
mui.previewImage();
moreMes();
function moreMes(){
document.getElementById("BtnMore").addEventListener("tap",function(){
var oUrl=baseUrl + "/images/logo180.png";
plus.nativeUI.showWaiting(); //显示原生等待框
var webviewShow = plus.webview.create("../html/moreItem.html", 'moreItem.html', {}, {
proid: patentId,
name:"patent",
data:{
content: document.getElementById("patentAbstract").innerHTML.substring(0,40),
title: document.getElementById("patentName").innerHTML,
href: baseUrl + "/e/z.html?id=" + patentId ,
thumbs: [oUrl]
},
weiboData:{
content: document.getElementById("patentName").innerHTML+ baseUrl + "/e/z.html?id=" + patentId ,
}
})
})
}
});