mui.init();
var articleId,
articleObj;
var coverImg,
uploadCovImg,
contentImgs = [],
uploadImgs = [], //存储需要上传的图片
imgCount,
selectedScore;
var docInfo;
var picker = new mui.PopPicker();
mui.plusReady(function(){
var self = plus.webview.currentWebview();
docInfo = JSON.parse(plus.storage.getItem("docInfo"));
articleId = self.articleId;
getArticleDetail();
templateHelper();
});
function getArticleDetail(){
var url = "/third/jkEdu/Article/getArticalById",
params = {
articleId: articleId,
userType: 1
};
sendGet(url, params, null, function(res){
if(res.status == 200){
var data = res.data;
articleObj = data;
getSecondCategory(data.firstLevelCategoryId, data.secondLevelCategoryId);
$("#contentPanel").html(data.articleContent);
var $imgs = $("#contentPanel img"),
len = $imgs.length,
text = data.articleContent.split('
';
}
params.content += str;
sendPost(url, params, null, function(res){
if(res.status == 200){
mui.toast("保存成功");
//返回列表页
var view = plus.webview.getWebviewById("myArticle");
if(view){
mui.fire(view,"reload");
}
mui.later(function(){
mui.back();
}, 300);
mui.back();
}else{
mui.toast(res.msg);
}
plus.nativeUI.closeWaiting();
}, 'POST', '', true);
}
function bindEvents(){
$("#infoPanel").on('click', "#category", function(){
var $this = $(this);
picker.show(function (selectedItems) {
$this.val(selectedItems[0].text);
$this.attr("data-id", selectedItems[0].value)
});
});
//监听选中框修改
$("#infoPanel").on('click', "[name=userange]", function(){
selectedScore = $(this).val();
})
//添加封面
$("#infoPanel").on('click', "#addCover", function(){
var $this = $(this);
if(coverImg != '' && coverImg) {
mui.toast("封面仅限一张!");
return false;
}
getAutoRecCompressImageLocalPath(function(url){
coverImg = url;
uploadCovImg = coverImg
var html = '
![]('+url+')
![](../images/delete_icon.png)
';
$this.parent().before(html);
}, 1, 1);
});
//封面删除功能
$('#infoPanel').on('click', '#imgCover .delete-icon', function(e){
window.event? window.event.cancelBubble = true : e.stopPropagation();
var $this = $(this);
//获得图片路径
coverImg = '';
uploadCovImg = '';
$this.parent().remove();
});
//添加文章内容中的图片
$("#infoPanel").on('click', "#addContentImg", function(){
var $this = $(this);
imgCount = $(".img-count").text();
var num = 9 - parseInt(imgCount);
if(num == 0){
mui.toast("最多只能选择9张图片!")
return false;
}
getAutoRecCompressImageLocalPath(function(url){
imgCount++;
$(".img-count").text(imgCount);
uploadImgs.push(url);
// plus.nativeUI.showWaiting();
// uploadImg(function() {
// mui.toast("内容图上传成功!");
// plus.nativeUI.closeWaiting();
// })
var html = template("img-tmp", {url: url});
$this.parent().before(html);
}, num, 9);
});
//内容图删除功能
$('#infoPanel').on('click', '#imgContent .delete-icon', function(){
var $this = $(this);
//获得图片路径
var urls = $this.parent().find(".image").attr("src");
$this.parent().remove();
var imgCount = parseInt($(".img-count").text());
imgCount--;
$(".img-count").text(imgCount);
for(var i = 0, len = contentImgs.length; i < len; i++) {
if(urls.indexOf(contentImgs[i]) > -1) {
contentImgs.splice(i, 1);
break;
}
}
for(var i = 0, len = uploadImgs.length; i < len; i++) {
if(uploadImgs[i].indexOf(urls) > -1) {
uploadImgs.splice(i, 1);
break;
}
}
});
//文章删除功能
$("#deleteArticle").click(function(){
dialog({
content: "确定要删除此篇文章吗?",
okValue: '确定',
ok: function(){
var url = "/third/jkEdu/Article/removeArticle",
params = {
ids: articleId
};
plus.nativeUI.showWaiting();
sendPost(url, params, null, function(res){
plus.nativeUI.closeWaiting();
if(res.status == 200){
mui.toast(res.msg || "删除文章成功!");
setTimeout(function() {
var view = plus.webview.getWebviewById("myArticle");
if(view){
mui.fire(view,"reload");
}
mui.later(function(){
mui.back();
}, 300);
mui.back();
}, 1000)
}else{
mui.toast(res.msg);
}
}, 'POST', '', true);
},
cancelValue: '我再想想',
cancel: function(){}
}).show()
});
//提交审核按钮
$("#saveArticle").on('click', function(){
var reqUrl = "/doctor/jkEdu/article/PC/saveArticle",
params = {
articleId: articleId,
articleTitle: $("#title").val() || '',
articlelevel: articleObj.articleType,
secondLevelCategoryId: $("#category").attr("data-id"),
secondLevelCategoryName: $("#category").val(),
firstLevelCategoryId: articleObj.firstLevelCategoryId,
firstLevelCategoryName: articleObj.firstLevelCategoryName,
content: $("#content").html(),
imageUrl: coverImg,
operatorRoleCode: docInfo.code,
opertorRoleLevel: docInfo.level,
userScope: selectedScore || articleObj.userScope,
roleType: 1, //1、普通医生,2、管理员
currentUserRole: docInfo.hospital,
currentUserRoleLevel: 4
};
// 封面图更改
if(uploadCovImg){
plus.nativeUI.showWaiting();
uploadCoverImg(function(url){
plus.nativeUI.closeWaiting();
params.imageUrl = url;
if(uploadImgs.length > 0){
uploadImg(function() {
saveArticle(reqUrl, params);
});
}else{
saveArticle(reqUrl, params);
}
});
} else if(uploadImgs.length > 0){
uploadImg(function() {
saveArticle(reqUrl, params);
});
}else{
saveArticle(reqUrl, params);
}
});
// 预览功能
$('#preview').on('tap',function(){
var articleTitle = $.trim($.trim($("#title").val())),
secondLevelCategoryId = $("#category").attr("data-id"),
secondLevelCategoryName = $.trim($("#category").val()),
content = $.trim($('#content').html()),
userScope = selectedScore || articleObj.userScope;
if(articleTitle){
if(secondLevelCategoryName){
if(content){
if(userScope){
mui.openWindow({
id: "preview",
url: "preview.html",
extras: {
articleTitle: articleTitle,
secondLevelCategoryName: secondLevelCategoryName,
imgCover: coverImg,//封面图
content: content,//内容
imgContent: uploadImgs,//未上传内容图
uploadImgs: contentImgs,// 已上传内容图
userScope: userScope//使用范围
}
})
}else{
mui.toast('使用范围不能为空');
return false;
}
}else{
mui.toast('内容不能为空');
return false;
}
}else{
mui.toast('分类不能为空');
return false;
}
}else{
mui.toast('文章标题不能为空');
return false;
}
})
}
function templateHelper(){
template.helper("getImgUrl", function(str){
if(str){
return getImgUrl(str);
}else{
return "";
}
});
}