consulting-analysis.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. var reqList = [];
  2. new Vue({
  3. el: "#main",
  4. data: {
  5. appname: "咨询分析",
  6. isback: true,
  7. isrefresh: true,
  8. isfilter: true,
  9. isopen: true,
  10. //页面请求参数
  11. level: '',
  12. area: '',
  13. areaTitle: '',
  14. lowLevel: '',
  15. chooseYear: '',
  16. endDate: '',
  17. topDatas: {
  18. total: 0,
  19. noRelyCount: 0,
  20. noRelyRate: 0,
  21. relyRate: 0
  22. },
  23. isloading:false, //加载中
  24. },
  25. components: {
  26. vuedals: Vuedals.Component
  27. },
  28. methods:{
  29. getAreaData: function(arg){
  30. //如果level改变,则需要重新加载整个页面的数据,否则只需加载底部区域数据
  31. if(arg.level == this.level){
  32. this.lowLevel = arg.lowLevel;
  33. loadData([2], this);
  34. }else{
  35. this.level = arg.level;
  36. this.lowLevel = arg.lowLevel;
  37. this.area = arg.area;
  38. this.areaTitle = arg.areaTitle;
  39. loadData([0,1,2], this);
  40. }
  41. EventBus.$emit('update-area-name', {areaName: this.areaTitle});
  42. //存储请求所带的参数
  43. reqList.push({
  44. level: this.level,
  45. area: this.area,
  46. areaTitle: this.areaTitle,
  47. lowLevel: this.lowLevel,
  48. endDate: this.endDate
  49. })
  50. }
  51. },
  52. mounted: function(){
  53. //初始化数据
  54. initData(this);
  55. //获得顶部各tab的值
  56. loadData([0,1,2], this); //参数组数表示请求的区域为上中下
  57. //存储请求所带的参数
  58. reqList.push({
  59. level: this.level,
  60. area: this.area,
  61. areaTitle: this.areaTitle,
  62. index: this.index,
  63. endDate: this.endDate,
  64. startDate: this.startDate,
  65. lowLevel: this.lowLevel
  66. });
  67. //设置监听器, 监听折线图日期变化
  68. var vm = this;
  69. //监听后退按钮的操作
  70. EventBus.$on("back-click", function(arg){
  71. EventBus.$emit('update-statistics-time', {}); //更新统计时间
  72. if(reqList.length == 1){
  73. history.go(-1);
  74. }
  75. else{
  76. var preInfo = reqList.pop();
  77. var info = reqList[reqList.length - 1];
  78. vm.level = info.level;
  79. vm.area = info.area;
  80. vm.areaTitle = info.areaTitle;
  81. vm.lowLevel = info.lowLevel;
  82. vm.index = info.index;
  83. loadData([0,1,2], vm);
  84. EventBus.$emit('update-area-name', {areaName: vm.areaTitle});
  85. }
  86. });
  87. //监听页面刷新
  88. EventBus.$on("refresh-click", function(arg){
  89. loadData([0,1,2], vm);
  90. });
  91. //弹出筛选框
  92. EventBus.$on('filter-click', function(arg) {
  93. //弹框显示筛选条件
  94. Vuedals.Bus.$emit('new', {
  95. title: '条件筛选',
  96. onClose:function(data){
  97. console.log(data);
  98. vm.chooseYear = data.chooseYear;
  99. vm.endDate = getEndDate(vm.chooseYear);
  100. loadData([0, 1, 2], vm);//刷新数据
  101. EventBus.$emit('update-statistics-year', {selectDate: vm.chooseYear + "年"});//更新年份
  102. EventBus.$emit('update-statistics-time', {});//更新统计时间
  103. },
  104. component: 'year-filter',
  105. props: {
  106. selectedYear: vm.chooseYear
  107. }
  108. });
  109. });
  110. $("#main").removeClass("c-hide");
  111. }
  112. });
  113. function initData(vm){
  114. //获得缓存中缓存的角色权限
  115. var userRole = window.sessionStorage.getItem("selectedRole");
  116. if(!userRole){
  117. return false;
  118. }
  119. vm.userRole = JSON.parse(userRole);
  120. vm.level = vm.userRole.code == '350200' ? 4 : vm.userRole.code.length == 6 ? 3 : 2;
  121. vm.area = vm.userRole.code;
  122. vm.areaTitle = vm.userRole.name;
  123. EventBus.$emit('update-area-name', {areaName: vm.areaTitle});
  124. var now = new Date();
  125. if(now.getMonth() >= 6){
  126. vm.chooseYear = now.getFullYear();
  127. }else{
  128. vm.chooseYear = now.getFullYear() - 1;
  129. }
  130. vm.endDate = getEndDate(vm.chooseYear);
  131. EventBus.$emit('update-statistics-year', {selectDate: vm.chooseYear + "年"});
  132. }
  133. function initReqParams(vm){
  134. var param = [{
  135. url: "/statistics/Consulting_Title",
  136. data: {level: vm.level, area: vm.area, year: vm.chooseYear}
  137. },{
  138. url: "/statistics/getCoutListByTime",
  139. data: {level: vm.level, area: vm.area, year: vm.chooseYear}
  140. },{
  141. url: "/statistics/Consulting_StatList",
  142. data: {level: vm.level, area: vm.area, year: vm.chooseYear, sort: 1, date: vm.endDate, lowlevel: vm.lowLevel}
  143. }];
  144. return param;
  145. }
  146. function loadData(loadArr, vm){
  147. //获取其他请求的参数
  148. var reqParams = initReqParams(vm),
  149. reqPromise = [];
  150. for(i=0; i< loadArr.length; i++){
  151. var j = loadArr[i];
  152. var param = reqParams[j];
  153. reqPromise.push(httpRequest.get(param.url, {data: param.data}));
  154. }
  155. vm.isloading=true
  156. if(reqPromise.length > 0){
  157. Promise.all(reqPromise).then(function(ress){
  158. vm.isloading=false
  159. var res1, res2, res2;
  160. for(var i=0; i<loadArr.length; i++){
  161. var j = loadArr[i] + 1;
  162. if(j == 1){
  163. res1 = ress[i];
  164. }
  165. if(j == 2){
  166. res2 = ress[i];
  167. }
  168. if(j == 3){
  169. res3 = ress[i];
  170. }
  171. }
  172. if(res1){
  173. if(res1.status == 200){
  174. handleTopPanelData(res1.data, vm);
  175. }else{
  176. console.log(res1.msg);
  177. }
  178. }
  179. if(res2){
  180. if(res2.status == 200){
  181. handleSecondPanelData(res2.data, vm);
  182. }else{
  183. console.log(res2.msg);
  184. }
  185. }
  186. if(res3){
  187. if(res3.status == 200){
  188. listHandle(res3.data, vm);
  189. }else{
  190. console.log(res3.msg);
  191. }
  192. }
  193. })
  194. }
  195. }
  196. function handleTopPanelData(data, vm){
  197. var obj = data.result[0];
  198. vm.topDatas = {
  199. total: obj.total,
  200. noRelyCount: obj.noRelyCount,
  201. noRelyRate: obj.noRelyRate,
  202. relyRate: obj.relyRate
  203. }
  204. }
  205. function handleSecondPanelData(data, vm){
  206. var list = data.resultList,
  207. xData = [],
  208. yData = [];
  209. for(i=0; i<list.length; i++){
  210. var item = list[i];
  211. xData.push(item.name + "时");
  212. yData.push(item.num);
  213. }
  214. drawBarChart(xData, yData);
  215. }
  216. function listHandle(data, vm){
  217. var list = data.resultList;
  218. var topArr = soreRank(getKeyValueArr(list, 'noRelyDoubleRate'));
  219. var arr = _.map(list, function(o, index){
  220. var cols = [o.name, o.total, o.noRelyCount, o.noRelyRate];
  221. return {
  222. rank: topArr[index],
  223. code: o.code,
  224. name: o.name,
  225. cols: cols
  226. }
  227. });
  228. EventBus.$emit("render-area-data",{
  229. level: vm.level,
  230. area: vm.area,
  231. lowLevel: vm.lowLevel,
  232. headers: ["排名", "咨询数", "未回复数", "未回复率"],
  233. rows: arr
  234. });
  235. }
  236. function drawBarChart(xData, yData) {
  237. var myChart = echarts.init(document.getElementById('barChart'));
  238. var options = {
  239. calculable: true,
  240. tooltip: {
  241. trigger: 'item',
  242. // formatter: '{a}<br />{b} : {c}次'
  243. },
  244. toolbox: {
  245. dataZoom: true,
  246. show: true,
  247. orient: 'vertical',
  248. x: 'right',
  249. y: 'center'
  250. },
  251. grid: {
  252. left: '20px',
  253. right: '20px',
  254. bottom: '20px',
  255. top: '20px',
  256. containLabel: true
  257. },
  258. xAxis: [{
  259. type: 'category',
  260. axisLine: {
  261. show: true,
  262. lineStyle: {
  263. color: '#dcdcdc',
  264. width: 1
  265. }
  266. },
  267. axisLabel: {
  268. show: true,
  269. color: '#666'
  270. },
  271. splitLine: {
  272. show: false
  273. },
  274. data: xData
  275. }],
  276. yAxis: [{
  277. type: 'value',
  278. axisLine: {
  279. show: true,
  280. lineStyle: {
  281. color: '#dcdcdc',
  282. width: 1
  283. }
  284. },
  285. axisLabel: {
  286. show: true,
  287. color: '#666'
  288. },
  289. splitLine: {
  290. show: false
  291. },
  292. }],
  293. series: [{
  294. name: '回复次数',
  295. type: 'bar',
  296. barWidth: 40,
  297. itemStyle: {
  298. normal: {
  299. color: function(params) {
  300. var colorList = ['#12B7F5', '#FB5DAB', '#CD67FD', '#FFC800', '#61EB41'];
  301. return colorList[params.dataIndex]
  302. },
  303. label: {
  304. show: true,
  305. position: 'top',
  306. formatter: function(params) {
  307. return params.value;
  308. }
  309. },
  310. barBorderRadius: 0
  311. }
  312. },
  313. data: yData
  314. }]
  315. };
  316. myChart.clear();
  317. myChart.setOption(options);
  318. window.onresize = function() {
  319. myChart.resize();
  320. }
  321. }