123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388 |
- 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('<img')[0],
- imgList = [];
- for(i=0; i<len; i++){
- var url = $($imgs[i]).attr("src");
- contentImgs.push(url)
- imgList.push(getImgUrl(url));
- }
- coverImg = data.articleCover;
- data.articleCover = getImgUrl(coverImg)
- data.content = text;
- data.imgs = imgList;
- data.imgCount = len;
- var html = template("info-panel", data);
- $("#infoPanel").empty().append(html);
- bindEvents();
- }else{
- mui.toast(res.msg);
- }
- }, true);
- }
- function getSecondCategory(firstlevelId, selectedId){
- var url = "/third/jkEdu/Article/getCategoryList",
- params = {
- categoryLevel: 2,
- firstlevelId: firstlevelId
- };
- sendGet(url, params, null, function(res){
- if(res.status == 200){
- var list = _.map(res.data, function(o){
- var b = {};
- b.value = o.categoryid;
- b.text = o.categoryname;
- return b;
- });
- picker.setData(list);
- if(selectedId){
- picker.pickers[0].setSelectedValue(selectedId, 500);
- }
- }else{
- mui.toast(res.msg);
- }
- }, true);
- }
- //上传封面图片,上传
- function uploadCoverImg(cb){
- var task = plus.uploader.createUpload(server+ "/upload/image",{
- method: "post"
- }, function(t, sta){
- if(sta == 200){
- var msg = t.responseText;
- var oImg = JSON.parse(msg);
- if(oImg.status == 200){
- var imgUrl = oImg.urls;
- var re = new RegExp("\\\\", "g");
- imgUrl = imgUrl.replace(re, "/");
- cb(imgUrl);
- }else{
- mui.toast("上传图片失败!");
- plus.nativeUI.closeWaiting();
- }
- }else{
- mui.toast("上传图片失败!");
- plus.nativeUI.closeWaiting();
- }
- });
-
- task.addFile(coverImg, {});
- task.start();
- }
- //上传内容图片
- var upload_count = 0;
- function uploadImg(cb){
- var len = uploadImgs.length;
- if(upload_count < len){
- var task = plus.uploader.createUpload(server + "/upload/fastDFSImag", {
- method: "post"
- }, function(t, sta) {
- if(sta == 200) {
- var msg = t.responseText;
- var oImg = JSON.parse(msg);
- if(oImg.status == 200){
- contentImgs.push(oImg.data);
- upload_count ++;
- // uploadImgs.pop();
- uploadImg(cb);
- }else{
- mui.toast("上传图片失败!");
- plus.nativeUI.closeWaiting();
- return false;
- }
- } else {
- mui.toast("上传图片失败!");
- plus.nativeUI.closeWaiting();
- return false;
- }
- });
- var url = uploadImgs[upload_count];
-
- task.addFile(url, {key: "file"});
- task.start();
- }else{
- cb();
- }
- }
- function saveArticle(url, params){
- var str = "";
- for(i=0; i<contentImgs.length; i++){
- str += '<img style="display: block; max-width: 100%;" src="' + contentImgs[i] + '"/ >';
- }
- 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 = '<div class="ui-col-0 mr10 ptb10 img-div2" id="imgCover"><img src="'+url+'" class="image"><img class="delete-icon t0" src="../images/delete_icon.png"></div>';
- $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 "";
- }
- });
- }
|