123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474 |
- var firstLevelId,
- secondLevelId = '',
- selectedTab = 0, //顶部tab选中的index
- page = [],
- pageSize = 10,
- loaded = [],
- patient,
- patientName,
- teamCode,
- pCodes, //从慢病管理页面中跳转过来的多个居民的code
- referrer,
- isfromAdmin;
- var isAdmin; //判断是否是管理员
- var docInfo;
-
- var scrollers = [];
- mui.init();
- mui.plusReady(function(){
- var self = plus.webview.currentWebview();
- firstLevelId = self.firstLevelId;
- var userAgent = JSON.parse(plus.storage.getItem("userAgent"));
- if(userAgent.observer){
- isfromAdmin=true;
- }
- isAdmin = self.isAdmin;
- patient = self.patient;
- patientName = self.patientName;
- teamCode = self.teamCode;
- pCodes = self.pCodes;
- referrer = self.referrer;
-
- if(!isAdmin){
- // $(".xuanfu").show();
- }
-
- docInfo = JSON.parse(plus.storage.getItem("docInfo"));
- getSecondLevelCategory();
- bindEvents();
- });
- function getSecondLevelCategory(){
- var url = "/third/jkEdu/Article/getCategoryList",
- params = {
- categoryLevel: 2,
- firstlevelId: firstLevelId
- };
- sendGet(url, params, null, function(res){
- if(res.status == 200){
- var html = template("tab-tmp", {list: res.data});
- // $("#tabPanel").empty().append(html);
- var controlPanelHtml = template("control-panel-tmp", {list: res.data});
- // $(".mui-slider-group").empty().append(controlPanelHtml);
-
- $(".mui-content").append(html + controlPanelHtml);
- var gallery = mui('.mui-slider');
- gallery.slider();
- initTabScroller();
- initScroller();
-
- // secondLevelId = res.data[0].categoryid;
- getArticleList(true);
- loaded[0] = "true";
- document.querySelector('.mui-slider').addEventListener('slide', function(event) {
- selectedTab = event.detail.slideNumber;
- var $item = $("#tabPanel a").eq(selectedTab);
- secondLevelId = $item.attr("data-id");
- if(loaded[selectedTab] == "false"){
- getArticleList(true);
- loaded[selectedTab] = "true";
- }
- });
- }else{
- mui.toast(res.msg);
- }
- },true);
- }
- function getArticleList(isInit){
- if(isInit){
- page[selectedTab] = 0;
- }
- var url = "/doctor/jkEdu/article/PC/queryArticlePcList",
- params = {
- firstLevelCategoryId: firstLevelId,
- secondLevelCategoryId: secondLevelId,
- currentUserRole: docInfo.hospital,
- currentUserRoleLevel: 4,
- iDisplayStart: page[selectedTab] * pageSize,
- iDisplayLength: pageSize,
- isAuthentication: 1, //已认证过的文章
- roleType: 1 //1、普通医生,2、管理员
- };
- if(patient){
- params.patient = patient;
- }
- if(isAdmin){
- var selectedRole = JSON.parse(plus.storage.getItem("selectedRole"));
- params.currentUserRole = selectedRole.code;
- params.currentUserRoleLevel = selectedRole.level;
- params.roleType = 2;
- }
- sendGet(url, params, null, function(res){
- if(res.status == 200){
- if(isInit){
- if(res.data.aaData.length == 0){
- $("#item"+(selectedTab)+" .mui-table-view").hide();
- $("#item"+(selectedTab)+" .no-result").show();
- }else{
- loaded[selectedTab] = "true";
- var html = template("articleimgLi", {list: res.data.aaData});
- $("#item"+(selectedTab)+" .mui-table-view").empty().append(html);
- }
- }else{
- var html = template("articleimgLi", {list: res.data.aaData});
- $("#item"+(selectedTab)+" .mui-table-view").append(html);
- }
-
- if(res.data.aaData.length < pageSize){
- // scrollers[selectedTab].disablePullupToRefresh();
- scrollers[selectedTab].endPullupToRefresh(true);
- }else{
- page[selectedTab] ++ ;
- scrollers[selectedTab].endPullupToRefresh();
- // scrollers[selectedTab].enablePullupToRefresh();
- }
- }else{
- mui.toast(res.msg);
- }
- }, true);
- }
- /*
- * 收藏文章
- */
- function collectionArticle(code,$this){
- plus.nativeUI.showWaiting();
- var params = {};
- params.articleId = code;
- params.userType = 1; //1医生,2居民
- sendPost("/third/jkEdu/Article/saveArticleCollection",params,function(res){
- plus.nativeUI.closeWaiting();
- if(res.msg){
- plus.nativeUI.toast(res.msg);
- }else{
- plus.nativeUI.toast("收藏失败!");
- }
- },function(res){
- plus.nativeUI.closeWaiting();
- if(res.status==200){
- $this.attr("data-status", 1);
- $this.find("img").attr("src", "../images/shoucang_pre.png");
- var span = $this.find("span");
- var collectNum = parseInt(span.html());
- span.html(collectNum+1);
- plus.nativeUI.toast("收藏成功");
- }else{
- if(res.msg){
- plus.nativeUI.toast(res.msg);
- }else{
- plus.nativeUI.toast("收藏失败!");
- }
- }
-
- })
-
- }
- /*
- * 取消收藏文章
- */
- function unCollectionArticle(code,$this){
- plus.nativeUI.showWaiting();
- var params = {};
- params.articleId=code;
- params.userType = 1; //1医生,2居民
- sendPost("/third/jkEdu/Article/cancelArticleCollection",params,function(res){
- plus.nativeUI.closeWaiting();
- if(res.msg){
- plus.nativeUI.toast(res.msg);
- }else{
- plus.nativeUI.toast("取消收藏失败!");
- }
- },function(res){
- plus.nativeUI.closeWaiting();
- if(res.status==200){
- $this.attr("data-status", 0);
- $this.find("img").attr("src", "../images/shoucang_button.png");
- var span = $this.find("span");
- var collectNum = parseInt(span.html());
- span.html(collectNum-1);
- plus.nativeUI.toast("取消收藏成功");
- }else{
- if(res.msg){
- plus.nativeUI.toast(res.msg);
- }else{
- plus.nativeUI.toast("取消收藏失败!");
- }
- }
-
- })
- }
- //弹框提示是否发送给居民
- function showDialog(article,title,patientName) {
- dialog({
- title: '<div><div class="c-f18 c-17b3ec c-t-left">发送给</div><div class="mt5 c-f14 c-t-left c-909090">'+patientName+'</div></div>',
- content: '<div><div class="c-f16 c-323232 c-t-left mb10">《'+title+'》</div><input id="messageInput" class="c-f14 pl10" placeholder="给居民留言..."/></div>',
- okValue: '立即发送',
- cancelValue: '我再看看',
- cancel: function () {
- return;
- },
- ok: function() {
- send(article);
- }
- }).showModal();
- }
- //发送文章给患者
- function send(article){
- var url = "/doctor/jkEdu/article/doctorSendArticleToPatients",
- params = {
- articleId: article,
- patientCode: patient,
- patient: patient,
- // teamCode: teamCode,
- leaveWords: $.trim($('#messageInput').val())
- };
- if(pCodes){
- params.patient = pCodes.join(",");
- }
- var docInfo = JSON.parse(plus.storage.getItem('docInfo'));
- params.currentUserRole = docInfo.hospital;
- params.currentUserRoleLevel = 4;
-
- plus.nativeUI.showWaiting();
- sendPost(url, params, null, function(res){
- if(res.status == 10000){
- mui.toast("发送成功!");
- var $this = $(".share[data-code="+article+"]");
- if(!pCodes){
- $this.after('<div class="sent-flag"><span class="c-fff c-f14 ml10">已发送</span></div>');
- }
- var num = $this.find(".send_count").text();
- $this.find(".send_count").text(parseInt(num)+1);
- if(referrer == "manbing"){
- var self = plus.webview.currentWebview(),
- selfId = self.id;
- backToManbingPage(self, selfId);
- }
- }else{
- if(res.msg){
- mui.toast(res.msg);
- }else{
- mui.toast("发送失败!");
- }
- }
- plus.nativeUI.closeWaiting();
- });
- }
- function bindEvents(){
- $("body").on('tap', '#tabPanel a', function(){
- if($(this).hasClass("mui-active")){
- return false;
- }
- selectedTab = $(this).index();
- secondLevelId = $(this).attr("data-id");
- if(loaded[selectedTab] == "false"){
- getArticleList(true);
- loaded[selectedTab] = "true";
- }
- });
-
- $(".xuanfu").on('click', function(){
- $(this).hide();
- $(".div-dialog-content").addClass("div-dialog-content-active");
- // $(".div-dialog-content").show();
- $(".modal-overlay").addClass("modal-overlay-visible");
- });
-
- //点击遮罩事件
- $(".modal-overlay").on("click", function(){
- $(".modal-overlay").removeClass("modal-overlay-visible");
- $(".div-dialog-content").removeClass("div-dialog-content-active");
- $(".xuanfu").show();
- });
-
- $(".my-article-icon").on('click', function(){
- $(".modal-overlay").removeClass("modal-overlay-visible");
- $(".div-dialog-content").removeClass("div-dialog-content-active");
- $(".xuanfu").show();
- openWebview("myArticle.html", {
- patient: patient,
- patientName: patientName,
- pCodes: pCodes,
- referrer: referrer
- });
- });
-
- $(".new-article-icon").on('click', function(){
- $(".modal-overlay").removeClass("modal-overlay-visible");
- $(".div-dialog-content").removeClass("div-dialog-content-active");
- $(".xuanfu").show();
- openWebview("addArticle.html", {hospitalName:docInfo.hospitalName,currentUserRole:docInfo.hospital});
- });
-
- $(".cancel-icon").on('click', function(){
- $(".modal-overlay").removeClass("modal-overlay-visible");
- $(".div-dialog-content").removeClass("div-dialog-content-active");
- $(".xuanfu").show();
- })
-
- $("body").on('tap', ".article-info", function(){
- var code = $(this).attr("data-article-code");
- var title = $(this).attr('data-title');
- if(isAdmin){
- openWebviewExtras("../../home/html/jianjiaotuisong-xiangqing.html",{articleId:code});
- }else{
- openWebview("article-info.html", {
- articleId: code,
- patient: patient,
- patientName: patientName,
- pCodes: pCodes,
- showHandleBar: true,
- referrer: referrer
- });
- }
- return false;
- }).on('tap','div.collect', function(){
- if(isfromAdmin){
- mui.toast("观察者模式无法收藏健康文章");
- }else{
- var $this = $(this);
- var status = $this.attr("data-status");
- var code = $this.attr("data-code");
- if(status == 0){
- collectionArticle(code,$this);
- }else{
- unCollectionArticle(code,$this);
- }
- }
- }).on('tap','div.share', function(){
- if(isfromAdmin){
- mui.toast("观察者模式无法分享健康文章");
- return false;
- }
- var $this = $(this);
- var code = $this.attr("data-code");
- var title = $this.attr("data-title");
- if(isAdmin){
- openWebviewExtras("../../home/html/tuisong_duixiang.html",{articleId:code});
- }else{
- if(!patient){
- if(isfromAdmin){
- mui.toast("观察者模式无法发送健康文章");
- }else{
- if(pCodes){
- dialog({
- title: '<div><div class="c-f18 c-17b3ec c-t-left">发送给</div><div class="mt5 c-f14 c-t-left c-909090">'+pCodes.length+'人</div></div>',
- content: '<div><div class="c-f16 c-323232 c-t-left mb10">《'+title+'》</div><input id="messageInput" class="c-f14 pl10" placeholder="给居民留言..."/></div>',
- okValue: '立即发送',
- cancelValue: '我再看看',
- cancel: function () {
- return;
- },
- ok: function() {
- send(code);
- }
- }).showModal();
- return false;
- }else{
- openWebview("xuanzejumin_more.html", {
- article: code,
- articleTitle: title,
- origin: 'jiaoyu'
- });
- }
- }
- }else{
- showDialog(code,title,patientName);
- }
- }
- });
-
- template.helper("setContent", function(str){
- var reg=/<[^<>]+>/g;
- str = str.replace(reg, '');
- return str;
- });
-
- template.helper("getArticleImage", function(str){
- if(str){
- if(str.indexOf("../") > -1){
- return ""; //原福州代码中返回的相对路径
- }
- var url = getImgUrl(str);
- return "<img src='"+url+"'>";
- }
- return "";
- });
-
- template.helper("formatDate", function(str){
- if(str){
- return str.substr(0,19)
- }else{
- return "";
- }
- });
-
- window.addEventListener('reload', function(){
- getArticleList(true);
- })
- }
- function initTabScroller(){
- //阻尼系数
- var deceleration = mui.os.ios?0.003:0.0009;
- mui('.mui-scroll-wrapper').scroll({
- bounce: false,
- indicators: true, //是否显示滚动条
- deceleration:deceleration
- });
- }
- function initScroller(){
- if(scrollers.length == 0) {
- $.each(document.querySelectorAll('.mui-slider-group .mui-scroll-wrapper'), function(index, pullRefreshEl) {
- page.push(0);
- loaded.push("false");
- var pullRefresh = mui(pullRefreshEl).pullRefresh({
- down: {
- callback: function(){
- getArticleList(true);
- this.endPulldownToRefresh();
- }
- },
- up: {
- callback: function(){
- var self = this;
- setTimeout(function(){
- getArticleList(false);
- // self.endPullupToRefresh();
- }, 500);
- }
- }
- });
-
- scrollers.push(pullRefresh);
- })
- }
- }
- function backToManbingPage(wv, selfId){
- var targetId = "zhongdiangenzong";
- if(wv.id == targetId){
- setTimeout(function(){
- plus.webview.getWebviewById(selfId).close();
- }, 300);
- }else{
- var opener = wv.opener();
- if(wv.id != selfId){
- wv.close();
- }
- backToManbingPage(opener, selfId);
- }
- }
- //设置页面监听
- window.addEventListener("refresh", function(){
- getArticleList(true);
- });
|