guidance_list.js 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. mui.init();
  2. var scrollers = [],
  3. page = [1,0,1], //主要存储个人和系统的模板分页信息
  4. page1 = [], //存储团队模板中,各个团队对应的模板分页信息
  5. loaded = [],
  6. patient = null,
  7. docInfo = null,
  8. reference,
  9. pagesize = 20,
  10. pagesize2 = 10,
  11. selectedTab = 0; //默认选中第一个tab
  12. mui.plusReady(function(){
  13. var self = plus.webview.currentWebview();
  14. var opener = self.opener();
  15. if(opener.id == "mine.html"){
  16. reference = "mine";
  17. }
  18. patient = self.code;
  19. initScroller();
  20. getList(true);
  21. bindEvents();
  22. });
  23. function getList(isInit){
  24. if(isInit){
  25. page[selectedTab] = 1;
  26. }
  27. var url = "doctor/guidance_temp/list",
  28. params = {
  29. type: selectedTab == 0 ? 2 : 1, //模板类型 1:系统 2:自定义 为空:所有
  30. pageNo: page[selectedTab],
  31. pageSize: pagesize
  32. },
  33. filter = '';
  34. if(selectedTab == 0){
  35. filter = $("#item1 .search-input").val();
  36. }else{
  37. filter = $("#item3 .search-input").val();
  38. }
  39. params.filter = filter;
  40. plus.nativeUI.showWaiting();
  41. sendGet(url, params, null, function(res){
  42. if(res.status == 200){
  43. loaded[selectedTab] = true;
  44. var $controlPanel = $("#item"+(selectedTab + 1)),
  45. $ul = $controlPanel.find("ul"),
  46. $noResult = $controlPanel.find(".no-result");
  47. if(isInit){
  48. if(res.data.length == 0){
  49. $ul.hide();
  50. $noResult.show();
  51. }else{
  52. $ul.show();
  53. $noResult.hide();
  54. var html = template("guidance_tmp", {list: res.data});
  55. $ul.empty().append(html);
  56. }
  57. }else{
  58. var html = template("guidance_tmp", {list: res.data});
  59. $ul.append(html);
  60. }
  61. if(res.data.length < pagesize){
  62. scrollers[selectedTab].endPullupToRefresh(true);
  63. }else{
  64. scrollers[selectedTab].endPullupToRefresh(false);
  65. page[selectedTab] ++;
  66. }
  67. }else{
  68. mui.toast(res.msg);
  69. }
  70. plus.nativeUI.closeWaiting();
  71. }, true);
  72. }
  73. function getTeamInfo(){
  74. var url = 'doctor/team/guidance/getDoctorTeams',
  75. params = {
  76. filter: $("#item2 .search-input").val()
  77. }
  78. plus.nativeUI.showWaiting();
  79. sendGet(url, params, null, function(res){
  80. if(res.status == 200){
  81. var html = template('team-tmp', {list: res.teamList});
  82. $(".team-group").empty().append(html);
  83. page1 = [];
  84. if(res.teamList.length > 0){
  85. for(i=0; i<res.teamList.length; i++){
  86. page1.push(1);
  87. }
  88. //展开第一个团队的数据
  89. getTeamTemplate(res.teamList[0].teamId, 0, true);
  90. }
  91. }else{
  92. mui.toast(res.msg);
  93. }
  94. plus.nativeUI.closeWaiting();
  95. }, true);
  96. }
  97. function getTeamTemplate(teamId, index, isInit){
  98. var url = "doctor/team/guidance/getTeamGuidanceList",
  99. params = {
  100. teamId: teamId,
  101. pageNo: page1[index],
  102. pageSize: pagesize2,
  103. filter: $("#item2 .search-input").val()
  104. };
  105. plus.nativeUI.showWaiting();
  106. sendGet(url, params, null, function(res){
  107. if(res.status == 200){
  108. var list = res.templateList,
  109. $panel = $(".data-panel").eq(index);
  110. var html = template("team_guidance_tmp", {list: list});
  111. if(isInit){
  112. if(list.length == 0){
  113. $panel.hide();
  114. }else{
  115. $panel.show();
  116. $panel.find("ul").empty().append(html);
  117. }
  118. }else{
  119. $panel.find("ul").append(html);
  120. }
  121. if(list.length < pagesize2){
  122. $panel.find(".add-more").hide();
  123. }else{
  124. $panel.find(".add-more").show();
  125. page1[index] ++;
  126. }
  127. }else{
  128. mui.toast(res.msg);
  129. }
  130. plus.nativeUI.closeWaiting();
  131. }, true);
  132. }
  133. //搜索提交请求
  134. function searchModel(type){
  135. console.log(type);
  136. if(type == 1 || type == 3){
  137. getList(true);
  138. }else{
  139. getTeamInfo();
  140. }
  141. return false;
  142. }
  143. function bindEvents(){
  144. document.querySelector('.mui-slider').addEventListener('slide', function(event) {
  145. selectedTab = event.detail.slideNumber;
  146. if(selectedTab != 1 && loaded[selectedTab] == "false"){
  147. getList(true);
  148. loaded[selectedTab] = "true";
  149. }else if(selectedTab == 1 && loaded[selectedTab] == 'false'){
  150. getTeamInfo();
  151. loaded[selectedTab] = "true";
  152. }
  153. });
  154. //团队列表展开
  155. $("#item2").on('tap', ".team-info", function(){
  156. var $this = $(this),
  157. code = $this.attr("data-code"),
  158. index = $this.parent().index(),
  159. $dataPanel = $this.parent().find(".data-panel"),
  160. $arrow = $this.find(".fa");
  161. if($arrow.hasClass("fa-caret-down")){
  162. $arrow.removeClass("fa-caret-down");
  163. $arrow.addClass("fa-caret-up");
  164. if($dataPanel.find("li").length == 0){
  165. getTeamTemplate(code, index, true);
  166. }else{
  167. $dataPanel.show();
  168. }
  169. }else{
  170. $arrow.removeClass("fa-caret-up");
  171. $arrow.addClass("fa-caret-down");
  172. $dataPanel.hide();
  173. }
  174. });
  175. //加载更多
  176. $("#item2").on('tap', '.add-more', function(){
  177. var $this = $(this),
  178. $parent = $this.parent().parent(),
  179. index = $parent.index(),
  180. code = $parent.find(".team-info").attr("data-code");
  181. getTeamTemplate(code, index, false);
  182. });
  183. //新增按钮
  184. $(".add-icon").on("tap", function(){
  185. var $this = $(this),
  186. type = $this.attr("data-val");
  187. if(type == "gr"){
  188. openWebview('edit_guidance.html',{
  189. action: "add",
  190. reference: reference,
  191. patiCode: patient
  192. });
  193. }else if(type == "team"){
  194. mui.openWindow('../html/bianjituanduimuban.html', 'bianjituanduimuban', {
  195. extras: {
  196. reference: reference,
  197. action: 'add',
  198. patiCode: patient
  199. // tName: me.tName,
  200. // tId: me.tId,
  201. }
  202. });
  203. }
  204. });
  205. //查看文章详情
  206. $("#item1").on('tap', 'li', function(){
  207. var code = $(this).attr("data-code");
  208. openWebview("guidance_detail.html",{
  209. code: code,
  210. reference: reference,
  211. patiCode: patient
  212. });
  213. });
  214. $("#item2").on('tap', 'li', function(){
  215. var $this = $(this),
  216. code = $this.attr("data-code"),
  217. $grantParent = $this.parent().parent().parent(),
  218. $team = $grantParent.find(".team-info"),
  219. tId = $team.attr("data-code"),
  220. tName = $team.attr("data-name");
  221. mui.openWindow('../html/chakantuanduimuban.html', 'chakantuanduimuban', {
  222. extras: {
  223. reference: reference,
  224. action: 'add',
  225. code: code,
  226. tId: tId,
  227. tName: tName,
  228. is_sys: false,
  229. patiCode: patient
  230. }
  231. });
  232. });
  233. $("#item3").on('tap', 'li', function(){
  234. var code = $(this).attr("data-code");
  235. openWebview("guidance_detail.html", {
  236. code: code,
  237. reference: reference,
  238. patiCode: patient,
  239. is_sys: true
  240. });
  241. });
  242. //搜索功能
  243. $(".search-input").on('keydown', function(e){
  244. if (e.which === 13) {
  245. if(selectedTab == 0 || selectedTab == 2){
  246. getList(true);
  247. }else{
  248. getTeamInfo();
  249. }
  250. }
  251. });
  252. //设置页面监听
  253. window.addEventListener("refresh", function(e){
  254. if(selectedTab == 0 || selectedTab == 2){
  255. getList(true);
  256. }else{
  257. getTeamInfo();
  258. }
  259. })
  260. }
  261. function initScroller(){
  262. $.each(document.querySelectorAll('.mui-slider-group .mui-scroll-wrapper'), function(index, pullRefreshEl) {
  263. page.push(1);
  264. loaded.push("false");
  265. if(index == 1){
  266. var pullRefresh = mui(pullRefreshEl).pullRefresh({
  267. down:{
  268. callback: function(){
  269. var self = this;
  270. setTimeout(function(){
  271. getTeamInfo();
  272. self.endPulldownToRefresh();
  273. }, 300);
  274. }
  275. }
  276. });
  277. }else{
  278. var pullRefresh = mui(pullRefreshEl).pullRefresh({
  279. down:{
  280. callback: function(){
  281. var self = this;
  282. setTimeout(function(){
  283. getList(true);
  284. self.endPulldownToRefresh();
  285. }, 300);
  286. }
  287. },
  288. up: {
  289. callback: function(){
  290. var self = this;
  291. setTimeout(function(){
  292. getList(false);
  293. }, 300);
  294. }
  295. }
  296. });
  297. }
  298. scrollers.push(pullRefresh);
  299. })
  300. }