guidance_huanzhe.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. // TODO 临时构造plus对象,使得能够在浏览器中进行调试
  2. // var plus = null;
  3. // 基本信息(包括userAgent、上个页面传递的数据)
  4. var baseInfo = null,
  5. // 基础环境信息(包括当前webview)
  6. baseEnv = null,
  7. pages = {}, //记录个分组内数据页数
  8. docInfo,
  9. content,
  10. modelCode,
  11. images;
  12. var $searchbarInput = $('.searchbar .search-input'),
  13. // 搜索无结果时显示
  14. $noResultWrap = $('#no_result_wrap'),
  15. patientInfo = null;
  16. // 获取基本信息(包括userAgent、上个页面传递的数据)
  17. var getBaseInfoPromise = function() {
  18. // 登录的相关信息
  19. var userAgent = plus && JSON.parse(plus.storage.getItem("userAgent"))
  20. return {
  21. userAgent: userAgent
  22. }
  23. },
  24. // 获取基础环境信息
  25. getBaseEnvPromise = function () {
  26. var env = {
  27. webview: plus&&plus.webview.currentWebview()
  28. };
  29. return Promise.resolve().then(function(res) {
  30. return env;
  31. });
  32. },
  33. //获取分组信息
  34. getGroupData = function(){
  35. docInfo = JSON.parse(plus.storage.getItem("docInfo"));
  36. var url = "doctor/patient_label_info/label_patient_amount",
  37. params = {
  38. labelType: 4, //获取团队标签
  39. teamCode: docInfo.adminTeamCode
  40. };
  41. plus.nativeUI.showWaiting();
  42. sendPost(url, params, null,function(res){
  43. if(res.status == 200){
  44. for(i=0; i<res.data.length; i++){
  45. var item = res.data[i];
  46. pages[item.labelCode] = 1;
  47. }
  48. var html = template("pati_group_tmpl", {list: res.data});
  49. $("#groupList").empty().append(html);
  50. plus.nativeUI.closeWaiting();
  51. }else{
  52. plus.nativeUI.closeWaiting();
  53. mui.toast(res.msg);
  54. }
  55. });
  56. },
  57. // 分页查询列表
  58. initPatientListByGroup = function(code, isInit) {
  59. if(isInit){
  60. pages[code] = 1;
  61. }
  62. var url = "doctor/patient_label_info/patients_by_label",
  63. params = {
  64. labelType: 4,
  65. labelCode: code,
  66. teamCode: docInfo.adminTeamCode,
  67. page: pages[code],
  68. pagesize: 20
  69. };
  70. sendGet(url, params, null, function(res){
  71. if(res.status == 200){
  72. var list = res.data;
  73. if(list.length == 0){
  74. $(".group-item[data-group="+code+"]").find(".load-more").hide();
  75. }else{
  76. var html = template("pati_list_tmpl", {list: list});
  77. if(isInit){
  78. $(".n-list[data-group="+code+"]").empty().append(html);
  79. }else{
  80. $(".n-list[data-group="+code+"]").append(html);
  81. }
  82. if(list.length < 20){
  83. $(".group-item[data-group="+code+"]").find(".load-more").hide();
  84. }else{
  85. pages[code] ++;
  86. $(".group-item[data-group="+code+"]").find(".load-more").show();
  87. }
  88. }
  89. }else{
  90. mui.toast(res.msg);
  91. }
  92. }, true)
  93. },
  94. // 滚动条分页实例初始化
  95. initScroller = function() {
  96. //阻尼系数
  97. var deceleration = mui.os.ios?0.003:0.0009;
  98. mui('.mui-scroll-wrapper').scroll({
  99. bounce: false,
  100. indicators: true, //是否显示滚动条
  101. deceleration:deceleration
  102. });
  103. mui(".mui-scroll").pullToRefresh({
  104. down: {
  105. callback: function() {
  106. var self = this;
  107. setTimeout(function() {
  108. getGroupData();
  109. self.endPullDownToRefresh();
  110. }, 1000);
  111. }
  112. }
  113. });
  114. },
  115. // 绑定页面事件
  116. bindEvents = function () {
  117. var acTiveId='activeId';//选中的ID
  118. $("#groupList").on('tap','li[data-patient-code]',function(e) {
  119. var code = $(this).attr("data-patient-code");
  120. var mobile = $(this).attr("data-patient-phone");
  121. var address = $(this).attr("data-patient-address");
  122. var isCheck = $(this).attr("check");
  123. var id = $(this).attr('id');
  124. if(id != acTiveId ){ //如果点击的不是之前选中的
  125. $('#'+acTiveId).find('.checboxImg').find('img').attr('src','../images/checbox-false.png');
  126. $('#'+acTiveId).removeAttr('id');
  127. $(this).find('.checboxImg').find('img').attr('src','../images/checbox-true.png');
  128. $(this).attr('check','yes');
  129. $(this).attr('id',acTiveId);
  130. }
  131. else { //如果点击的是自己的话
  132. if(isCheck == 'no'){
  133. $(this).find('.checboxImg').find('img').attr('src','../images/checbox-true.png');
  134. $(this).attr('check','yes');
  135. }
  136. else {
  137. $(this).find('.checboxImg').find('img').attr('src','../images/checbox-false.png');
  138. $(this).attr('check','no');
  139. $(this).removeAttr('id',acTiveId);
  140. }
  141. }
  142. // if(baseEnv.webview.origin=="suifang") {//“随访”功能
  143. // if(baseEnv.webview.follow_type == 1){
  144. // openWebview("../../suifang/html/add_plan.html",{patientInfo: {code:code,mobile:mobile,address:address},chooseDate:baseEnv.webview.chooseDate});
  145. // return false;
  146. // }
  147. // if(baseEnv.webview.follow_type == 2){
  148. // openWebview("../../suifang/html/follow_way.html",{patientInfo: {code:code,mobile:mobile,address:address}});
  149. // return false;
  150. // }
  151. // }else{
  152. // openWebview("../../huanzhe/html/huanzhexinxi.html",{
  153. // patiCode: code
  154. // });
  155. // }
  156. return false;
  157. });
  158. $(".send_btn").on('tap', function(){
  159. var patiCode =$('#'+acTiveId).attr('data-patient-code');
  160. if(!patiCode) {mui.toast("请选择居民再进行发送");return};
  161. dialog({
  162. content: "发出后无法变更,是否确认发送给居民?",
  163. okValue: "继续发送",
  164. ok: function(){
  165. var url = "doctor/health/guidance/add",
  166. params = {
  167. patient: patiCode,
  168. content: content,
  169. modelCode: modelCode,
  170. images: images
  171. };
  172. console.log(params)
  173. plus.nativeUI.showWaiting();
  174. sendPost(url, params, null, function(res){
  175. if (res.status == 200) {
  176. mui.toast("发送成功!");
  177. var self = plus.webview.currentWebview(),
  178. opener = self.opener(),
  179. pre_opener = self.opener().opener();
  180. if(opener.id == "jkzd"){ //自己的模板详情
  181. if(pre_opener.id == "guidance_info"){
  182. mui.fire(pre_opener.opener(), "update");
  183. pre_opener.opener().show();
  184. mui.later(function(){
  185. pre_opener.close('none');
  186. opener.close('none');
  187. self.close('none');
  188. }, 300);
  189. }else{
  190. mui.fire(pre_opener, "update");
  191. pre_opener.show();
  192. mui.later(function(){
  193. opener.close('none');
  194. self.close('none');
  195. }, 300);
  196. }
  197. }else{ //系统模板详情
  198. var pre_pre_opener = pre_opener.opener();
  199. if(pre_pre_opener.id == "guidance_info"){
  200. mui.fire(pre_pre_opener.opener(), "update");
  201. pre_pre_opener.opener().show();
  202. mui.later(function(){
  203. pre_pre_opener.close('none');
  204. opener.close('none');
  205. pre_opener.close('none');
  206. self.close('none');
  207. }, 300);
  208. }else{
  209. mui.fire(pre_pre_opener, "update");
  210. pre_pre_opener.show();
  211. mui.later(function(){
  212. opener.close('none');
  213. pre_opener.close('none');
  214. self.close('none');
  215. }, 300);
  216. }
  217. }
  218. }else{
  219. mui.toast(res.msg)
  220. }
  221. plus.nativeUI.closeWaiting();
  222. }, 'POST', '', true);
  223. },
  224. cancelValue: "不了,谢谢",
  225. cancel: function(){}
  226. }).showModal();
  227. });
  228. $("#groupList").on('tap', ".group-item", function(){
  229. var $el = $(this),
  230. code = $.trim($el.attr("data-group")),
  231. amount = parseInt($el.attr("data-amount")),
  232. isOpen = $el.hasClass("current"),
  233. $groupInfo = $el.find('.group-info'),
  234. $siblings = $el.siblings();
  235. if(isOpen) {
  236. $el.removeClass("current");
  237. $el.find(".ui-arrow").removeClass("ui-arrow-t");
  238. $el.find(".ui-arrow").addClass("ui-arrow-b");
  239. $groupInfo.hide();
  240. }else{
  241. var $opened = $(".group-item.current");
  242. $el.addClass("current");
  243. $el.find(".ui-arrow").removeClass("ui-arrow-b");
  244. $el.find(".ui-arrow").addClass("ui-arrow-t");
  245. if($opened.length > 0){
  246. $opened.removeClass('current').find(".group-info").hide();
  247. $opened.find(".ui-arrow").removeClass("ui-arrow-t");
  248. $opened.find(".ui-arrow").addClass("ui-arrow-b");
  249. }
  250. if(amount > 0){
  251. $groupInfo.show();
  252. var liLen = $el.find('ul.n-list li').length;
  253. if(liLen == 0){
  254. initPatientListByGroup(code, true);
  255. }
  256. }
  257. }
  258. });
  259. $("#groupList").on('tap', ".load-more", function(e){
  260. e.stopPropagation();
  261. var $this = $(this),
  262. code = $this.attr("data-group");
  263. // mui('.mui-scroll-wrapper').refresh();
  264. initPatientListByGroup(code, false);
  265. });
  266. $searchbarInput.on('tap',function() {
  267. mui.openWindow({
  268. id: "searchhuanzhe2",
  269. url: "../../huanzhe/html/searchhuanzhe.html",
  270. extras: {}
  271. })
  272. });
  273. $(".header-link").on('click', function(){
  274. openWebview("../../huanzhe/html/biaoqianguanli.html",{
  275. teamCode: docInfo.adminTeamCode
  276. });
  277. })
  278. /*刷新事件*/
  279. window.addEventListener("refresh", function group(e) {
  280. getGroupData();
  281. });
  282. };
  283. // 页面业务处理流程开始
  284. new Promise(function(resolve, reject) {
  285. // TODO 临时放开
  286. //resolve(true);
  287. mui.plusReady(function() {
  288. // plus已经准备好,可以往下执行
  289. resolve(true);
  290. });
  291. }).then(function() {
  292. // 获取基础环境信息
  293. return getBaseEnvPromise().then(function(env) {
  294. baseEnv = env;
  295. }).then(function() {
  296. // 获取登录医生信息
  297. var self = plus.webview.currentWebview();
  298. content =self.content;
  299. modelCode =self.modelCode;
  300. images =self.images;
  301. console.log(content)
  302. console.log(modelCode)
  303. console.log(images)
  304. baseInfo = getBaseInfoPromise();
  305. initScroller();
  306. // searchByPaging(true);
  307. getGroupData();
  308. // 绑定页面事件
  309. bindEvents();
  310. if(baseEnv.webview.origin){//“随访”功能,需要返回按钮
  311. $(".mui-action-back").show();
  312. }
  313. })
  314. }).catch(function(e) {
  315. plus.nativeUI.closeWaiting();
  316. console && console.error(e);
  317. });
  318. function setAge(age) {
  319. if(age == 0) {
  320. return "<1";
  321. }
  322. if(age == -1)
  323. return "未知";
  324. return age;
  325. }
  326. template.helper("setAge", setAge);
  327. function setSex(s) {
  328. if(s == 1) {
  329. return "男";
  330. } else if(s == 2) {
  331. return "女";
  332. }
  333. }
  334. template.helper("setSex", setSex);
  335. template.helper("getPhoto", function(str){
  336. return getImgUrl(str);
  337. })