zhuanfa.js 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. var $queryTab = $('#query_tab'),
  2. $noResultWrap = $('#no_result_wrap'),
  3. $views = $('.c-view'),
  4. $jmView = $('#jm_view'),
  5. $ysView = $('#ys_view'),
  6. $searchPage_jm,
  7. $searchPage_ys,
  8. $zuijin_jumin_list = $("#zuijin_jumin_list"),
  9. $zuijin_yisheng_list = $("#zuijin_yisheng_list"),
  10. recents= {};
  11. var baseInfo = null, baseEnv = null, docInfo;
  12. var getBaseInfo = function() {
  13. docInfo = JSON.parse(plus.storage.getItem('docInfo'));
  14. var userAgent = plus.storage.getItem("userAgent");
  15. return {
  16. userAgent: JSON.parse(userAgent),
  17. imMessages: plus.webview.currentWebview().imMessages
  18. }
  19. },
  20. getBaseEnv = function() {
  21. return {
  22. webview: plus.webview.currentWebview()
  23. }
  24. },
  25. setTemplateHelper = function() {
  26. template.helper("setPatientPhoto", function(p) {
  27. if(!p || p == "") {
  28. return "../../../images/p-default.png";
  29. } else {
  30. return p
  31. }
  32. });
  33. template.helper("setDoctorPhoto", function(p) {
  34. if(!p || p == "") {
  35. return "../../../images/d-default.png";
  36. } else {
  37. return p
  38. }
  39. })
  40. template.helper("setSex", function(s) {
  41. if(s==1) {
  42. return "男"
  43. } else {
  44. return "女"
  45. }
  46. return "";
  47. })
  48. template.helper("setAge",function (str) {
  49. if(!str) return "";
  50. var r = str.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/);
  51. if(r==null)return false;
  52. var d= new Date(r[1], r[3]-1, r[4]);
  53. if(d.getFullYear()==r[1]&&(d.getMonth()+1)==r[3]&&d.getDate()==r[4])
  54. {
  55. var y = new Date().getFullYear();
  56. return (y-r[1]);
  57. }
  58. return "";
  59. })
  60. template.helper("toJson", function(o) {
  61. if(o) {
  62. return JSON.stringify(o)
  63. }
  64. return "{}";
  65. })
  66. },
  67. bindEvents = function() {
  68. $queryTab.on('click','.tab-item',function() {
  69. var type = $(this).attr('data-type'),
  70. $activeView;
  71. $queryTab.find('.tab-item').removeClass('curr');
  72. $views.hide();
  73. $(this).addClass('curr');
  74. if(type == "ys_view") {
  75. $jmView.find('.dest-list').hide();
  76. $activeView = $ysView;
  77. $(".span-search-title").html("搜索医生");
  78. $noResultWrap.find(".div-content").html("对不起,暂无最近联系记录");
  79. $(".div-title").html("最近联系(仅团队成员和咨询中医生)");
  80. } else {
  81. $ysView.find('.dest-list').hide();
  82. $activeView = $jmView;
  83. $(".span-search-title").html("搜索居民");
  84. $noResultWrap.find(".div-content").html("对不起,暂无咨询中居民");
  85. $(".div-title").html("最近联系(仅咨询中居民)");
  86. }
  87. $activeView.show();
  88. var isNotEmpty = !!$activeView.find('.dest-list li').length;
  89. if(isNotEmpty) {
  90. $activeView.find('.dest-list').show();
  91. $noResultWrap.hide();
  92. } else {
  93. $noResultWrap.show();
  94. }
  95. });
  96. $(".jm-create_chat").on('click',function() {
  97. mui.openWindow({
  98. url: "../../home/html/huanzhe.html",
  99. id: "Zfhuanzhe",
  100. extras: {
  101. message: "IM",
  102. imMessages: baseInfo.imMessages
  103. }
  104. });
  105. });
  106. $('.ys-create_chat').on('click',function() {
  107. mui.openWindow({
  108. url: "../../tuandui/html/tuandui.html",
  109. id: "Zftuandui",
  110. extras: {
  111. message: "IM",
  112. imMessages: baseInfo.imMessages
  113. }
  114. });
  115. });
  116. /**
  117. * 搜索按钮点击
  118. */
  119. $('.lin-search').on('tap', function() {
  120. // if($("#query_tab").find(".tab-item.curr").attr("data-type")=="jm_view"){//搜索居民
  121. mui.fire($searchPage_jm, "initSearch", {imMessages:baseInfo.imMessages});
  122. $searchPage_jm.show();
  123. // }else{
  124. // mui.fire($searchPage_ys, "initSearch", {imMessages:baseInfo.imMessages});
  125. // $searchPage_ys.show();
  126. // }
  127. })
  128. },
  129. loadPhoto = function(){
  130. //居民
  131. $.each($('#undo_wrapper .list-wrap .dest-list li'), function(i, v) {
  132. var info = JSON.parse($(v).attr('data-json'));
  133. imClient.Sessions.getParticipantsAvatars(info.id, function(rs){
  134. if(rs.length>0){
  135. var $photo = $(v).find('.c-avatar-m');
  136. $photo.html(setPhoto(rs,"patient",info));
  137. }
  138. }, function(){
  139. })
  140. });
  141. //医生
  142. $.each($('#doing_wrapper .list-wrap .dest-list li'), function(i, v) {
  143. var info = JSON.parse($(v).attr('data-json'));
  144. imClient.Sessions.getParticipantsAvatars(info.id, function(rs){
  145. if(rs.length>0){
  146. var $photo = $(v).find('.c-avatar-m');
  147. if(info.type==2){
  148. for(var k in rs){
  149. if(docInfo.code != rs[k].id){
  150. $photo.html('<img style="border-radius: 50px;" src="'+ rs[k].avatar +'">');
  151. break;
  152. }
  153. }
  154. } else {
  155. $photo.html(setPhoto(rs,"doctor",info));
  156. }
  157. }
  158. }, function(){
  159. })
  160. });
  161. },
  162. setPhoto = function(groupPhoto,type,info){
  163. var images = '';
  164. var cssArr=null;
  165. if(type=="patient"){
  166. for(var i in groupPhoto){
  167. if(groupPhoto[i].ispatient=="1"){//患者信息
  168. cssArr = ["position: absolute;width: 50px !important;height: 50px !important;border-radius: 50px;background-size: 50px;overflow: hidden;"];
  169. images+='<div class="div-image" style="'+cssArr+'">'+
  170. '<img src="'+getImgUrl(groupPhoto[i].avatar)+'"/>'+
  171. '</div>';
  172. break;
  173. }
  174. }
  175. }else{
  176. if(groupPhoto.length>=5){
  177. cssArr = ["top: 0;left: 50%;margin-left: -8px;","top: 12px;left: 2px;","top: 12px;left: 28px;","top: 27px;left: 5px;","top: 27px;left: 24px;"];
  178. }else if(groupPhoto.length==4){
  179. cssArr = ["top: 5px;left: 3px;","top: 5px;left: 25px;","top: 27px;left: 3px;"," top: 27px;left: 25px;"];
  180. }else if(groupPhoto.length==3){
  181. cssArr = ["top: 5px;left: 50%;margin-left: -10px;","top: 20px;left: 3px;","top: 20px;left: 25px;"];
  182. }else if(groupPhoto.length==2){
  183. cssArr = ["top: 5px;left: 50%;margin-left: -10px;"," top: 19px;left: 24px;"];
  184. }else if(groupPhoto.length==1 || groupPhoto.length==0){
  185. cssArr = ["position: absolute;width: 50px;height: 50px;border-radius: 50px;background-size: 50px;overflow: hidden;"];
  186. }
  187. for(var i in groupPhoto){
  188. if(i>4) break;
  189. if(groupPhoto[i].avatar){
  190. images+='<div class="div-image" style="'+cssArr[i]+'">'+
  191. '<img src="'+getImgUrl(groupPhoto[i].avatar)+'"/>'+
  192. '</div>';
  193. }else{
  194. images+='<div class="div-image" style="'+cssArr[i]+'">'+
  195. '<img src="../../../images/d-default.png"/>'+
  196. '</div>';
  197. }
  198. }
  199. if(groupPhoto.length==0){
  200. images+='<div class="div-image" style="'+cssArr[0]+'">'+
  201. '<img src="../../../images/d-default.png"/>'+
  202. '</div>';
  203. }
  204. }
  205. return images;
  206. };
  207. // 页面业务处理流程开始
  208. new Promise(function(resolve, reject) {
  209. mui.plusReady(function() {
  210. resolve(true);
  211. });
  212. })
  213. .then(function() {
  214. baseEnv = getBaseEnv();
  215. baseInfo = getBaseInfo();
  216. setTemplateHelper();
  217. })
  218. .then(function() {
  219. plus.nativeUI.showWaiting();
  220. //查询最近联系(仅咨询中居民)
  221. imClient.Sessions.getSessionsWithPatient(docInfo.code, 1, 2000, 0, function(rs){
  222. console.log(JSON.stringify(rs))
  223. var data = [];
  224. $.each(rs, function(i, v){
  225. if(v.business_type==2 && v.type!=0 && v.type!=3 && v.last_content_type!="7"){
  226. data.push(v);
  227. }
  228. })
  229. if(data.length==0){
  230. $noResultWrap.show();
  231. }else{
  232. var resData = soreByTimeStamp(data);
  233. $zuijin_jumin_list.html(template("jumin_li_tmpl",{list: resData}));
  234. loadPhoto();
  235. }
  236. plus.nativeUI.closeWaiting();
  237. })
  238. //最近联系(仅团队成员和咨询中医生)
  239. imClient.Sessions.getRecentSessions(baseInfo.userAgent.uid, function(data){
  240. var p = [];
  241. var d = [];
  242. $.each(data, function(i, v){
  243. v.business_type==2? p.push(v) : d.push(v);
  244. })
  245. recents.patients = p;
  246. recents.doctors = d;
  247. if(data) {
  248. $zuijin_yisheng_list.html(template("yisheng_li_tmpl",{list: d}));
  249. loadPhoto();
  250. } else {
  251. mui.toast(res.msg);
  252. }
  253. }, function(msg){
  254. mui.toast('获取最近联系人失败!');
  255. console.error(JSON.stringify(msg));
  256. })
  257. })
  258. .then(function() {
  259. /**
  260. * [搜索居民]预加载查询页面
  261. */
  262. $searchPage_jm = plus.webview.getWebviewById('sousuojuming');
  263. if($searchPage_jm){
  264. $searchPage_jm.hide();
  265. }else{
  266. $searchPage_jm = mui.preload({
  267. id:"zfsousuojuming",
  268. url: '../../home/html/sousuojuming.html'
  269. });
  270. }
  271. /**
  272. * 【搜索医生】预加载查询页面
  273. */
  274. // $searchPage_ys = plus.webview.getWebviewById('zfsousuoyisheng');
  275. // if($searchPage_ys){
  276. // $searchPage_ys.hide();
  277. // }else{
  278. // $searchPage_ys = mui.preload({
  279. // id:"zfsousuoyisheng",
  280. // url: '../../home/html/sousuoyisheng.html'
  281. // });
  282. // }
  283. bindEvents();
  284. // $queryTab.find('.tab-item').eq(0).trigger('click');
  285. })
  286. .then(function() {
  287. $([$zuijin_jumin_list[0],$zuijin_yisheng_list[0]]).on("click",'li',function() {
  288. var info = JSON.parse($(this).attr("data-json"));
  289. var messages = baseInfo.imMessages;
  290. mui.confirm("是否确认将消息逐条转发给"+info.name+"?", "提示", ["不了,谢谢", "确认转发"], function(e) {
  291. if(e.index == 0) {
  292. } else {
  293. Promise.all(_.map(messages,function(msg){
  294. return new Promise(function(resolve, reject) {
  295. imClient.Sessions.sendMessage(info.id, docInfo.code, docInfo.name, msg.content,msg.type, function(res){
  296. resolve(true);
  297. }, function(msg){
  298. resolve(true);
  299. })
  300. })
  301. })).then(function() {
  302. mui.toast('发送成功');
  303. // var self = plus.webview.currentWebview();
  304. // mui.fire(self.opener(), "revertZf");
  305. // self.close();
  306. })
  307. }
  308. })
  309. });
  310. })
  311. .catch(function(e) { console && console.error(e); });
  312. function soreByTimeStamp(resArr){
  313. var formatResult = _.chain(resArr)
  314. // 根据date日期字段排序
  315. .sortBy("create_date").reverse();
  316. return formatResult.value();
  317. }