estimate-analysis.js 8.5 KB

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