guidance_list.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  1. mui.init();
  2. var scrollers = [],
  3. page = [1,0,1], //主要存储个人和系统的模板分页信息
  4. page1 = [], //存储团队模板中,各个团队对应的模板分组信息
  5. page2 = [], //存储团队模板中,各个团队对应的模板分页信息
  6. loaded = [],
  7. patient = null,
  8. docInfo = null,
  9. reference,
  10. pagesize = 20,
  11. pagesize2 = 10,
  12. selectedTab = 0; //默认选中第一个tab
  13. teamID = null,
  14. searchteamId = '',
  15. searchIndex = '',
  16. obj='';
  17. mui.plusReady(function(){
  18. var self = plus.webview.currentWebview();
  19. var opener = self.opener();
  20. if(opener.id == "mine.html"){
  21. reference = "mine";
  22. }
  23. patient = self.code;
  24. signCode = self.sign;
  25. obj = init();
  26. juageAdd();
  27. initScroller();
  28. getList(true);
  29. bindEvents();
  30. });
  31. //获取登陆者信息
  32. function init(){
  33. //登陆相关信息
  34. var userAgent = JSON.parse(plus.storage.getItem('userAgent'));
  35. //获取团队信息
  36. var teamInfo = JSON.parse(plus.storage.getItem('teamInfo'));
  37. var doctorInfo = JSON.parse(plus.storage.getItem("docInfo"));
  38. return{
  39. userAgent:userAgent,
  40. teamInfo:teamInfo,
  41. doctorInfo:doctorInfo
  42. }
  43. }
  44. //判断是否显示是否是团队长是否添加模板
  45. function juageAdd(){
  46. var docinfo = obj.doctorInfo;
  47. if (docinfo.isLeader!=1) {
  48. $('#item2').find('.add-icon').hide();
  49. return
  50. }
  51. }
  52. function getList(isInit){
  53. if(isInit){
  54. page[selectedTab] = 1;
  55. }
  56. var url = "doctor/guidance_temp/list",
  57. params = {
  58. type: selectedTab == 0 ? 2 : 1, //模板类型 1:系统 2:自定义 为空:所有
  59. pageNo: page[selectedTab],
  60. pageSize: pagesize
  61. },
  62. filter = '';
  63. if(selectedTab == 0){
  64. filter = $("#item1 .search-input").val();
  65. }else{
  66. filter = $("#item3 .search-input").val();
  67. }
  68. params.filter = filter;
  69. plus.nativeUI.showWaiting();
  70. sendGet(url, params, null, function(res){
  71. if(res.status == 200){
  72. loaded[selectedTab] = true;
  73. var $controlPanel = $("#item"+(selectedTab + 1)),
  74. $ul = $controlPanel.find("ul"),
  75. $noResult = $controlPanel.find(".no-result");
  76. if(isInit){
  77. if(res.data.length == 0){
  78. $ul.hide();
  79. $noResult.show();
  80. }else{
  81. $ul.show();
  82. $noResult.hide();
  83. var html = template("guidance_tmp", {list: res.data});
  84. $ul.empty().append(html);
  85. }
  86. }else{
  87. var html = template("guidance_tmp", {list: res.data});
  88. $ul.append(html);
  89. }
  90. if(res.data.length < pagesize){
  91. scrollers[selectedTab].endPullupToRefresh(true);
  92. }else{
  93. scrollers[selectedTab].endPullupToRefresh(false);
  94. page[selectedTab] ++;
  95. }
  96. }else{
  97. mui.toast(res.msg);
  98. }
  99. plus.nativeUI.closeWaiting();
  100. }, true);
  101. }
  102. function getTeamInfo(){
  103. var url = 'doctor/team/guidance/getDoctorTeams',
  104. params = {
  105. filter: $("#item2 .search-input").val()
  106. }
  107. plus.nativeUI.showWaiting();
  108. sendGet(url, params, null, function(res){
  109. if(res.status == 200){
  110. var html = template('team-tmp', {list: res.teamList});
  111. $(".team-group").empty().append(html);
  112. page1 = [];
  113. if(res.teamList.length > 0){
  114. for(i=0; i<res.teamList.length; i++){
  115. page1.push(1);
  116. }
  117. //展开第一个团队分组的数据
  118. searchteamId = res.teamList[0].teamId;
  119. searchIndex = 0;
  120. getlableGroup(res.teamList[0].teamId, 0, true);
  121. }
  122. }else{
  123. mui.toast(res.msg);
  124. }
  125. plus.nativeUI.closeWaiting();
  126. }, true);
  127. }
  128. //通过查询团队标签签过滤条件获取团队健康指导模板列表
  129. function getTeamInfoBySearch(index){
  130. var url = '/doctor/team/guidance/getTeamGuidanceListByLabelWithFilter',
  131. params = {
  132. teamId:searchteamId,
  133. filter: $("#item2 .search-input").val()
  134. }
  135. plus.nativeUI.showWaiting();
  136. sendGet(url, params, null, function(res){
  137. var arr =[]; var f_obj = {}; var s_obj={}; var name = [];
  138. if(res.status == 200){
  139. var data = res.data
  140. for(k in data) {
  141. // var obj= {};
  142. // obj.name = k;
  143. f_obj ={
  144. name :k
  145. }
  146. name.push(f_obj);
  147. for(var i = 0;i<data[k].length;i++){
  148. var fObj = {}
  149. fObj = $.extend({},data[k][i]);
  150. arr.push(fObj);
  151. }
  152. console.log(arr);
  153. }
  154. var html = template('search-lableGroups-tmp', {list: name});
  155. var htmlson = template('search-lableGroups-son-tmp', {listson: arr});
  156. $(".Group").eq(index).empty().append(html);
  157. // $(".Group").eq(index).find('.data-panel').removeClass('c-hide');
  158. $(".Group").eq(index).find('.data-panel').find('ul').append(htmlson)
  159. // page1 = [];
  160. // if(res.teamList.length > 0){
  161. // for(i=0; i<res.teamList.length; i++){
  162. // page1.push(1);
  163. // }
  164. // //展开第一个团队分组的数据
  165. // getlableGroup(res.teamList[0].teamId, 0, true)
  166. // }
  167. }else{
  168. mui.toast(res.msg);
  169. }
  170. plus.nativeUI.closeWaiting();
  171. }, true);
  172. }
  173. function getlableGroup(teamId, index, isInit){
  174. var url = "/doctor/guidance_temp/lable/findAllListByPage",
  175. params = {
  176. teamId: teamId,
  177. pageNo: page1[index],
  178. pageSize: pagesize2,
  179. };
  180. plus.nativeUI.showWaiting();
  181. sendGet(url, params, null, function(res){
  182. if(res.status == 200){
  183. var list = res.data,
  184. $panel = $('.team-info').eq(index).parent().find('.data-panel');
  185. var html = template("lableGroups-tmp", {list: list});
  186. page2 = [];
  187. if(res.data.length > 0){
  188. for(i=0; i<res.data.length; i++){
  189. page2.push(1);
  190. }
  191. }
  192. if(isInit){
  193. if(list.length == 0){
  194. $panel.hide();
  195. }else{
  196. $panel.show();
  197. $panel.find("ul").empty().append(html);
  198. }
  199. }else{
  200. $panel.find("ul").append(html);
  201. }
  202. if(list.length < pagesize2){
  203. $panel.find(".f-add-more").hide();
  204. }else{
  205. $panel.find(".f-add-more").show();
  206. page1[index] ++;
  207. }
  208. }else{
  209. mui.toast(res.msg);
  210. }
  211. plus.nativeUI.closeWaiting();
  212. }, true);
  213. }
  214. // 根据单个团队标签获取团队健康指导模板列表
  215. function getTeamTemplateList(teamId,index,code,elm,isInit){
  216. var url = "/doctor/team/guidance/getTeamGuidanceLabelList",
  217. params = {
  218. teamId: teamId,
  219. pageNo: page2[index],
  220. pageSize: pagesize2,
  221. labelCode:code
  222. };
  223. plus.nativeUI.showWaiting();
  224. sendGet(url, params, null, function(res){
  225. if(res.status == 200){
  226. var list = res.data,
  227. $panel = elm.parent().find(".data-panel");
  228. var html = template("team_guidance_tmp", {list: list});
  229. if(isInit){
  230. if(list.length == 0){
  231. $panel.hide();
  232. }else{
  233. $('.Group').find(".data-panel").hide();
  234. $('.Group').find(".fa").removeClass('fa-caret-up');
  235. $('.Group').find(".fa").addClass('fa-caret-right');
  236. elm.find('.fa').removeClass('fa-caret-right');
  237. elm.find('.fa').addClass('fa-caret-up');
  238. $panel.show();
  239. $panel.find("ul").empty().append(html);
  240. }
  241. }else{
  242. $panel.find("ul").append(html);
  243. }
  244. if(list.length < pagesize2){
  245. $panel.find(".s-add-more").hide();
  246. }else{
  247. $panel.find(".s-add-more").show();
  248. page2[index] ++;
  249. }
  250. }else{
  251. mui.toast(res.msg);
  252. }
  253. plus.nativeUI.closeWaiting();
  254. }, true);
  255. }
  256. //搜索提交请求
  257. function searchModel(type){
  258. if(type == 1 || type == 3){
  259. getList(true);
  260. }else{
  261. getTeamInfoBySearch(searchIndex);
  262. }
  263. return false;
  264. }
  265. function bindEvents(){
  266. document.querySelector('.mui-slider').addEventListener('slide', function(event) {
  267. selectedTab = event.detail.slideNumber;
  268. if(selectedTab != 1 && loaded[selectedTab] == "false"){
  269. getList(true);
  270. loaded[selectedTab] = "true";
  271. }else if(selectedTab == 1 && loaded[selectedTab] == 'false'){
  272. getTeamInfo();
  273. loaded[selectedTab] = "true";
  274. }
  275. });
  276. //团队列表展开
  277. $("#item2").on('tap', ".team-info", function(){
  278. var $this = $(this),
  279. code = $this.attr("data-code"),
  280. index = $this.parent().index(),
  281. $dataPanel = $this.parent().find(".data-panel"),
  282. $arrow = $this.find(".fa");
  283. searchteamId = code;
  284. searchIndex= index;
  285. if($arrow.hasClass("fa-caret-down")){
  286. $arrow.removeClass("fa-caret-down");
  287. $arrow.addClass("fa-caret-up");
  288. if($dataPanel.find("li").length == 0){
  289. getlableGroup(code, index, true);
  290. }else{
  291. $dataPanel.show();
  292. }
  293. }else{
  294. $arrow.removeClass("fa-caret-up");
  295. $arrow.addClass("fa-caret-down");
  296. $dataPanel.hide();
  297. }
  298. });
  299. //加载更多标签分组
  300. $("#item2").on('tap', '.f-add-more ', function(){
  301. var $this = $(this),
  302. $parent = $this.parent().parent(),
  303. index = $parent.index(),
  304. code = $parent.find(".team-info").attr("data-code");
  305. getlableGroup(code, index, false);
  306. });
  307. //加载更多标签 分组对应单个团队模板列表
  308. $("#item2").on('tap','.Group .s-add-more', function(){
  309. var $this = $(this),
  310. $parent = $this.parent().parent(),
  311. index = $parent.index(),
  312. code = $parent.find(".lable-info").attr("data-code");
  313. teamId = $parent.parent().parent().parent().find(".team-info").attr("data-code");
  314. getTeamTemplateList(teamId,index,code,$parent,false);
  315. });
  316. // 根据单个团队标签获取团队健康指导模板列表
  317. $("#item2").on('tap', '.Group .lable-info', function(event){
  318. event.stopPropagation();
  319. var $this = $(this),
  320. code = $this.attr('data-code'),
  321. teamId =$this.parent().parent().parent().parent().find('.team-info').attr('data-code');
  322. index = $this.parent().index(),
  323. $dataPanel = $this.parent().find(".data-panel"),
  324. $arrow = $this.find(".fa");
  325. console.log(teamId);
  326. if($arrow.hasClass("fa-caret-right")){
  327. $arrow.removeClass("fa-caret-right");
  328. $arrow.addClass("fa-caret-up");
  329. if($dataPanel.find("li").length == 0){
  330. getTeamTemplateList(teamId,index,code,$this,true);
  331. }else{
  332. $dataPanel.show();
  333. }
  334. }else{
  335. $arrow.removeClass("fa-caret-up");
  336. $arrow.addClass("fa-caret-right");
  337. $dataPanel.hide();
  338. }
  339. });
  340. //新增按钮
  341. $(".add-icon").on("tap", function(){
  342. var $this = $(this),
  343. type = $this.attr("data-val");
  344. if(type == "gr"){
  345. openWebview('edit_guidance.html',{
  346. action: "add",
  347. reference: reference,
  348. patiCode: patient,
  349. sign:signCode
  350. });
  351. }else if(type == "team"){
  352. mui.openWindow('../html/bianjituanduimuban.html', 'bianjituanduimuban', {
  353. extras: {
  354. reference: reference,
  355. action: 'add',
  356. patiCode: patient,
  357. sign:signCode
  358. // tName: me.tName,
  359. // tId: me.tId,
  360. }
  361. });
  362. }
  363. });
  364. //查看文章详情
  365. $("#item1").on('tap', 'li', function(){
  366. var code = $(this).attr("data-code");
  367. openWebview("guidance_detail.html",{
  368. code: code,
  369. reference: reference,
  370. patiCode: patient,
  371. sign:signCode
  372. });
  373. });
  374. $("#item2").on('tap', 'li', function(){
  375. var $this = $(this),
  376. code = $this.attr("data-code"),
  377. $grantParent = $this.parent().parent().parent().parent().parent().parent();
  378. $team = $grantParent.find(".team-info");
  379. tId = $team.attr("data-code"),
  380. tName = $team.attr("data-name");
  381. mui.openWindow('../html/chakantuanduimuban.html', 'chakantuanduimuban', {
  382. extras: {
  383. reference: reference,
  384. action: 'add',
  385. code: code,
  386. tId: tId,
  387. tName: tName,
  388. is_sys: false,
  389. patiCode: patient,
  390. sign:signCode
  391. }
  392. });
  393. });
  394. $("#item3").on('tap', 'li', function(){
  395. var code = $(this).attr("data-code");
  396. openWebview("guidance_detail.html", {
  397. code: code,
  398. reference: reference,
  399. patiCode: patient,
  400. is_sys: true,
  401. sign:signCode
  402. });
  403. });
  404. //搜索功能
  405. $(".search-input").on('keydown', function(e){
  406. if (e.which === 13) {
  407. if(selectedTab == 0 || selectedTab == 2){
  408. getList(true);
  409. }else{
  410. getTeamInfoBySearch(searchIndex);
  411. }
  412. }
  413. });
  414. //设置页面监听
  415. window.addEventListener("refresh", function(e){
  416. if(selectedTab == 0 || selectedTab == 2){
  417. getList(true);
  418. }else{
  419. getTeamInfo();
  420. }
  421. })
  422. }
  423. function initScroller(){
  424. $.each(document.querySelectorAll('.mui-slider-group .mui-scroll-wrapper'), function(index, pullRefreshEl) {
  425. page.push(1);
  426. loaded.push("false");
  427. if(index == 1){
  428. var pullRefresh = mui(pullRefreshEl).pullRefresh({
  429. down:{
  430. callback: function(){
  431. var self = this;
  432. setTimeout(function(){
  433. getTeamInfo();
  434. self.endPulldownToRefresh();
  435. }, 300);
  436. }
  437. }
  438. });
  439. }else{
  440. var pullRefresh = mui(pullRefreshEl).pullRefresh({
  441. down:{
  442. callback: function(){
  443. var self = this;
  444. setTimeout(function(){
  445. getList(true);
  446. self.endPulldownToRefresh();
  447. }, 300);
  448. }
  449. },
  450. up: {
  451. callback: function(){
  452. var self = this;
  453. setTimeout(function(){
  454. getList(false);
  455. }, 300);
  456. }
  457. }
  458. });
  459. }
  460. scrollers.push(pullRefresh);
  461. })
  462. }