resident-analysis-filter.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. (function(){
  2. Vue.component('resident-analysis-filter',{
  3. template: '<div style="height: 400px;overflow: auto;margin-bottom: 50px;">\
  4. <div class="mt10 ml10 filter-title">统计年份</div>\
  5. <div class="c-row mt20 ml40" id="signYear" v-html="yearHtml" @click="yearClick">\
  6. </div>\
  7. <div class="mt20 ml10 filter-title">统计维度</div>\
  8. <div class="div-content" @click="divBtnClick"></div>\
  9. <div id="footer">\
  10. <div class="c-row btn-wrap c-border-top fr">\
  11. <div class="div-foot-btn mr20" @click="resetClick">\
  12. <a href="#" class="c-666 f-fs16">重置</a>\
  13. </div>\
  14. <div class="div-foot-btn active" @click="confirmClick">\
  15. <a href="#" class="c-666 f-fs16">确定</a>\
  16. </div>\
  17. </div>\
  18. </div>\
  19. </div>',
  20. props:['curLevel','curCode','curName'],
  21. data: function(){
  22. return {
  23. yearHtml:"",
  24. contentHtml:"",
  25. selectLevel:"",
  26. resultCode:"",
  27. roleLevel:""
  28. }
  29. },
  30. methods: {
  31. formatYearData: function () {
  32. //显示年份最低是2016年
  33. var now = new Date(),
  34. year = now.getFullYear();
  35. var yearHtml = "";
  36. if(now.getMonth() >= 6){
  37. yearHtml += '<div class="c-33 active" data-val="'+year+'"><a>'+year+"</a></div>";
  38. }
  39. for(i=year-1; i>=2016; i--){
  40. if(i == (year-1) && now.getMonth() < 6){
  41. yearHtml += '<div class="c-33 active" data-val="'+i+'"><a>'+i+"</a></div>";
  42. }else{
  43. yearHtml += '<div class="c-33" data-val="'+i+'"><a>'+i+"</a></div>";
  44. }
  45. }
  46. this.yearHtml = yearHtml;
  47. },
  48. requestData:function(){
  49. var vm = this;
  50. var reqUrl = "";
  51. if(vm.curLevel == 4){//市管
  52. reqUrl = "/area/"+this.curCode+"/towns";
  53. }else if(vm.curLevel == 3){//区管
  54. reqUrl = "/hospitals/"+this.curCode+"/community_hospitals";
  55. }else{//社区管
  56. reqUrl = "/doctor/admin-teams/teams/"+this.curCode;
  57. }
  58. var reqUrl = [{
  59. url: reqUrl,
  60. reqType: 'get',
  61. data: {}
  62. }]
  63. httpRequest.getReqPromises(reqUrl).then(function(datas) {
  64. if(datas[0].status==200){
  65. vm.pingData(datas[0].data || [])
  66. }
  67. });
  68. },
  69. yearClick:function(){
  70. $(event.target.closest("div")).addClass('active').siblings().removeClass('active')
  71. },
  72. divBtnClick:function(){
  73. var vm = this;
  74. if(event.target.nodeName === 'A') {
  75. vm.curCode = $(event.target.closest("div")).attr("data-id");
  76. var item = $(event.target.closest(".div-item"));
  77. var dataLevel = item.attr("data-level");
  78. if(dataLevel == 4) {
  79. $(".div-content .div-item[data-level='4'] .div-btn").removeClass("active");
  80. item.next().remove();
  81. item.next().remove();
  82. vm.curLevel = 4;
  83. }
  84. if(dataLevel == 3) {
  85. $(".div-content .div-item[data-level='3'] .div-btn").removeClass("active");
  86. item.next().remove();
  87. vm.curLevel = 3;
  88. }
  89. if(dataLevel == 2) {
  90. $(".div-content .div-item[data-level='2'] .div-btn").removeClass("active");
  91. vm.curLevel = 2;
  92. }
  93. $(event.target.closest(".div-btn")).addClass("active");
  94. if(vm.curCode != "" && dataLevel != 2) {
  95. vm.resultCode = vm.curCode;
  96. } else {
  97. vm.resultCode = vm.curCode;
  98. }
  99. if(vm.curCode) {
  100. vm.curName = $(event.target.closest(".div-btn")).find("a").html();
  101. } else {
  102. vm.curName = item.find(".div-title").html();
  103. }
  104. vm.selectLevel = vm.curCode ? dataLevel - 1 : dataLevel;
  105. if(dataLevel == 2) {
  106. return false;
  107. }
  108. vm.curLevel--;
  109. if(vm.curCode) {
  110. vm.requestData();
  111. }
  112. }
  113. },
  114. resetClick:function(){
  115. var vm = this;
  116. vm.resultCode = "";
  117. vm.selectLevel = vm.roleLevel;
  118. var userRole = JSON.parse(window.localStorage.getItem("selectedRole"));
  119. vm.curName = vm.selectLevel==4?userRole.name.substring(0,3):userRole.name;
  120. $("#signYear").find(".c-33").removeClass("active");
  121. $("#signYear").find(".c-33").eq(0).addClass("active");
  122. $(".div-content .div-item").find(".div-btn").removeClass("active");
  123. $(".div-content .div-item").eq(0).find(".div-btn").eq(0).addClass("active");
  124. $(".div-content .div-item").eq(1).remove();
  125. $(".div-content .div-item").eq(1).remove();
  126. },
  127. confirmClick:function(){
  128. var vm = this;
  129. console.log("area:"+vm.resultCode)
  130. console.log("name:"+vm.curName)
  131. console.log("level:"+vm.selectLevel)
  132. console.log("year:"+$("#signYear .c-33.active").attr("data-val"))
  133. //触发刷新
  134. this.$emit('vuedals:close',{areaCode:vm.resultCode,name:vm.curName,level:vm.selectLevel,year:$("#signYear .c-33.active").attr("data-val")});
  135. },
  136. pingData:function(list){
  137. var vm = this;
  138. var resultData = "";
  139. var activeClass = "";
  140. if(vm.curLevel == 4){//市管
  141. list.unshift({"code":"","name":"厦门全市"});
  142. vm.curName = vm.curName.substring(0,3);
  143. }else if(vm.curLevel == 3){//区管
  144. list.unshift({"code":"","name":"全区"});
  145. }else{//社区管
  146. list.unshift({"id":"","name":"全社区"});
  147. }
  148. if(list.length>0){
  149. var labelName = '<div class="div-item" data-level="'+vm.curLevel+'">'+
  150. '<div class="div-title">'+vm.curName+'</div>';
  151. var xzResult = [];//每三条分成一组
  152. var xzContent = '';
  153. for(var i=0,len=list.length;i<len;i+=3){//形状列表切割
  154. xzResult.push(list.slice(i,i+3));
  155. }
  156. for(var x in xzResult){
  157. var item = xzResult[x];
  158. if(x==0){
  159. activeClass = "active";
  160. }else{
  161. activeClass = "";
  162. }
  163. if(item.length==1){//只有一条数据
  164. var id = item[0].code;
  165. if(vm.curLevel=="2") {
  166. id = item[0].id;
  167. }
  168. var name = vm.curLevel==3 && id1?item[0].name.substring(3,item[0].name.length):item[0].name;
  169. xzContent+='<div class="mt20 div-group-btn c-row ml40">'+
  170. '<div class="div-btn c-33 '+activeClass+'" data-id="'+id+'" @click="">'+
  171. '<a href="#" class="f-fs14">'+name+'</a>'+
  172. '</div>'+
  173. '</div>';
  174. }
  175. if(item.length==2){
  176. var id1 = item[0].code;
  177. var id2 = item[1].code;
  178. if(vm.curLevel=="2") {
  179. id1 = item[0].id;
  180. id2 = item[1].id;
  181. }
  182. var name1 = vm.curLevel==3 && id1?item[0].name.substring(3,item[0].name.length):item[0].name;
  183. var name2 = vm.curLevel==3 && id2?item[1].name.substring(3,item[1].name.length):item[1].name;
  184. xzContent+= '<div class="mt20 div-group-btn c-row ml40">'+
  185. '<div class="div-btn c-33 '+activeClass+'" data-id="'+id1+'">'+
  186. '<a href="#" class="f-fs14">'+name1+'</a>'+
  187. '</div>'+
  188. '<div class="div-btn c-33 " data-id="'+id2+'" data-level="'+item[1].level+'">'+
  189. '<a href="#" class="f-fs14">'+name2+'</a>'+
  190. '</div>'+
  191. '</div>';
  192. }
  193. if(item.length==3){
  194. var id1 = item[0].code;
  195. var id2 = item[1].code;
  196. var id3 = item[2].code;
  197. if(vm.curLevel=="2") {
  198. id1 = vm.curCode;
  199. id2 = item[1].id;
  200. id3 = item[2].id;
  201. }
  202. var name1 = vm.curLevel==3 && id1?item[0].name.substring(3,item[0].name.length):item[0].name;
  203. var name2 = vm.curLevel==3 && id2?item[1].name.substring(3,item[1].name.length):item[1].name;
  204. var name3 = vm.curLevel==3 && id3?item[2].name.substring(3,item[2].name.length):item[2].name;
  205. xzContent+='<div class="mt20 div-group-btn c-row ml40">'+
  206. '<div class="div-btn c-33 '+activeClass+'" data-id="'+id1+'">'+
  207. '<a href="#" class="f-fs14">'+name1+'</a>'+
  208. '</div>'+
  209. '<div class="div-btn c-33 " data-id="'+id2+'">'+
  210. '<a href="#" class="f-fs14">'+name2+'</a>'+
  211. '</div>'+
  212. '<div class="div-btn c-33 " data-id="'+id3+'">'+
  213. '<a href="#" class="f-fs14">'+name3+'</a>'+
  214. '</div>'+
  215. '</div>';
  216. }
  217. }
  218. resultData += labelName+xzContent+'</div>';
  219. }
  220. $(".div-content").append(resultData);
  221. }
  222. },
  223. mounted: function(){
  224. this.roleLevel = this.curLevel;
  225. this.selectLevel = this.curLevel;
  226. this.resultCode = this.curCode;
  227. this.formatYearData();
  228. this.requestData();
  229. }
  230. });
  231. })()