123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266 |
- (function(){
- Vue.component('resident-analysis-filter',{
- template: '<div :style="{height: height}" style="overflow: auto;margin-bottom: 50px;overflow-y: scroll;">\
- <div class="mt10 ml10 filter-title">统计年份</div>\
- <div class="c-row mt20 ml40" id="signYear" v-html="yearHtml" @click="yearClick">\
- </div>\
- <div class="mt20 ml10 filter-title">统计维度</div>\
- <div class="div-content" @click="divBtnClick" v-html="filterHtml"></div>\
- <div id="footer">\
- <div class="c-row btn-wrap c-border-top fr">\
- <div class="div-foot-btn mr20" @click="resetClick">\
- <a href="#" class="c-666 f-fs16">重置</a>\
- </div>\
- <div class="div-foot-btn active" @click="confirmClick">\
- <a href="#" class="c-666 f-fs16">确定</a>\
- </div>\
- </div>\
- </div>\
- </div>',
- props:['curLevel','curCode','curName','yearHtml','filterHtml'],
- data: function(){
- return {
- selectLevel:"",
- resultCode:"",
- roleLevel:"",
- height: window.innerHeight * 0.6 + 'px'
- }
- },
- methods: {
- formatYearData: function () {
- //显示年份最低是2016年
- var now = new Date(),
- year = now.getFullYear();
- var yearHtml = "";
- if(now.getMonth() >= 6){
- yearHtml += '<div class="c-33 mt20 active" style="margin-left:0;margin-right:3%;" data-val="'+year+'"><a>'+year+"</a></div>";
- }
- for(i=year-1; i>=2016; i--){
- if(i == (year-1) && now.getMonth() < 6){
- yearHtml += '<div class="c-33 mt20 active" style="margin-left:0;margin-right:3%;" data-val="'+i+'"><a>'+i+"</a></div>";
- }else{
- yearHtml += '<div class="c-33 mt20" style="margin-left:0;margin-right:3%;" data-val="'+i+'"><a>'+i+"</a></div>";
- }
- }
- this.yearHtml = yearHtml;
- },
- requestData:function(){
- var vm = this,
- reqPromise = [],
- reqUrl = "";
- if(vm.curLevel == 4){//市管
- reqUrl = "/area/"+this.curCode+"/towns";
- }else if(vm.curLevel == 3){//区管
- reqUrl = "/hospitals/"+this.curCode+"/community_hospitals";
- }else{//社区管
- reqUrl = "/doctor/admin-teams/teams/"+this.curCode;
- }
-
- reqPromise.push(httpRequest.get(reqUrl, {data: {}}));
- Promise.all(reqPromise).then(function(datas) {
- if(datas[0].status==200){
- vm.pingData(datas[0].data || [])
- }
- });
- },
- yearClick:function(){
- $(event.target.parentNode).addClass('active').siblings().removeClass('active')
- },
- divBtnClick:function(){
- var vm = this;
- if(event.target.nodeName === 'A') {
- vm.curCode = $(event.target.parentNode).attr("data-id");
- var item = $(event.target.parentNode.parentNode.parentNode);
- var dataLevel = item.attr("data-level");
- if(dataLevel == 4) {
- $(".div-content .div-item[data-level='4'] .div-btn").removeClass("active");
- item.next().remove();
- item.next().remove();
- vm.curLevel = 4;
- }
- if(dataLevel == 3) {
- $(".div-content .div-item[data-level='3'] .div-btn").removeClass("active");
- item.next().remove();
- vm.curLevel = 3;
- }
- if(dataLevel == 2) {
- $(".div-content .div-item[data-level='2'] .div-btn").removeClass("active");
- vm.curLevel = 2;
- }
- $(event.target.parentNode).addClass("active");
- if(vm.curCode != "" && dataLevel != 2) {
- vm.resultCode = vm.curCode;
- } else {
- vm.resultCode = vm.curCode;
- }
- if(vm.curCode) {
- vm.curName = $(event.target.parentNode).find("a").html();
- } else {
- vm.curName = item.find(".div-title").html();
- }
-
- vm.selectLevel = vm.curCode ? dataLevel - 1 : dataLevel;
- if(dataLevel == 2) {
- return false;
- }
-
- vm.curLevel--;
- if(vm.curCode) {
- vm.requestData();
- }
- }
- },
- resetClick:function(){
- var vm = this;
- vm.resultCode = "";
- vm.selectLevel = vm.roleLevel;
- var userRole = JSON.parse(window.sessionStorage.getItem("selectedRole"));
- vm.curName = vm.selectLevel==4?userRole.name.substring(0,3):userRole.name;
- vm.curCode = userRole.code;
- $("#signYear").find(".c-33").removeClass("active");
- $("#signYear").find(".c-33").eq(0).addClass("active");
- $(".div-content .div-item").find(".div-btn").removeClass("active");
- $(".div-content .div-item").eq(0).find(".div-btn").eq(0).addClass("active");
- $(".div-content .div-item").eq(1).remove();
- $(".div-content .div-item").eq(1).remove();
- },
- confirmClick:function(){
- var vm = this;
- //触发刷新
- var lastItem = $(".div-content .div-item .div-btn.active").last().find("a").html();
- if(lastItem=="全区"){
- if(vm.roleLevel==3){//区管理员
- var userRole = JSON.parse(window.sessionStorage.getItem("selectedRole"));
- vm.resultCode = vm.curCode || userRole.code;
- }else{
- vm.resultCode = $($(".div-content .div-item .div-btn.active").eq(0)).attr("data-id");
- vm.curName = $($(".div-content .div-item .div-btn.active").eq(0)).find("a").text();
- }
- vm.selectLevel = 3;
- }
- if(lastItem=="全社区"){
- if($(".div-content .div-item .div-btn.active").length==3){
- vm.resultCode = $($(".div-content .div-item .div-btn.active").eq(1)).attr("data-id");
- vm.curName = $($(".div-content .div-item .div-btn.active").eq(1)).find("a").text();
- }else{
- vm.resultCode = $($(".div-content .div-item .div-btn.active").eq(0)).attr("data-id");
- vm.curName = $($(".div-content .div-item .div-btn.active").eq(0)).find("a").text();
- }
- vm.selectLevel = 2;
- }
- this.$emit('vuedals:close', {
- areaCode: vm.resultCode,
- name: vm.curName,
- level: vm.selectLevel,
- year: $("#signYear .c-33.active").attr("data-val"),
- filterHtml:$(".div-content").html(),
- yearHtml:$("#signYear").html()
- });
- // console.log("area:"+vm.resultCode)
- // console.log("name:"+vm.curName)
- // console.log("level:"+vm.selectLevel)
- // console.log("year:"+$("#signYear .c-33.active").attr("data-val"))
- },
- pingData:function(list){
- var vm = this;
- var resultData = "";
- var activeClass = "";
- if(vm.curLevel == 4){//市管
- list.unshift({"code":"","name":"厦门全市"});
- vm.curName = vm.curName.substring(0,3);
- }else if(vm.curLevel == 3){//区管
- list.unshift({"code":"","name":"全区"});
- }else{//社区管
- list.unshift({"id":"","name":"全社区"});
- }
- if(list.length>0){
- var labelName = '<div class="div-item" data-level="'+vm.curLevel+'">'+
- '<div class="div-title">'+vm.curName+'</div>';
-
- var xzResult = [];//每三条分成一组
- var xzContent = '';
- for(var i=0,len=list.length;i<len;i+=3){//形状列表切割
- xzResult.push(list.slice(i,i+3));
- }
- for(var x in xzResult){
- var item = xzResult[x];
- if(x==0){
- activeClass = "active";
- }else{
- activeClass = "";
- }
- if(item.length==1){//只有一条数据
- var id = item[0].code;
- if(vm.curLevel=="2") {
- id = item[0].id;
- }
- var name = vm.curLevel==3 && id1?item[0].name.substring(3,item[0].name.length):item[0].name;
- xzContent+='<div class="mt20 div-group-btn c-row ml40">'+
- '<div class="div-btn c-33 '+activeClass+'" data-id="'+id+'" @click="">'+
- '<a href="#" class="f-fs14">'+name+'</a>'+
- '</div>'+
- '</div>';
- }
- if(item.length==2){
- var id1 = item[0].code;
- var id2 = item[1].code;
- if(vm.curLevel=="2") {
- id1 = item[0].id;
- id2 = item[1].id;
- }
- var name1 = vm.curLevel==3 && id1?item[0].name.substring(3,item[0].name.length):item[0].name;
- var name2 = vm.curLevel==3 && id2?item[1].name.substring(3,item[1].name.length):item[1].name;
- xzContent+= '<div class="mt20 div-group-btn c-row ml40">'+
- '<div class="div-btn c-33 '+activeClass+'" data-id="'+id1+'">'+
- '<a href="#" class="f-fs14">'+name1+'</a>'+
- '</div>'+
- '<div class="div-btn c-33 " data-id="'+id2+'" data-level="'+item[1].level+'">'+
- '<a href="#" class="f-fs14">'+name2+'</a>'+
- '</div>'+
- '</div>';
- }
- if(item.length==3){
- var id1 = item[0].code;
- var id2 = item[1].code;
- var id3 = item[2].code;
- if(vm.curLevel=="2") {
- id1 = vm.curCode;
- id2 = item[1].id;
- id3 = item[2].id;
- }
-
- var name1 = vm.curLevel==3 && id1?item[0].name.substring(3,item[0].name.length):item[0].name;
- var name2 = vm.curLevel==3 && id2?item[1].name.substring(3,item[1].name.length):item[1].name;
- var name3 = vm.curLevel==3 && id3?item[2].name.substring(3,item[2].name.length):item[2].name;
- xzContent+='<div class="mt20 div-group-btn c-row ml40">'+
- '<div class="div-btn c-33 '+activeClass+'" data-id="'+id1+'">'+
- '<a href="#" class="f-fs14">'+name1+'</a>'+
- '</div>'+
- '<div class="div-btn c-33 " data-id="'+id2+'">'+
- '<a href="#" class="f-fs14">'+name2+'</a>'+
- '</div>'+
- '<div class="div-btn c-33 " data-id="'+id3+'">'+
- '<a href="#" class="f-fs14">'+name3+'</a>'+
- '</div>'+
- '</div>';
- }
-
- }
-
- resultData += labelName+xzContent+'</div>';
- }
- $(".div-content").append(resultData);
- }
- },
- mounted: function(){
- this.roleLevel = this.curLevel;
- this.selectLevel = this.curLevel;
- this.resultCode = this.curCode;
- if(!(this.filterHtml && this.yearHtml)){
- this.formatYearData();
- this.requestData();
- }
- }
- });
-
- })()
|