estimate-analysis.js 8.4 KB

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