resident-analysis-filter.js 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. (function(){
  2. Vue.component('resident-analysis-filter',{
  3. template: '<div :style="{height: height}" style="overflow: auto;margin-bottom: 50px;overflow-y: scroll;">\
  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" v-html="filterHtml"></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','yearHtml','filterHtml'],
  21. data: function(){
  22. return {
  23. selectLevel:"",
  24. resultCode:"",
  25. roleLevel:"",
  26. height: window.innerHeight * 0.6 + 'px'
  27. }
  28. },
  29. methods: {
  30. formatYearData: function () {
  31. //显示年份最低是2016年
  32. var now = new Date(),
  33. year = now.getFullYear();
  34. var yearHtml = "";
  35. // if(now.getMonth() >= 6){
  36. // yearHtml += '<div class="c-33 mt20 active" style="margin-left:0;margin-right:3%;" data-val="'+year+'"><a>'+year+"</a></div>";
  37. // }
  38. for(i=year; i>=2016; i--){
  39. if(i == year){
  40. yearHtml += '<div class="c-33 mt20 active" style="margin-left:0;margin-right:3%;" data-val="'+i+'"><a>'+i+"</a></div>";
  41. }else{
  42. yearHtml += '<div class="c-33 mt20" style="margin-left:0;margin-right:3%;" data-val="'+i+'"><a>'+i+"</a></div>";
  43. }
  44. }
  45. this.yearHtml = yearHtml;
  46. },
  47. requestData:function(){
  48. var vm = this,
  49. reqPromise = [],
  50. 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. reqPromise.push(httpRequest.get(reqUrl, {data: {}}));
  59. Promise.all(reqPromise).then(function(datas) {
  60. if(datas[0].status==200){
  61. vm.pingData(datas[0].data || [])
  62. }
  63. });
  64. },
  65. yearClick:function(){
  66. $(event.target.parentNode).addClass('active').siblings().removeClass('active')
  67. },
  68. divBtnClick:function(){
  69. var vm = this;
  70. if(event.target.nodeName === 'A') {
  71. vm.curCode = $(event.target.parentNode).attr("data-id");
  72. var item = $(event.target.parentNode.parentNode.parentNode);
  73. var dataLevel = item.attr("data-level");
  74. if(dataLevel == 4) {
  75. $(".div-content .div-item[data-level='4'] .div-btn").removeClass("active");
  76. item.next().remove();
  77. item.next().remove();
  78. vm.curLevel = 4;
  79. }
  80. if(dataLevel == 3) {
  81. $(".div-content .div-item[data-level='3'] .div-btn").removeClass("active");
  82. item.next().remove();
  83. vm.curLevel = 3;
  84. }
  85. if(dataLevel == 2) {
  86. $(".div-content .div-item[data-level='2'] .div-btn").removeClass("active");
  87. vm.curLevel = 2;
  88. }
  89. $(event.target.parentNode).addClass("active");
  90. if(vm.curCode != "" && dataLevel != 2) {
  91. vm.resultCode = vm.curCode;
  92. } else {
  93. vm.resultCode = vm.curCode;
  94. }
  95. if(vm.curCode) {
  96. vm.curName = $(event.target.parentNode).find("a").html();
  97. } else {
  98. vm.curName = item.find(".div-title").html();
  99. }
  100. vm.selectLevel = vm.curCode ? dataLevel - 1 : dataLevel;
  101. if(dataLevel == 2) {
  102. return false;
  103. }
  104. vm.curLevel--;
  105. if(vm.curCode) {
  106. vm.requestData();
  107. }
  108. }
  109. },
  110. resetClick:function(){
  111. var vm = this;
  112. vm.resultCode = "";
  113. vm.selectLevel = vm.roleLevel;
  114. var userRole = JSON.parse(window.sessionStorage.getItem("selectedRole"));
  115. vm.curName = vm.selectLevel==4?userRole.name.substring(0,3):userRole.name;
  116. vm.curCode = userRole.code;
  117. $("#signYear").find(".c-33").removeClass("active");
  118. $("#signYear").find(".c-33").eq(0).addClass("active");
  119. $(".div-content .div-item").find(".div-btn").removeClass("active");
  120. $(".div-content .div-item").eq(0).find(".div-btn").eq(0).addClass("active");
  121. $(".div-content .div-item").eq(1).remove();
  122. $(".div-content .div-item").eq(1).remove();
  123. },
  124. confirmClick:function(){
  125. var vm = this;
  126. //触发刷新
  127. var lastItem = $(".div-content .div-item .div-btn.active").last().find("a").html();
  128. if(lastItem=="全区"){
  129. if(vm.roleLevel==3){//区管理员
  130. var userRole = JSON.parse(window.sessionStorage.getItem("selectedRole"));
  131. vm.resultCode = vm.curCode || userRole.code;
  132. }else{
  133. vm.resultCode = $($(".div-content .div-item .div-btn.active").eq(0)).attr("data-id");
  134. vm.curName = $($(".div-content .div-item .div-btn.active").eq(0)).find("a").text();
  135. }
  136. vm.selectLevel = 3;
  137. }
  138. if(lastItem=="全社区"){
  139. if($(".div-content .div-item .div-btn.active").length==3){
  140. vm.resultCode = $($(".div-content .div-item .div-btn.active").eq(1)).attr("data-id");
  141. vm.curName = $($(".div-content .div-item .div-btn.active").eq(1)).find("a").text();
  142. }else{
  143. vm.resultCode = $($(".div-content .div-item .div-btn.active").eq(0)).attr("data-id");
  144. vm.curName = $($(".div-content .div-item .div-btn.active").eq(0)).find("a").text();
  145. }
  146. vm.selectLevel = 2;
  147. }
  148. this.$emit('vuedals:close', {
  149. areaCode: vm.resultCode,
  150. name: vm.curName,
  151. level: vm.selectLevel,
  152. year: $("#signYear .c-33.active").attr("data-val"),
  153. filterHtml:$(".div-content").html(),
  154. yearHtml:$("#signYear").html()
  155. });
  156. // console.log("area:"+vm.resultCode)
  157. // console.log("name:"+vm.curName)
  158. // console.log("level:"+vm.selectLevel)
  159. // console.log("year:"+$("#signYear .c-33.active").attr("data-val"))
  160. },
  161. pingData:function(list){
  162. var vm = this;
  163. var resultData = "";
  164. var activeClass = "";
  165. if(vm.curLevel == 4){//市管
  166. list.unshift({"code":"","name":"厦门全市"});
  167. vm.curName = vm.curName.substring(0,3);
  168. }else if(vm.curLevel == 3){//区管
  169. list.unshift({"code":"","name":"全区"});
  170. }else{//社区管
  171. list.unshift({"id":"","name":"全社区"});
  172. }
  173. if(list.length>0){
  174. var labelName = '<div class="div-item" data-level="'+vm.curLevel+'">'+
  175. '<div class="div-title">'+vm.curName+'</div>';
  176. var xzResult = [];//每三条分成一组
  177. var xzContent = '';
  178. for(var i=0,len=list.length;i<len;i+=3){//形状列表切割
  179. xzResult.push(list.slice(i,i+3));
  180. }
  181. for(var x in xzResult){
  182. var item = xzResult[x];
  183. if(x==0){
  184. activeClass = "active";
  185. }else{
  186. activeClass = "";
  187. }
  188. if(item.length==1){//只有一条数据
  189. var id = item[0].code;
  190. if(vm.curLevel=="2") {
  191. id = item[0].id;
  192. }
  193. var name = vm.curLevel==3 && id1?item[0].name.substring(3,item[0].name.length):item[0].name;
  194. xzContent+='<div class="mt20 div-group-btn c-row ml40">'+
  195. '<div class="div-btn c-33 '+activeClass+'" data-id="'+id+'" @click="">'+
  196. '<a href="#" class="f-fs14">'+name+'</a>'+
  197. '</div>'+
  198. '</div>';
  199. }
  200. if(item.length==2){
  201. var id1 = item[0].code;
  202. var id2 = item[1].code;
  203. if(vm.curLevel=="2") {
  204. id1 = item[0].id;
  205. id2 = item[1].id;
  206. }
  207. var name1 = vm.curLevel==3 && id1?item[0].name.substring(3,item[0].name.length):item[0].name;
  208. var name2 = vm.curLevel==3 && id2?item[1].name.substring(3,item[1].name.length):item[1].name;
  209. xzContent+= '<div class="mt20 div-group-btn c-row ml40">'+
  210. '<div class="div-btn c-33 '+activeClass+'" data-id="'+id1+'">'+
  211. '<a href="#" class="f-fs14">'+name1+'</a>'+
  212. '</div>'+
  213. '<div class="div-btn c-33 " data-id="'+id2+'" data-level="'+item[1].level+'">'+
  214. '<a href="#" class="f-fs14">'+name2+'</a>'+
  215. '</div>'+
  216. '</div>';
  217. }
  218. if(item.length==3){
  219. var id1 = item[0].code;
  220. var id2 = item[1].code;
  221. var id3 = item[2].code;
  222. if(vm.curLevel=="2") {
  223. id1 = vm.curCode;
  224. id2 = item[1].id;
  225. id3 = item[2].id;
  226. }
  227. var name1 = vm.curLevel==3 && id1?item[0].name.substring(3,item[0].name.length):item[0].name;
  228. var name2 = vm.curLevel==3 && id2?item[1].name.substring(3,item[1].name.length):item[1].name;
  229. var name3 = vm.curLevel==3 && id3?item[2].name.substring(3,item[2].name.length):item[2].name;
  230. xzContent+='<div class="mt20 div-group-btn c-row ml40">'+
  231. '<div class="div-btn c-33 '+activeClass+'" data-id="'+id1+'">'+
  232. '<a href="#" class="f-fs14">'+name1+'</a>'+
  233. '</div>'+
  234. '<div class="div-btn c-33 " data-id="'+id2+'">'+
  235. '<a href="#" class="f-fs14">'+name2+'</a>'+
  236. '</div>'+
  237. '<div class="div-btn c-33 " data-id="'+id3+'">'+
  238. '<a href="#" class="f-fs14">'+name3+'</a>'+
  239. '</div>'+
  240. '</div>';
  241. }
  242. }
  243. resultData += labelName+xzContent+'</div>';
  244. }
  245. $(".div-content").append(resultData);
  246. }
  247. },
  248. mounted: function(){
  249. this.roleLevel = this.curLevel;
  250. this.selectLevel = this.curLevel;
  251. this.resultCode = this.curCode;
  252. if(!(this.filterHtml && this.yearHtml)){
  253. this.formatYearData();
  254. this.requestData();
  255. }
  256. }
  257. });
  258. })()