suifang_list.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. var patiCode = "";
  2. var patiName = "";
  3. var scrollerObArr=[],baseEnv;
  4. var menuData = [{code:"1",name:"随访计划",url:"doctor/followup/list_by_team",page: 1,template: 'suifang_tmpl'},
  5. {code:"2",name:"随访记录",url:"doctor/followup/list_by_team",page: 1,template: 'suifang_tmpl'}];
  6. var slider = null;
  7. var noResultWrap = '<div id="no_result_wrap">'+
  8. '<img class="no-result-img" src="../../../images/shujuweikong_img.png" />'+
  9. '</div>';
  10. var activeIndex = 0;
  11. var pageSize = 10;
  12. var docInfo ='';
  13. var type = ""; //记录前一个页面的id
  14. // 获取基础环境信息
  15. var getBaseEnvPromise = function () {
  16. var env = {
  17. webview: plus&&plus.webview.currentWebview()
  18. };
  19. return Promise.resolve().then(function(res) {
  20. return env;
  21. });
  22. },
  23. //初始化iscroll对象
  24. initScroller = function(menuData){
  25. for(var x in menuData){
  26. var $dom = $("#div-container"+x);
  27. //实例化iscroll
  28. var contentIscroll = $dom.lscroll({
  29. iscrollOpt: {
  30. click:true
  31. },
  32. pullDownAction: function(g){
  33. var curPage = g.options.page;
  34. getList(g.iScroll,curPage, true);
  35. },
  36. pullUpAction: function(g){
  37. var curPage = g.options.page;
  38. getList(g.iScroll,curPage, false);
  39. }
  40. });
  41. scrollerObArr.push({myscroll:contentIscroll});
  42. }
  43. },
  44. //加载数据
  45. getList = function(myscroll,page,isInit){
  46. var target = $(myscroll.wrapper).find(".div-content").find("ul.dest_list_wrap");
  47. var index = parseInt($(myscroll.wrapper).find(".div-content").attr("id").replace("div-container",""));
  48. var menu = menuData[index];
  49. var teamCode = $(".lin-sel-group li").eq(activeIndex).attr('data-code');
  50. if(isInit) {
  51. menu.page = page
  52. }
  53. getReqPromise(menu.url,{
  54. type: index+1,
  55. patient: patiCode,
  56. teamCode: teamCode||"",
  57. page: page,
  58. pagesize: pageSize
  59. }).then(function(res) {
  60. if(res.status==200){
  61. var list = res.list || res.data;
  62. if(list.length > 0){
  63. var len = list.length;
  64. menu.page++;
  65. var html = template(menu.template, {list: list});
  66. if(isInit){//下拉刷新
  67. target.html(html);
  68. }else{//上拉加载
  69. target.append(html);
  70. }
  71. setTimeout(function(){
  72. scrollerObArr[index].myscroll.refresh(len<pageSize);
  73. },500)
  74. }else{//无数据
  75. setTimeout(function(){
  76. scrollerObArr[index].myscroll.refresh(true);
  77. },500)
  78. if(page==1){
  79. $(myscroll.wrapper).find(".div-content ul.dest_list_wrap").html(noResultWrap);
  80. }
  81. }
  82. }else{
  83. $(myscroll.wrapper).find(".div-content ul.dest_list_wrap").empty();
  84. mui.toast(res.msg)
  85. }
  86. });
  87. slider.gotoItem(index);
  88. },
  89. //获取反馈类型字典
  90. initArticleType = function(){
  91. var menuStr = "";
  92. var contentStr = "";
  93. var activeClass,contentClass;
  94. for(var x in menuData){
  95. //菜单
  96. activeClass = "";
  97. if(x==0){activeClass = "mui-active";}
  98. menuStr+='<a class="mui-control-item c-f16 '+activeClass+'" data-index="'+x+'">'+menuData[x].name+'</a>';
  99. //内容
  100. contentStr+='<div class="mui-slider-item mui-control-content '+activeClass+'">'+
  101. '<div class="div-content" id="div-container'+x+'">'+
  102. '<ul class="dest_list_wrap"></ul></div>'+
  103. '</div>';
  104. }
  105. $(".div-menu").html(menuStr);
  106. $(".mui-slider-group").html(contentStr);
  107. initScroller(menuData);//初始化iscroll事件
  108. initPage(1,$("#Dtitle").attr("data-index"));
  109. slider = mui('.mui-slider').slider();
  110. $('.mui-scroll-wrapper').addClass('mui-slider-indicator');
  111. mui('.mui-scroll-wrapper').scroll();
  112. },
  113. //页面初始化
  114. initPage = function(page,status) {
  115. var reqUrl = [];
  116. var teamCode = $(".lin-sel-group li").eq(activeIndex).attr('data-code');
  117. var params = _.map(menuData,function(o) {
  118. return {
  119. url: o.url,
  120. data: {
  121. patient: patiCode,
  122. teamCode: teamCode||"",
  123. type: 1,
  124. page: o.page,
  125. pagesize: pageSize,
  126. }
  127. }
  128. });
  129. var firstReq = [];
  130. firstReq.push(params[0]);
  131. getReqPromises(firstReq).then(function(datas) {
  132. _.each(datas,function(o,i) {
  133. var res = datas[i];
  134. if(res.status == 200) {
  135. var list = res.list || res.data;
  136. if(list.length > 0) {
  137. var len = list.length;
  138. menuData[i].page++;
  139. var html = template(menuData[i].template, {list: list});
  140. $(".mui-slider-group").find(".div-content").find("ul.dest_list_wrap").eq(i).html(html);
  141. setTimeout(function(){
  142. scrollerObArr[i].myscroll.refresh(len<pageSize);
  143. },500)
  144. } else {
  145. $(".mui-slider-group").find(".div-content").find("ul.dest_list_wrap").eq(i).html(noResultWrap);
  146. setTimeout(function(){
  147. scrollerObArr[i].myscroll.refresh(true);
  148. },500)
  149. }
  150. } else{
  151. mui.toast(res.msg)
  152. }
  153. });
  154. plus.nativeUI.closeWaiting();
  155. }).catch(function(e) {
  156. console && console.error(e);
  157. });
  158. },
  159. // 绑定页面事件
  160. bindEvents = function () {
  161. //切换菜单
  162. $('.mui-slider').on('tap','.mui-control-item:not(.mui-active)',function(){
  163. var index = this.getAttribute('data-index');
  164. getList(scrollerObArr[index].myscroll.iScroll,1, true)
  165. })
  166. $(".demo-comtop").on("click","h1",function(){
  167. $(".lin-mask").show();
  168. $(".lin-sel-group").show();
  169. });
  170. $(".lin-mask").on("click",function(){
  171. $(".lin-mask").hide();
  172. $(".lin-sel-group").hide();
  173. });
  174. $(".lin-sel-group").on("click","li",function(){
  175. slider.gotoItem(0);
  176. activeIndex = $(this).index();
  177. var index = $(this).attr("data-code");
  178. $(".lin-sel-group li").removeClass("checked");
  179. $(this).addClass("checked");
  180. $(".lin-mask").trigger("click");
  181. $("#Dtitle").html($(this).find("label").html()).attr("data-index",index);
  182. _.each(menuData,function(o) {
  183. o.page = 1;
  184. })
  185. //重新加载数据
  186. initPage(1,index);
  187. });
  188. //模板中的item的点击事件
  189. $('body').on("tap", ".sf_detail", function(){
  190. openSuiFangDetail(this);
  191. })
  192. },
  193. // 修复bug#2580 【医生端】居民服务:团队长只能查看居民的服务记录信息问题。
  194. hasSigned = function() {
  195. return $(".lin-sel-group li").eq(activeIndex).attr('data-has-sign')=="1";
  196. },
  197. openSuiFangDetail = function(ele) {
  198. var info = JSON.parse(ele.getAttribute("data-info"));
  199. //不是随访医生,团队长且状态没完成 1-->已完成 3-->进行中2-->未开始(计划中)
  200. if(docInfo.code != info.doctorCode && !(docInfo.isLeader=="1" && docInfo.adminTeamCode ==$("#Dtitle").attr("data-index")) && info.status!=1 ){
  201. mui.toast("您暂时无法查看哦");
  202. return ;
  203. }
  204. var str = ele.getAttribute("data-info");
  205. var docMsg = JSON.stringify(docInfo);
  206. var strObj = JSON.parse(str);
  207. var otherPeople = false;
  208. if(docInfo.code != info.doctorCode && !(docInfo.isLeader=="1" && docInfo.adminTeamCode ==$("#Dtitle").attr("data-index"))){
  209. otherPeople = true
  210. }
  211. if(strObj.prescriptionCode){
  212. if(strObj.status!='2'){
  213. openWebview("../../suifang/html/fvDetail.html", {followup_id: strObj.id,status:strObj.status,prescriptionCode:strObj.prescriptionCode,otherPeople:otherPeople});
  214. }else{
  215. var patientInfo={}
  216. patientInfo.code = strObj.patientCode
  217. mui.openWindow('../../suifang/html/follow_way.html', 'follow_way', {
  218. extras: {
  219. followup_id:strObj.id,
  220. followClass:strObj.followupClass,
  221. patientInfo:patientInfo,
  222. prescriptionCode: strObj.prescriptionCode
  223. }
  224. })
  225. }
  226. }else{
  227. openWebview("../../suifang/html/suifang_detail.html", {data: str,docInfo:docMsg});
  228. }
  229. },
  230. addNew = function() {
  231. openWebview("choose_suifang.html", {patiCode: patiCode});
  232. },
  233. prepareData = function(){
  234. if(type && type == "sf"){ //显示随访的数据
  235. menuData = [
  236. {code:"2",name:"随访",url:"doctor/followup/list_by_team",page: 1,template: 'suifang_tmpl'}
  237. ];
  238. $("#statistics_btn").hide();
  239. }else{
  240. $("#statistics_btn").show();
  241. }
  242. }
  243. // 页面业务处理流程开始
  244. new Promise(function(resolve, reject) {
  245. // TODO 临时放开
  246. //resolve(true);
  247. mui.plusReady(function() {
  248. // plus已经准备好,可以往下执行
  249. resolve(true);
  250. });
  251. }).then(function() {
  252. template.helper('toInfo', function(v){
  253. v.patientCode = patiCode;
  254. return JSON.stringify(v);
  255. });
  256. template.helper("setSex", function(s) {
  257. if(s == 1) {
  258. return "男"
  259. } else if(s == 2) {
  260. return "女"
  261. }
  262. });
  263. template.helper("setPhoto", function(p) {
  264. return getImgUrl(p);
  265. });
  266. template.helper("setTime", function(p) {
  267. if(p){
  268. p = p.split('.')[0];
  269. return new Date(Date.parse(p.replace(/-/g, "/"))).format("yyyy-MM-dd hh:mm:ss")
  270. }else{
  271. return "";
  272. }
  273. });
  274. //随访
  275. template.helper("setTime2", function(p) {
  276. // 为了防止类似“2016-12-21 14:08:10.0”在IOS上无法识别问题
  277. if(p){
  278. p = p.split('.')[0];
  279. return new Date(Date.parse(p.replace(/-/g, "/"))).format("yyyy-MM-dd hh:mm")
  280. }else{
  281. return "";
  282. }
  283. });
  284. }).then(function() {
  285. docInfo = JSON.parse(plus.storage.getItem("docInfo"));
  286. // 获取基础环境信息
  287. return getBaseEnvPromise().then(function(env) {
  288. baseEnv = env;
  289. patiCode =baseEnv.webview.patientCode;
  290. patiName = baseEnv.webview.patientName;
  291. })
  292. })
  293. .then(function() {
  294. // plus.nativeUI.showWaiting();
  295. // // TODO 团队选择
  296. // return getReqPromise("doctor/family_contract/patient_doctor_teams",{
  297. // patient: patiCode
  298. // }).then(function(res) {
  299. // if(res.status == 200) {
  300. // var data = res.data,teams = [];
  301. // // 是否有签约关系 1:有 0:无,此时jtTeam与ssTeam都没有
  302. // if(data.hasSign=="1") {
  303. // data.ssTeam && (function() {
  304. // var team = data.ssTeam.team;
  305. // team.hasSign = data.ssTeam.hasSign; // 医生与患者是否有签约关系
  306. // team.isLeader = data.ssTeam.isLeader; // 是否是团队长
  307. // teams.push(team)
  308. // })();
  309. // data.jtTeam && (function() {
  310. // var team = data.jtTeam.team;
  311. // team.hasSign = data.jtTeam.hasSign; // 医生与患者是否有签约关系
  312. // team.isLeader = data.jtTeam.isLeader; // 是否是团队长
  313. // teams.push(team)
  314. // })();
  315. // }
  316. // }
  317. // $('.lin-sel-group').html(template('teams_tmpl', {data:teams}));
  318. // //初始默认选中第一个团队信息
  319. // var $select = $(".lin-sel-group li").eq(activeIndex);
  320. // var code = $select.attr("data-code");
  321. // $(".lin-sel-group li").removeClass("checked");
  322. // $select.addClass("checked");
  323. // $("#Dtitle").html($select.find("label").html()).attr("data-index",code);
  324. // })
  325. })
  326. .then(function() {
  327. reference = baseEnv.webview.reference || 0;
  328. type = baseEnv.webview.type;
  329. prepareData();
  330. initArticleType();
  331. bindEvents();
  332. })
  333. .catch(function(e) {
  334. plus.nativeUI.closeWaiting();
  335. console && console.error(e);
  336. })
  337. window.addEventListener("refresh2", function(event){
  338. $(".lin-sel-group li").eq(activeIndex).trigger("click");
  339. })