123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304 |
- // TODO 临时构造plus对象,使得能够在浏览器中进行调试
- //var plus = null;
- // TODO 列表数据示例
- //var groupData = {"msg":"患者列表查询成功!","data":[{labelCode:"mbrq",labelName:"慢病人群",isSystem:"1",amount:45},{labelCode:"65sysrq",labelName:"65岁以上人群",isSystem:"1",amount:32},{labelCode:"ptrq",labelName:"普通人群",isSystem:"1",amount:3}],"status":200};
- //var patientData = {"msg":"患者列表查询成功!","data":[{"qyrq":"2016-09-18","code":"82c28c0634aa42a797f9e2eecebc79b8","disease":0,"sex":1,"idcard":"352602197602291394","name":"张西亮","signType":"2","diseases":"","partAmount":0,"age":40},{"qyrq":"2016-08-04","code":"tudouP2016082901","disease":1,"recordAmount":0,"sex":1,"idcard":"11010119900101231X","name":"谢小平","photo":"","signType":"1","diseases":[{"diseaseName":"高血压","disease":"1","signType":"1","del":"1"}],"age":26,"diseaseLevel":0}],"status":200};
- // 基本信息(包括userAgent)
- var baseInfo = null,
- // 基础环境信息(包括当前webview)
- baseEnv = null;
- var self;
- var lastTeamId;
- // 搜索框
- var $searchbar = $('.searchbar'),
- // 搜索输入框
- $searchbarInput = $('.searchbar .search-input'),
- // 搜索取消按钮
- $searchCancelBtn = $('.searchbar-cancel'),
- // 搜索框下面悬浮的搜索提示
- $searchSuggest = $('#search_suggest_text'),
- // 搜索结果展示容器
- $searchtResult = $('#search_result'),
- // 搜索无结果时显示
- $noResultWrap = $('#no_result_wrap'),
- // 患者分组列表
- $patiList = $('#pati_list'),
- $selectedTypeName = $('#selected_type_name'),
- $shezhiBtn = $("#shezhi_btn");
- // 获取登录相关信息
- var getBaseInfo = function() {
- // 登录的相关信息
- var userAgent = JSON.parse(plus.storage.getItem("userAgent"))
- return {
- userAgent: userAgent,
- teamInfo: JSON.parse(plus.storage.getItem("teamInfo")),
- accessData: baseEnv.webview.accessData
- }
- },
- // 获取基础环境信息
- getBaseEnvPromise = function () {
- self = plus.webview.currentWebview();
- var env = {
- webview: plus&&plus.webview.currentWebview()
- };
- return Promise.resolve().then(function(res) {
- return env;
- });
- },
- // 初始化画面患者分组列表
- initPatientGroupsList = function() {
- var url = self.type == 1 ? "/doctor/patient_label_info/label_team_amount" : "doctor/patient_label_info/label_patient_amount";
- getReqPromise(url,{labelType: baseInfo.accessData.labelType, teamCode: lastTeamId})
- .then(function(res) {
- if(res.status == 200) {
- var rsData = res.data;
- if(baseInfo.accessData.labelType == "9"){
- rsData = res.data.result;
- }
- var data = _.filter(rsData,function(o) {
- return o.labelCode != 0 || (o.labelCode==0 && o.amount > 0);
- });
- if(data && data.length) {
- var html = template("pati_group_tmpl", {list: data});
- $patiList.empty().append(html);
- $noResultWrap.hide();
- $searchtResult.show();
- } else {
- $searchtResult.hide();
- $noResultWrap.show();
- }
- }
-
- }).catch(function(e){ console && console.error(e); plus.nativeUI.closeWaiting(); });
- },
- showLoadMore = function($el) {
- var amount = $el.attr("data-amount"),
- loaded = $el.find('ul.n-list li').length,
- $loadMore = $el.find('.load-more');
- if(amount>loaded) {
- $loadMore.show();
- } else {
- $loadMore.hide();
- }
- },
- initPatientListByGroup = function(code) {
- var url = self.type == 1 ? "doctor/patient_label_info/team_patient" : "doctor/patient_label_info/patients_by_label";
-
- plus.nativeUI.showWaiting();
- var $group = $patiList.find('.patient-list[data-group="'+code+'"]');
- getReqPromise(url, {labelType: baseInfo.accessData.labelType, labelCode: code, teamCode: lastTeamId, page: 1, pagesize: 50})
- .then(function(res) {
- if(res.status == 200) {
- var data = res.data;
- if(baseInfo.accessData.labelType == "9"){
- data = res.data.result;
- }
- var html = template("pati_list_tmpl", {list: _.map(data,function(o) {
- o.jsonStr = JSON.stringify(o);
- return o;
- })});
- $group.find('ul.n-list').empty().append(html);
- showLoadMore($group);
- }
- plus.nativeUI.closeWaiting();
- }).catch(function(e){ console && console.error(e); plus.nativeUI.closeWaiting(); });
- },
- togglePatientListShow = function($el) {
- var isOpen = $el.hasClass("current"),
- $list = $el.find('ul.n-list'),
- $siblings = $el.siblings();
- if(isOpen) {
- $el.removeClass("current");
- $list.hide();
- $el.find('.load-more').hide();
- } else {
- $el.addClass("current");
- showLoadMore($el);
- $siblings.removeClass('current').find("ul.n-list").hide();
- $siblings.find('.load-more').hide();
- $list.show();
- }
- return isOpen;
- },
- showSheZhi = function() {
- if(baseInfo.accessData.labelType == 4) {
- $shezhiBtn.show();
- } else {
- $shezhiBtn.hide();
- }
- },
- refreshPage = function(){
- baseInfo = getBaseInfo();
- lastTeamId = plus.storage.getItem("selectedTeamId");
- $selectedTypeName.text(baseInfo.accessData.typeName);
- showSheZhi();
- initPatientGroupsList();
- },
- // 绑定页面事件
- bindEvents = function () {
- $patiList.on('click','.load-more',function() {
- plus.nativeUI.showWaiting();
- var url = self.type == 1 ? "doctor/patient_label_info/team_patient" : "doctor/patient_label_info/patients_by_label";
- var $wrap = $(this).closest(".patient-list"),
- code = $wrap.attr("data-group"),
- page = parseInt($wrap.attr("data-page"));
- getReqPromise(url,{labelType: baseInfo.accessData.labelType,labelCode: code, teamCode: lastTeamId, page: page + 1, pagesize: 50})
- .then(function(res) {
- if(res.status == 200) {
- var rsData = res.data;
- if(baseInfo.accessData.labelType == "9"){
- rsData = res.data.result;
- }
- var html = template("pati_list_tmpl", {list: _.map(rsData,function(o) {
- o.jsonStr = JSON.stringify(o);
- return o;
- })});
- $wrap.find('ul.n-list').append(html);
- $wrap.attr("data-page",page+1);
- showLoadMore($wrap);
- }
- plus.nativeUI.closeWaiting();
- }).catch(function(e){ console && console.error(e) });
- return false;
- }).on('click','.patient-list',function() {
- var code = $.trim($(this).attr("data-group")),
- isOpen = togglePatientListShow($(this)),
- isEmpty = !$(this).find('ul.n-list li').length;
- $patiList.find(".patient-type").css({position: "relative", top: "initial", "z-index": "initial"});
- code && !isOpen && isEmpty && initPatientListByGroup(code);
- }).on('click','li[data-patient-code]',function() {
- var patiInfo = $(this).attr("data-json");
- if(baseEnv.webview.message) {
- var info = JSON.parse(patiInfo);
- openWebview("../../message/html/p2p.html",{otherCode: info.code,otherName: info.name,otherPhoto: info.photo,otherSex: info.sex});
- } else {
- var overdue = "";
- var patiCode = $(this).attr("data-patient-code");
- if(baseInfo.accessData.labelType == "9"){
- overdue = 1;
- }
- openWebview("../../huanzhe/html/huanzhexinxi.html",{teamCode: lastTeamId, patiCode:patiCode, overdue : overdue});
- }
- return false;
- })
-
- $searchbarInput.on('click',function() {
- mui.openWindow({
- id:"searchhuanzhe",
- url: '../../huanzhe/html/searchhuanzhe.html',
- extras: {
- message: baseEnv.webview.message,
- type: self.type,
- labelType:baseInfo.accessData.labelType
- }
- });
- });
-
- $shezhiBtn.on('click',function() {
- openWebview("../../huanzhe/html/biaoqianguanli.html",{
- teamCode: plus.storage.getItem("selectedTeamId")
- });
- });
-
- /*刷新事件*/
- window.addEventListener("refresh", function refresh(e) {
- refreshPage();
- });
- // window.onscroll = function() {
- // var scrollTop = document.body.scrollTop,
- // $current = $('.patient-list.current',$patiList).eq(0),
- // top = $current.length && $current.offset().top;
- // if($current.length) {
- // if(scrollTop >= top - 50) {
- // $current.find(".patient-type").css({position: "fixed", top: 45, "z-index": 9999});
- // } else {
- // $current.find(".patient-type").css({position: "relative", top: "initial", "z-index": "initial"});
- // }
- // }
- // }
-
- /*提醒续签*/
- $("#remindRenew").on("tap", function(){
- var remindInfo = window.localStorage.getItem("remindXQ");
- //remindInfo = {date: '2017-05-07', remind: 1}
- var info = remindInfo && JSON.parse(remindInfo);
- var date = new Date(),
- dateStr = date.format("yyyy-MM-dd");
- if(remindInfo && (info.date == dateStr) && (info.remind == 1)){
- mui.toast("对不起,您今天已经全部提醒过,无法再次全部提醒");
- return;
- }
- var url = "/doctor/sign/sendRenewToPatients";
- dialog({
- content: "是否向所有去年签约到期居民发送签约提醒?(如绑定手机号则短信提醒,如绑定微信则微信提醒)",
- okValue: "立即提醒",
- ok: function(){
- plus.nativeUI.showWaiting();
- sendPost(url, {}, null, function(res){
- if(res.status == 200){
- if(res.data == 0){
- mui.toast(res.msg);
- }else{
- mui.toast("已向所有待续签居民发出续签提醒");
- }
- var obj = {date: dateStr, remind: 1};
- localStorage.setItem("remindXQ", JSON.stringify(obj));
- // $(".header-link").hide();
- }else{
- mui.toast(res.msg);
- }
- plus.nativeUI.closeWaiting();
- }, "post", "", true);
- },
- cancelValue: "不了,谢谢",
- cancel: function(){}
- }).showModal();
- });
- };
- // 页面业务处理流程开始
- new Promise(function(resolve, reject) {
- // TODO 临时放开
- //resolve(true);
- mui.plusReady(function() {
- // hrefhrefplus已经准备好,可以往下执行
- var oldBack = mui.back;
- mui.back = function() {
- var preWebview = plus.webview.currentWebview().opener();
- mui.fire(preWebview,"refresh");
- oldBack();
- }
- resolve(true);
- });
- }).then(function() {
-
- // 获取基础环境信息
- return getBaseEnvPromise().then(function(env) {
- baseEnv = env;
- }).then(function() {
- // 获取登录基本信息
- baseInfo = getBaseInfo();
- lastTeamId = plus.storage.getItem("selectedTeamId");
- $selectedTypeName.text(baseInfo.accessData.typeName);
- //如果是签约过期居民,显示“提醒续签”按钮
- if(baseInfo.accessData.labelType == "9"){
- $("#remindRenew").show();
- }else{
- $("#remindRenew").hide();
- }
- showSheZhi();
- // 绑定页面事件
- bindEvents();
- initPatientGroupsList();
-
- })
- }).catch(function(e) {
- plus.nativeUI.closeWaiting();
- console && console.error(e);
- });
|