resident-analysis-filter.js 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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 active" data-val="'+year+'"><a>'+year+"</a></div>";
  37. }
  38. for(i=year-1; i>=2016; i--){
  39. if(i == (year-1) && now.getMonth() < 6){
  40. yearHtml += '<div class="c-33 active" data-val="'+i+'"><a>'+i+"</a></div>";
  41. }else{
  42. yearHtml += '<div class="c-33" 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.closest("div")).addClass('active').siblings().removeClass('active')
  67. },
  68. divBtnClick:function(){
  69. var vm = this;
  70. if(event.target.nodeName === 'A') {
  71. vm.curCode = $(event.target.closest("div")).attr("data-id");
  72. var item = $(event.target.closest(".div-item"));
  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.closest(".div-btn")).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.closest(".div-btn")).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.localStorage.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.localStorage.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. }
  135. vm.selectLevel = 3;
  136. }
  137. if(lastItem=="全社区"){
  138. if($(".div-content .div-item .div-btn.active").length==3){
  139. vm.resultCode = $($(".div-content .div-item .div-btn.active").eq(1)).attr("data-id");
  140. vm.curName = $($(".div-content .div-item .div-btn.active").eq(1)).find("a").text();
  141. }else{
  142. vm.resultCode = $($(".div-content .div-item .div-btn.active").eq(0)).attr("data-id");
  143. }
  144. vm.selectLevel = 2;
  145. }
  146. this.$emit('vuedals:close', {
  147. areaCode: vm.resultCode,
  148. name: vm.curName,
  149. level: vm.selectLevel,
  150. year: $("#signYear .c-33.active").attr("data-val"),
  151. filterHtml:$(".div-content").html(),
  152. yearHtml:$("#signYear").html()
  153. });
  154. // console.log("area:"+vm.resultCode)
  155. // console.log("name:"+vm.curName)
  156. // console.log("level:"+vm.selectLevel)
  157. // console.log("year:"+$("#signYear .c-33.active").attr("data-val"))
  158. },
  159. pingData:function(list){
  160. var vm = this;
  161. var resultData = "";
  162. var activeClass = "";
  163. if(vm.curLevel == 4){//市管
  164. list.unshift({"code":"","name":"厦门全市"});
  165. vm.curName = vm.curName.substring(0,3);
  166. }else if(vm.curLevel == 3){//区管
  167. list.unshift({"code":"","name":"全区"});
  168. }else{//社区管
  169. list.unshift({"id":"","name":"全社区"});
  170. }
  171. if(list.length>0){
  172. var labelName = '<div class="div-item" data-level="'+vm.curLevel+'">'+
  173. '<div class="div-title">'+vm.curName+'</div>';
  174. var xzResult = [];//每三条分成一组
  175. var xzContent = '';
  176. for(var i=0,len=list.length;i<len;i+=3){//形状列表切割
  177. xzResult.push(list.slice(i,i+3));
  178. }
  179. for(var x in xzResult){
  180. var item = xzResult[x];
  181. if(x==0){
  182. activeClass = "active";
  183. }else{
  184. activeClass = "";
  185. }
  186. if(item.length==1){//只有一条数据
  187. var id = item[0].code;
  188. if(vm.curLevel=="2") {
  189. id = item[0].id;
  190. }
  191. var name = vm.curLevel==3 && id1?item[0].name.substring(3,item[0].name.length):item[0].name;
  192. xzContent+='<div class="mt20 div-group-btn c-row ml40">'+
  193. '<div class="div-btn c-33 '+activeClass+'" data-id="'+id+'" @click="">'+
  194. '<a href="#" class="f-fs14">'+name+'</a>'+
  195. '</div>'+
  196. '</div>';
  197. }
  198. if(item.length==2){
  199. var id1 = item[0].code;
  200. var id2 = item[1].code;
  201. if(vm.curLevel=="2") {
  202. id1 = item[0].id;
  203. id2 = item[1].id;
  204. }
  205. var name1 = vm.curLevel==3 && id1?item[0].name.substring(3,item[0].name.length):item[0].name;
  206. var name2 = vm.curLevel==3 && id2?item[1].name.substring(3,item[1].name.length):item[1].name;
  207. xzContent+= '<div class="mt20 div-group-btn c-row ml40">'+
  208. '<div class="div-btn c-33 '+activeClass+'" data-id="'+id1+'">'+
  209. '<a href="#" class="f-fs14">'+name1+'</a>'+
  210. '</div>'+
  211. '<div class="div-btn c-33 " data-id="'+id2+'" data-level="'+item[1].level+'">'+
  212. '<a href="#" class="f-fs14">'+name2+'</a>'+
  213. '</div>'+
  214. '</div>';
  215. }
  216. if(item.length==3){
  217. var id1 = item[0].code;
  218. var id2 = item[1].code;
  219. var id3 = item[2].code;
  220. if(vm.curLevel=="2") {
  221. id1 = vm.curCode;
  222. id2 = item[1].id;
  223. id3 = item[2].id;
  224. }
  225. var name1 = vm.curLevel==3 && id1?item[0].name.substring(3,item[0].name.length):item[0].name;
  226. var name2 = vm.curLevel==3 && id2?item[1].name.substring(3,item[1].name.length):item[1].name;
  227. var name3 = vm.curLevel==3 && id3?item[2].name.substring(3,item[2].name.length):item[2].name;
  228. xzContent+='<div class="mt20 div-group-btn c-row ml40">'+
  229. '<div class="div-btn c-33 '+activeClass+'" data-id="'+id1+'">'+
  230. '<a href="#" class="f-fs14">'+name1+'</a>'+
  231. '</div>'+
  232. '<div class="div-btn c-33 " data-id="'+id2+'">'+
  233. '<a href="#" class="f-fs14">'+name2+'</a>'+
  234. '</div>'+
  235. '<div class="div-btn c-33 " data-id="'+id3+'">'+
  236. '<a href="#" class="f-fs14">'+name3+'</a>'+
  237. '</div>'+
  238. '</div>';
  239. }
  240. }
  241. resultData += labelName+xzContent+'</div>';
  242. }
  243. $(".div-content").append(resultData);
  244. }
  245. },
  246. mounted: function(){
  247. this.roleLevel = this.curLevel;
  248. this.selectLevel = this.curLevel;
  249. this.resultCode = this.curCode;
  250. if(!(this.filterHtml && this.yearHtml)){
  251. this.formatYearData();
  252. this.requestData();
  253. }
  254. }
  255. });
  256. })()