consulting-analysis.js 9.7 KB

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