var reqList = [{}]; //记录请求的参数和url,用于后退时使用 var colors={"0":"#5b9db5","1":"#ed7d31","2":"#a5a5a5", "3":"#ffc000","4":"#44c274","5":"#70ad47", "6":"#255e91","7":"#9e480e","8":"#7e7e7e","9":"#997300","10":"#264478","11":"#43682b","12":"#5b9db5"} Vue.use(Vuedals.default); new Vue({ el: "#main", data: { isloading:false, //加载中 start:"", end:"", pieData:[], //饼图数据 tabnumber:0, tabledata0:[], //表格数据 topData:{}, //请求页面所需参数 levelList:[{level:"4",areaLevel:"2"},{level:"3",areaLevel:"3"},{level:"2",areaLevel:"4"}], //两种搜索,地区等级对比 areaLevel:"", // 2、市,3、区,4、社区,5、团队 initareaLevel:"", initlevel: '', initarea: '', level: '', area: '', areaTitle: '', lowLevel: '', initlowLevel:"", lowCode: '', chooseYear: '', userRole: '', pieShow:true, pieShow1:true, reqListLength:1, }, components: { vuedals: Vuedals.Component }, mounted: function () { var vm=this //初始化数据 initData(vm); }, methods: { getData:function(isNext,type){ //是否下转 var vm = this var params={ areaLevel: vm.areaLevel, level: vm.level, area: vm.area, endDate: vm.end, startDate: vm.start, lowLevel: vm.lowLevel, areaTitle:vm.areaTitle } loadData([0,1,2,3], vm); //刷新数据 if(isNext){ //存储请求所带的参数 reqList.push(params); vm.reqListLength=reqList.length }else{ reqList[reqList.length-1]=params vm.reqListLength=reqList.length } }, //表格tab切换/下转 getnewdata:function(arg){ var vm = this vm.lowLevel=arg.lowLevel||"" if(arg.level){ vm.level = arg.level vm.areaLevel = _.find(vm.levelList,{level:vm.level}).areaLevel } if(arg.area){ vm.area = arg.area } if(arg.areaTitle){ vm.areaTitle = arg.areaTitle } vm.getData(arg.level) //有传level,说明是下转 }, //重新搜索 initSearchHandle: function (arg) { var vm=this vm.start = arg.start vm.end = arg.end //搜索时,取消下转记录 vm.area=vm.initarea vm.areaLevel=vm.initareaLevel vm.level=vm.initlevel vm.lowLevel = vm.initlowLevel reqList=[{}]; //搜索时清空历史记录,重新搜索 vm.getData() vm.initTable() }, showTab:function(){ }, backClick:function(){ var vm=this if (reqList.length == 1) { history.go(-1); } else { var preInfo = reqList.pop(); var info = reqList[reqList.length - 1]; vm.areaLevel = info.areaLevel; vm.level = info.level; vm.area = info.area; vm.lowLevel = info.lowLevel; vm.getData() vm.$refs.tableRef0.changeTab({level:vm.level,lowlevel:vm.lowLevel}) //表格tab } }, bindEvent:function(){ var vm=this //监听后退按钮的操作 EventBus.$on("back-click", function (arg) { EventBus.$emit('update-statistics-time', {}); //更新统计时间 vm.backClick() }); //监听页面刷新 EventBus.$on("refresh-click", function (arg) { EventBus.$emit('update-statistics-time', {}); //更新统计时间 initData(vm) }); $("#main").removeClass("c-hide"); }, initTable:function(){ var vm=this vm.$refs.tableRef0.initTable({ tabList:[{name:"各区",level:"4",lowlevel:"3",isShow:true},{name:"社区",level:"3",lowlevel:"4",isShow:true},{name:"团队",level:"2",lowlevel:"5",isShow:true}], //表格表头 headers:[{thead:"排名",param:"name",canclick:true},{thead:"访视人数",param:"rehabilitationTotalAmount0"}], tabnumber:vm.tabnumber }) }, }, }) function initData(vm) { //获得缓存中缓存的角色权限 var userRole = window.sessionStorage.getItem("selectedRole"); if (!userRole) { return false; } vm.userRole = JSON.parse(userRole); //level:2、市,3、区,4、社区,5、团队 vm.initareaLevel = vm.areaLevel = vm.userRole.code == '350200' ? 2 : vm.userRole.code.length == 6 ? 3 : 4; vm.initlevel = vm.level = vm.userRole.code == '350200' ? 4 : vm.userRole.code.length == 6 ? 3 : 2; vm.lowLevel = vm.initlowLevel = vm.userRole.code == '350200' ? 3 : vm.userRole.code.length == 6 ? 4 : 5; vm.initarea =vm.area = vm.userRole.code; vm.areaTitle = vm.userRole.name; vm.tabnumber=vm.areaLevel==4?1:vm.areaLevel==3?2:3 //表格显示的tab数 //初始化时间 EventBus.$emit("init-FilterDate") vm.bindEvent() } function initReqParams(vm) { var reqParam = [{ url: "statistics/getHomeVisitTotalHead", //头部 reqType: 'get', data:{ startDate: vm.start, endDate: vm.end, area: vm.area, level: vm.areaLevel, //2、市,3、区,4、社区,5、团队 index:150, }, },{ url: "statistics/getSpecialistTypeCircle", //访视对象分析150 reqType: 'get', data:{ startDate: vm.start, endDate: vm.end, area: vm.area, level: vm.areaLevel, //等级,4 市 3区 2社区 1团队 index:150, }, },{ url: "statistics/getSpecialistTypeCircle", //访视完成情况分析152 reqType: 'get', data:{ startDate: vm.start, endDate: vm.end, area: vm.area, level: vm.areaLevel, //等级,4 市 3区 2社区 1团队 index:152, }, },{ url: "statistics/rehabilitationLowLevel", //列表151 reqType: 'get', data:{ startDate: vm.start, endDate: vm.end, area: vm.area, level: vm.areaLevel, //等级,4 市 3区 2社区 1团队 sort: 1, lowLevel:vm.lowLevel||"", //等级 5:团队 4社区机构 3区级 2市级, index:151, }, }]; return reqParam; } function loadData(loadArr, vm) { //获取其他请求的参数 var reqParams = initReqParams(vm), reqPromise = [], newArr = []; //记录非顶部请求的请求数组 for (i = 0; i < loadArr.length; i++) { var j = loadArr[i]; var param = reqParams[j]; reqPromise.push(httpRequest.get(param.url, { data: param.data })); newArr.push(loadArr[i]); } vm.isloading=true if (reqPromise.length > 0) { Promise.all(reqPromise).then(function (ress) { var res1, res2, res3, res4, res5; for (var i = 0; i < loadArr.length; i++) { var j = loadArr[i] + 1; if (j == 1) { res1 = ress[i]; } if (j == 2) { res2 = ress[i]; } if (j == 3) { res3 = ress[i]; } if (j == 4) { res4 = ress[i]; } if (j == 5) { res5 = ress[i]; } } if(res1&& res1.status == 200){ vm.topData=res1.data } if(res2&& res2.status == 200){ if(res2.data.length==0||(res2.data.length==1&&!res2.data[0].slaveKey1Name)){ vm.pieShow=false }else{ vm.pieShow=true vm.$nextTick(function(){ handlePieData({elId:"pieChart", arry:res2.data, title:{}, colors:colors,position:['30%', '51%'], radius:['70%', '90%'],nameparam:"slaveKey1Name",param:"total"}) }) } } if(res3&& res3.status == 200){ if(res3.data.length==0||(res3.data.length==1&&!res3.data[0].slaveKey1Name)){ vm.pieShow1=false }else{ vm.pieShow1=true vm.$nextTick(function(){ handlePieData({elId:"pieChart1", arry:res3.data, title:{}, colors:colors,position:['30%', '51%'], radius:['70%', '90%'],nameparam:"slaveKey1Name",param:"total"}) }) } } if(res4&& res4.status == 200){ vm.tabledata0=listHandle(res4.data,"rehabilitationTotalAmount0", vm); } vm.isloading=false }) } } function listHandle(list,param, vm){ var topArr = []; if(list.length==1&&!list[0].name){ list=[] } topArr = soreRank(getKeyValueArr(list, param||"amount")); var newlist = _.map(list, function(o, index){ o.rank=topArr[index] return o }); EventBus.$emit("render-area-data",{ }); return newlist }