guidance_huanzhe.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  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 main =plus.webview.getWebviewById('guidance_list');
  178. mui.fire(main,'refresh');
  179. var self = plus.webview.currentWebview(),
  180. opener = self.opener(),
  181. pre_opener = self.opener().opener();
  182. if(opener.id == "jkzd"){ //自己的模板详情
  183. if(pre_opener.id == "guidance_info"){
  184. mui.fire(pre_opener.opener(), "update");
  185. pre_opener.opener().show();
  186. mui.later(function(){
  187. pre_opener.close('none');
  188. opener.close('none');
  189. self.close('none');
  190. }, 300);
  191. }else{
  192. mui.fire(pre_opener, "update");
  193. pre_opener.show();
  194. mui.later(function(){
  195. opener.close('none');
  196. self.close('none');
  197. }, 300);
  198. }
  199. }else{ //系统模板详情
  200. var pre_pre_opener = pre_opener.opener();
  201. if(pre_pre_opener.id == "guidance_info"){
  202. mui.fire(pre_pre_opener.opener(), "update");
  203. pre_pre_opener.opener().show();
  204. mui.later(function(){
  205. pre_pre_opener.close('none');
  206. opener.close('none');
  207. pre_opener.close('none');
  208. self.close('none');
  209. }, 300);
  210. }else{
  211. mui.fire(pre_pre_opener, "update");
  212. pre_pre_opener.show();
  213. mui.later(function(){
  214. opener.close('none');
  215. pre_opener.close('none');
  216. self.close('none');
  217. }, 300);
  218. }
  219. }
  220. }else{
  221. mui.toast(res.msg)
  222. }
  223. plus.nativeUI.closeWaiting();
  224. }, 'POST', '', true);
  225. },
  226. cancelValue: "不了,谢谢",
  227. cancel: function(){}
  228. }).showModal();
  229. });
  230. $("#groupList").on('tap', ".group-item", function(){
  231. var $el = $(this),
  232. code = $.trim($el.attr("data-group")),
  233. amount = parseInt($el.attr("data-amount")),
  234. isOpen = $el.hasClass("current"),
  235. $groupInfo = $el.find('.group-info'),
  236. $siblings = $el.siblings();
  237. if(isOpen) {
  238. $el.removeClass("current");
  239. $el.find(".ui-arrow").removeClass("ui-arrow-t");
  240. $el.find(".ui-arrow").addClass("ui-arrow-b");
  241. $groupInfo.hide();
  242. }else{
  243. var $opened = $(".group-item.current");
  244. $el.addClass("current");
  245. $el.find(".ui-arrow").removeClass("ui-arrow-b");
  246. $el.find(".ui-arrow").addClass("ui-arrow-t");
  247. if($opened.length > 0){
  248. $opened.removeClass('current').find(".group-info").hide();
  249. $opened.find(".ui-arrow").removeClass("ui-arrow-t");
  250. $opened.find(".ui-arrow").addClass("ui-arrow-b");
  251. }
  252. if(amount > 0){
  253. $groupInfo.show();
  254. var liLen = $el.find('ul.n-list li').length;
  255. if(liLen == 0){
  256. initPatientListByGroup(code, true);
  257. }
  258. }
  259. }
  260. });
  261. $("#groupList").on('tap', ".load-more", function(e){
  262. e.stopPropagation();
  263. var $this = $(this),
  264. code = $this.attr("data-group");
  265. // mui('.mui-scroll-wrapper').refresh();
  266. initPatientListByGroup(code, false);
  267. });
  268. $searchbarInput.on('tap',function() {
  269. openWebview('guidance_searchhuanzhe.html',{
  270. content: content,
  271. modelCode: modelCode,
  272. images: images
  273. });
  274. // mui.openWindow({
  275. // id: "searchhuanzhe2",
  276. // url: "../../huanzhe/html/searchhuanzhe.html?isIndex=true",
  277. // extras: {}
  278. // })
  279. });
  280. $(".header-link").on('click', function(){
  281. openWebview("../../huanzhe/html/biaoqianguanli.html",{
  282. teamCode: docInfo.adminTeamCode
  283. });
  284. })
  285. /*刷新事件*/
  286. window.addEventListener("refresh", function group(e) {
  287. getGroupData();
  288. });
  289. };
  290. // 页面业务处理流程开始
  291. new Promise(function(resolve, reject) {
  292. // TODO 临时放开
  293. //resolve(true);
  294. mui.plusReady(function() {
  295. // plus已经准备好,可以往下执行
  296. resolve(true);
  297. });
  298. }).then(function() {
  299. // 获取基础环境信息
  300. return getBaseEnvPromise().then(function(env) {
  301. baseEnv = env;
  302. }).then(function() {
  303. // 获取登录医生信息
  304. var self = plus.webview.currentWebview();
  305. content =self.content;
  306. modelCode =self.modelCode;
  307. images =self.images;
  308. console.log(content)
  309. console.log(modelCode)
  310. console.log(images)
  311. baseInfo = getBaseInfoPromise();
  312. initScroller();
  313. // searchByPaging(true);
  314. getGroupData();
  315. // 绑定页面事件
  316. bindEvents();
  317. if(baseEnv.webview.origin){//“随访”功能,需要返回按钮
  318. $(".mui-action-back").show();
  319. }
  320. })
  321. }).catch(function(e) {
  322. plus.nativeUI.closeWaiting();
  323. console && console.error(e);
  324. });
  325. function setAge(age) {
  326. if(age == 0) {
  327. return "<1";
  328. }
  329. if(age == -1)
  330. return "未知";
  331. return age;
  332. }
  333. template.helper("setAge", setAge);
  334. function setSex(s) {
  335. if(s == 1) {
  336. return "男";
  337. } else if(s == 2) {
  338. return "女";
  339. }
  340. }
  341. template.helper("setSex", setSex);
  342. template.helper("getPhoto", function(str){
  343. return getImgUrl(str);
  344. })