estimate-analysis.js 9.0 KB

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