estimate-analysis.js 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. var reqList = [];
  2. new Vue({
  3. el: "#main",
  4. data: {
  5. appname: "评价分析",
  6. //页面请求参数
  7. index: 28,
  8. level: '',
  9. area: '',
  10. startDate: '',
  11. endDate: '',
  12. avg: 0,
  13. isloading:false,
  14. },
  15. components: {
  16. vuedals: Vuedals.Component
  17. },
  18. methods: {
  19. getAreaData: function(arg){
  20. //如果level改变,则需要重新加载整个页面的数据,否则只需加载底部区域数据
  21. if(arg.level == this.level){
  22. this.lowLevel = arg.lowLevel;
  23. loadData([2], this);
  24. }else{
  25. this.level = arg.level;
  26. this.lowLevel = arg.lowLevel;
  27. this.area = arg.area;
  28. this.areaTitle = arg.areaTitle;
  29. loadData([0,1,2], this);
  30. }
  31. EventBus.$emit('update-area-name', {areaName: this.areaTitle});
  32. //存储请求所带的参数
  33. reqList.push({
  34. level: this.level,
  35. area: this.area,
  36. areaTitle: this.areaTitle,
  37. index: this.index,
  38. endDate: this.endDate,
  39. startDate: this.startDate,
  40. lowLevel: this.lowLevel
  41. })
  42. }
  43. },
  44. mounted: function(){
  45. //初始化数据
  46. initData(this);
  47. //获得顶部各tab的值
  48. loadData([0,1,2], this); //参数组数表示请求的区域为上中下
  49. //存储请求所带的参数
  50. reqList.push({
  51. level: this.level,
  52. area: this.area,
  53. areaTitle: this.areaTitle,
  54. index: this.index,
  55. endDate: this.endDate,
  56. startDate: this.startDate,
  57. lowLevel: this.lowLevel
  58. });
  59. //设置监听器, 监听折线图日期变化
  60. var vm = this;
  61. //监听后退按钮的操作
  62. EventBus.$on("back-click", function(arg){
  63. EventBus.$emit('update-statistics-time', {}); //更新统计时间
  64. if(reqList.length == 1){
  65. history.go(-1);
  66. }
  67. else{
  68. var preInfo = reqList.pop();
  69. var info = reqList[reqList.length - 1];
  70. vm.level = info.level;
  71. vm.area = info.area;
  72. vm.areaTitle = info.areaTitle;
  73. vm.lowLevel = info.lowLevel;
  74. vm.index = info.index;
  75. loadData([0,1,2], vm);
  76. EventBus.$emit('update-area-name', {areaName: vm.areaTitle});
  77. }
  78. });
  79. //监听页面刷新
  80. EventBus.$on("refresh-click", function(arg){
  81. loadData([0,1,2], vm);
  82. });
  83. $("#main").removeClass("c-hide")
  84. }
  85. });
  86. function initData(vm){
  87. //获得缓存中缓存的角色权限
  88. var userRole = window.sessionStorage.getItem("selectedRole");
  89. if(!userRole){
  90. return false;
  91. }
  92. vm.userRole = JSON.parse(userRole);
  93. vm.level = vm.userRole.code == '350200' ? 4 : vm.userRole.code.length == 6 ? 3 : 2;
  94. vm.area = vm.userRole.code;
  95. vm.areaTitle = vm.userRole.name;
  96. EventBus.$emit('update-area-name', {areaName: vm.areaTitle});
  97. var now = new Date();
  98. vm.endDate = now.format("yyyy-M-dd");
  99. vm.startDate = "2017-01-01"; //评价功能是2017年才上线的
  100. }
  101. function initReqParams(vm){
  102. var param = [{
  103. url: "/statistics/getAVGSocre",
  104. data: {level: vm.level, area: vm.area}
  105. },{
  106. url: "/statistics/getAVGSocreByMonth",
  107. data: {level: vm.level, area: vm.area, statDate: vm.startDate, endDate: vm.endDate}
  108. },{
  109. url: "/statistics/lowlevel_all",
  110. data: {level: vm.level, area: vm.area, index: vm.index, sort: 1, date: vm.endDate, lowLevel: vm.lowLevel}
  111. }];
  112. return param;
  113. }
  114. function loadData(loadArr, vm){
  115. //获取其他请求的参数
  116. var reqParams = initReqParams(vm),
  117. reqPromise = [],
  118. sendPanelReq = [];
  119. for(i=0; i< loadArr.length; i++){
  120. var j = loadArr[i];
  121. var param = reqParams[j];
  122. if(j == 1){
  123. sendPanelReq.push(param);
  124. }else{
  125. reqPromise.push(httpRequest.get(param.url, {data: param.data}));
  126. }
  127. }
  128. vm.isloading=true
  129. //因为中间区域的请求时间较长,所以另外放出来处理
  130. if(sendPanelReq.length > 0){
  131. //删除loadArr里的1
  132. var index = loadArr.indexOf(1);
  133. loadArr.splice(index, 1);
  134. statisticAPI.getAVGSocreByMonth(sendPanelReq[0].data).then(function(res){
  135. if(res.status == 200){
  136. handleSecondPanelData(res.data, vm);
  137. }else{
  138. console.log(res.msg);
  139. }
  140. });
  141. }
  142. if(reqPromise.length > 0){
  143. Promise.all(reqPromise).then(function(ress){
  144. var res1, res2, res3;
  145. for(var i=0; i<loadArr.length; i++){
  146. var j = loadArr[i] + 1;
  147. if(j == 1){
  148. res1 = ress[i];
  149. }
  150. if(j == 3){
  151. res3 = ress[i];
  152. }
  153. }
  154. if(res1){
  155. if(res1.status == 200){
  156. vm.avg = res1.data.rs.avgCount;
  157. }else{
  158. console.log(res1.msg);
  159. }
  160. }
  161. // if(res2){
  162. // if(res2.status == 200){
  163. // handleSecondPanelData(res2.data, vm);
  164. // }else{
  165. // console.log(res2.msg);
  166. // }
  167. //
  168. // }
  169. if(res3){
  170. if(res3.status == 200){
  171. listHandle(res3.data, vm);
  172. }else{
  173. console.log(res3.msg);
  174. }
  175. }
  176. })
  177. }
  178. }
  179. function handleSecondPanelData(data, vm){
  180. var xData = [],
  181. yData = [];
  182. for(i=0; i<data.length; i++){
  183. var item = data[i];
  184. xData.push(item.month);
  185. yData.push(item.socre);
  186. }
  187. drawLine(xData, yData, '平均评分', '#12b7f5');
  188. vm.isloading=false
  189. }
  190. function listHandle(data, vm){
  191. for(i in data){
  192. var data2 = JSON.parse(data[i]);
  193. var list = data2.data;
  194. var topArr = soreRank(getKeyValueArr(list, 'avgCount'));
  195. var arr = _.map(list, function(o, index){
  196. var cols = [o.name, o.avgCount || '暂无评分'];
  197. return {
  198. rank: topArr[index],
  199. code: o.code,
  200. name: o.name,
  201. cols: cols
  202. }
  203. });
  204. EventBus.$emit("render-area-data",{
  205. level: vm.level,
  206. area: vm.area,
  207. lowLevel: vm.lowLevel,
  208. headers: ["排名", "平均评分"],
  209. rows: arr,
  210. cityLevelNoShowTeamTab: true,
  211. districtLevelNoShowTeamTab: true
  212. });
  213. }
  214. }
  215. function drawLine(xData, yData, name, color){
  216. var lineCharts = echarts.init(document.getElementById('lineChart'));
  217. //处理数据, 数据按照10条数一屏展示
  218. var lastIndex = xData.length % 10;
  219. if(xData.length >10 ){
  220. dataZoom_end = 100-(9/xData.length)*100;
  221. }else{
  222. dataZoom_end = 0;
  223. }
  224. var options = {
  225. tooltip: {
  226. trigger: 'axis'
  227. },
  228. legend: {
  229. top: '0px',
  230. data: [name],
  231. borderColor: "#f1f1f1"
  232. },
  233. grid: {
  234. show: false,
  235. left: '10px',
  236. right: '30px',
  237. bottom: '40px',
  238. top: '20px',
  239. containLabel: true
  240. },
  241. xAxis: {
  242. type: 'category',
  243. boundaryGap: false,
  244. data: xData,
  245. axisLabel: {
  246. interval:0,//横轴信息全部显示
  247. formatter: function (value, index) {
  248. return value+"月";
  249. }
  250. }
  251. },
  252. yAxis: {
  253. type: 'value',
  254. axisPointer: {
  255. snap: true
  256. },
  257. scale: true,
  258. minInterval: 1,
  259. boundaryGap: ['10%', '30%'],
  260. splitLine: {show:false}
  261. },
  262. dataZoom: [{//给x轴设置滚动条
  263. start: dataZoom_end,
  264. end: 100,
  265. type: 'slider',
  266. zoomLock: true,
  267. showDetail: false
  268. },{ //下面这个属性是内容区域配置
  269. start: dataZoom_end,
  270. end: 100,
  271. type: 'inside',
  272. zoomLock: true,
  273. }],
  274. series: [{
  275. name: name,
  276. type: 'line',
  277. smooth: true,
  278. data: yData,
  279. // color: color,
  280. lineStyle:{
  281. normal:{
  282. color: color
  283. }
  284. },
  285. itemStyle: {
  286. normal: {
  287. color: color
  288. }
  289. }
  290. }]
  291. };
  292. $("#lineChart").removeAttr('_echarts_instance_')
  293. lineCharts.setOption(options);
  294. window.onresize = function(){
  295. lineCharts.resize();
  296. }
  297. }