123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338 |
- var $queryTab = $('#query_tab'),
- $noResultWrap = $('#no_result_wrap'),
- $views = $('.c-view'),
- $jmView = $('#jm_view'),
- $ysView = $('#ys_view'),
- $searchPage_jm,
- $searchPage_ys,
- $zuijin_jumin_list = $("#zuijin_jumin_list"),
- $zuijin_yisheng_list = $("#zuijin_yisheng_list"),
- recents= {};
- var baseInfo = null, baseEnv = null, docInfo;
- var getBaseInfo = function() {
- docInfo = JSON.parse(plus.storage.getItem('docInfo'));
- var userAgent = plus.storage.getItem("userAgent");
- return {
- userAgent: JSON.parse(userAgent),
- imMessages: plus.webview.currentWebview().imMessages
- }
- },
- getBaseEnv = function() {
- return {
- webview: plus.webview.currentWebview()
- }
- },
- setTemplateHelper = function() {
- template.helper("setPatientPhoto", function(p) {
- if(!p || p == "") {
- return "../../../images/p-default.png";
- } else {
- return p
- }
- });
- template.helper("setDoctorPhoto", function(p) {
- if(!p || p == "") {
- return "../../../images/d-default.png";
- } else {
- return p
- }
- })
- template.helper("setSex", function(s) {
- if(s==1) {
- return "男"
- } else {
- return "女"
- }
- return "";
- })
- template.helper("setAge",function (str) {
- if(!str) return "";
- var r = str.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/);
- if(r==null)return false;
- var d= new Date(r[1], r[3]-1, r[4]);
- if(d.getFullYear()==r[1]&&(d.getMonth()+1)==r[3]&&d.getDate()==r[4])
- {
- var y = new Date().getFullYear();
- return (y-r[1]);
- }
- return "";
- })
- template.helper("toJson", function(o) {
- if(o) {
- return JSON.stringify(o)
- }
- return "{}";
- })
- },
- bindEvents = function() {
- $queryTab.on('click','.tab-item',function() {
- var type = $(this).attr('data-type'),
- $activeView;
-
- $queryTab.find('.tab-item').removeClass('curr');
- $views.hide();
- $(this).addClass('curr');
-
- if(type == "ys_view") {
- $jmView.find('.dest-list').hide();
- $activeView = $ysView;
- $(".span-search-title").html("搜索医生");
- $noResultWrap.find(".div-content").html("对不起,暂无最近联系记录");
- $(".div-title").html("最近联系(仅团队成员和咨询中医生)");
- } else {
- $ysView.find('.dest-list').hide();
- $activeView = $jmView;
- $(".span-search-title").html("搜索居民");
- $noResultWrap.find(".div-content").html("对不起,暂无咨询中居民");
- $(".div-title").html("最近联系(仅咨询中居民)");
- }
-
- $activeView.show();
- var isNotEmpty = !!$activeView.find('.dest-list li').length;
- if(isNotEmpty) {
- $activeView.find('.dest-list').show();
- $noResultWrap.hide();
- } else {
- $noResultWrap.show();
- }
- });
-
- $(".jm-create_chat").on('click',function() {
- mui.openWindow({
- url: "../../home/html/huanzhe.html",
- id: "Zfhuanzhe",
- extras: {
- message: "IM",
- imMessages: baseInfo.imMessages
- }
- });
- });
-
- $('.ys-create_chat').on('click',function() {
- mui.openWindow({
- url: "../../tuandui/html/tuandui.html",
- id: "Zftuandui",
- extras: {
- message: "IM",
- imMessages: baseInfo.imMessages
- }
- });
- });
-
-
- /**
- * 搜索按钮点击
- */
- $('.lin-search').on('tap', function() {
- // if($("#query_tab").find(".tab-item.curr").attr("data-type")=="jm_view"){//搜索居民
- mui.fire($searchPage_jm, "initSearch", {imMessages:baseInfo.imMessages});
- $searchPage_jm.show();
- // }else{
- // mui.fire($searchPage_ys, "initSearch", {imMessages:baseInfo.imMessages});
- // $searchPage_ys.show();
- // }
- })
- },
- loadPhoto = function(){
- //居民
- $.each($('#undo_wrapper .list-wrap .dest-list li'), function(i, v) {
- var info = JSON.parse($(v).attr('data-json'));
- imClient.Sessions.getParticipantsAvatars(info.id, function(rs){
- if(rs.length>0){
- var $photo = $(v).find('.c-avatar-m');
- $photo.html(setPhoto(rs,"patient",info));
- }
- }, function(){
-
- })
- });
- //医生
- $.each($('#doing_wrapper .list-wrap .dest-list li'), function(i, v) {
- var info = JSON.parse($(v).attr('data-json'));
- imClient.Sessions.getParticipantsAvatars(info.id, function(rs){
- if(rs.length>0){
- var $photo = $(v).find('.c-avatar-m');
- if(info.type==2){
- for(var k in rs){
- if(docInfo.code != rs[k].id){
- $photo.html('<img style="border-radius: 50px;" src="'+ rs[k].avatar +'">');
- break;
- }
- }
- } else {
- $photo.html(setPhoto(rs,"doctor",info));
- }
- }
- }, function(){
-
- })
- });
- },
- setPhoto = function(groupPhoto,type,info){
- var images = '';
- var cssArr=null;
- if(type=="patient"){
- for(var i in groupPhoto){
- if(groupPhoto[i].ispatient=="1"){//患者信息
- cssArr = ["position: absolute;width: 50px !important;height: 50px !important;border-radius: 50px;background-size: 50px;overflow: hidden;"];
- images+='<div class="div-image" style="'+cssArr+'">'+
- '<img src="'+getImgUrl(groupPhoto[i].avatar)+'"/>'+
- '</div>';
- break;
- }
- }
- }else{
- if(groupPhoto.length>=5){
- cssArr = ["top: 0;left: 50%;margin-left: -8px;","top: 12px;left: 2px;","top: 12px;left: 28px;","top: 27px;left: 5px;","top: 27px;left: 24px;"];
- }else if(groupPhoto.length==4){
- cssArr = ["top: 5px;left: 3px;","top: 5px;left: 25px;","top: 27px;left: 3px;"," top: 27px;left: 25px;"];
- }else if(groupPhoto.length==3){
- cssArr = ["top: 5px;left: 50%;margin-left: -10px;","top: 20px;left: 3px;","top: 20px;left: 25px;"];
- }else if(groupPhoto.length==2){
- cssArr = ["top: 5px;left: 50%;margin-left: -10px;"," top: 19px;left: 24px;"];
- }else if(groupPhoto.length==1 || groupPhoto.length==0){
- cssArr = ["position: absolute;width: 50px;height: 50px;border-radius: 50px;background-size: 50px;overflow: hidden;"];
- }
- for(var i in groupPhoto){
- if(i>4) break;
- if(groupPhoto[i].avatar){
- images+='<div class="div-image" style="'+cssArr[i]+'">'+
- '<img src="'+getImgUrl(groupPhoto[i].avatar)+'"/>'+
- '</div>';
- }else{
- images+='<div class="div-image" style="'+cssArr[i]+'">'+
- '<img src="../../../images/d-default.png"/>'+
- '</div>';
- }
- }
- if(groupPhoto.length==0){
- images+='<div class="div-image" style="'+cssArr[0]+'">'+
- '<img src="../../../images/d-default.png"/>'+
- '</div>';
- }
- }
-
- return images;
-
- };
- // 页面业务处理流程开始
- new Promise(function(resolve, reject) {
- mui.plusReady(function() {
- resolve(true);
- });
- })
- .then(function() {
- baseEnv = getBaseEnv();
- baseInfo = getBaseInfo();
- setTemplateHelper();
- })
- .then(function() {
- plus.nativeUI.showWaiting();
- //查询最近联系(仅咨询中居民)
- imClient.Sessions.getSessionsWithPatient(docInfo.code, 1, 2000, 0, function(rs){
- console.log(JSON.stringify(rs))
- var data = [];
- $.each(rs, function(i, v){
- if(v.business_type==2 && v.type!=0 && v.type!=3 && v.last_content_type!="7"){
- data.push(v);
- }
- })
- if(data.length==0){
- $noResultWrap.show();
- }else{
- var resData = soreByTimeStamp(data);
- $zuijin_jumin_list.html(template("jumin_li_tmpl",{list: resData}));
- loadPhoto();
- }
- plus.nativeUI.closeWaiting();
- })
- //最近联系(仅团队成员和咨询中医生)
- imClient.Sessions.getRecentSessions(baseInfo.userAgent.uid, function(data){
- var p = [];
- var d = [];
- $.each(data, function(i, v){
- v.business_type==2? p.push(v) : d.push(v);
- })
- recents.patients = p;
- recents.doctors = d;
- if(data) {
- $zuijin_yisheng_list.html(template("yisheng_li_tmpl",{list: d}));
- loadPhoto();
- } else {
- mui.toast(res.msg);
- }
- }, function(msg){
- mui.toast('获取最近联系人失败!');
- console.error(JSON.stringify(msg));
- })
- })
- .then(function() {
-
- /**
- * [搜索居民]预加载查询页面
- */
- $searchPage_jm = plus.webview.getWebviewById('sousuojuming');
- if($searchPage_jm){
- $searchPage_jm.hide();
- }else{
- $searchPage_jm = mui.preload({
- id:"zfsousuojuming",
- url: '../../home/html/sousuojuming.html'
- });
- }
-
- /**
- * 【搜索医生】预加载查询页面
- */
- // $searchPage_ys = plus.webview.getWebviewById('zfsousuoyisheng');
- // if($searchPage_ys){
- // $searchPage_ys.hide();
- // }else{
- // $searchPage_ys = mui.preload({
- // id:"zfsousuoyisheng",
- // url: '../../home/html/sousuoyisheng.html'
- // });
- // }
-
- bindEvents();
- // $queryTab.find('.tab-item').eq(0).trigger('click');
- })
- .then(function() {
- $([$zuijin_jumin_list[0],$zuijin_yisheng_list[0]]).on("click",'li',function() {
- var info = JSON.parse($(this).attr("data-json"));
- var messages = baseInfo.imMessages;
- mui.confirm("是否确认将消息逐条转发给"+info.name+"?", "提示", ["不了,谢谢", "确认转发"], function(e) {
- if(e.index == 0) {
-
- } else {
- Promise.all(_.map(messages,function(msg){
- return new Promise(function(resolve, reject) {
- imClient.Sessions.sendMessage(info.id, docInfo.code, docInfo.name, msg.content,msg.type, function(res){
- resolve(true);
- }, function(msg){
- resolve(true);
- })
- })
- })).then(function() {
- mui.toast('发送成功');
- // var self = plus.webview.currentWebview();
- // mui.fire(self.opener(), "revertZf");
- // self.close();
- })
- }
- })
- });
- })
- .catch(function(e) { console && console.error(e); });
- function soreByTimeStamp(resArr){
- var formatResult = _.chain(resArr)
- // 根据date日期字段排序
- .sortBy("create_date").reverse();
- return formatResult.value();
- }
|