change-back.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. var reqList = []; //记录请求的参数和url,用于后退时使用
  2. Vue.use(Vuedals.default);
  3. new Vue({
  4. el: "#main",
  5. data: {
  6. appname: "退改签",
  7. isback: true,
  8. isrefresh: true,
  9. isfilter: false,
  10. isopen: false,
  11. //请求页面所需参数
  12. level: '',
  13. area: '',
  14. areaTitle: '',
  15. index: '9',
  16. selectedDateType: 1, //折线图坐标值1-日,2-周,3-月
  17. endDate: '',
  18. startDate: '',
  19. lowLevel: '',
  20. chooseYear: '',
  21. userRole: '',
  22. //数据结果
  23. topDatas: {
  24. index_2: 0,
  25. index_9: 0,
  26. index_10: 0
  27. },
  28. isloading:false, //加载中
  29. },
  30. components: {
  31. vuedals: Vuedals.Component
  32. },
  33. methods: {
  34. changeTag: function(val) {
  35. this.index = val;
  36. loadData([1, 2], this);
  37. //存储请求所带的参数
  38. reqList.push({
  39. level: this.level,
  40. area: this.area,
  41. areaTitle: this.areaTitle,
  42. index: this.index,
  43. date:this.endDate,
  44. endDate: this.endDate,
  45. startDate: this.startDate,
  46. lowLevel: this.lowLevel
  47. })
  48. },
  49. getNewLineData: function(arg) {
  50. this.selectedDateType = arg.dateType;
  51. loadData([1], this);
  52. },
  53. getAreaData: function(arg) {
  54. //如果level改变,则需要重新加载整个页面的数据,否则只需加载底部区域数据
  55. if(arg.level == this.level) {
  56. this.lowLevel = arg.lowLevel;
  57. loadData([2], this);
  58. } else {
  59. this.level = arg.level;
  60. this.lowLevel = arg.lowLevel;
  61. this.area = arg.area;
  62. this.areaTitle = arg.areaTitle;
  63. loadData([0, 1, 2], this);
  64. }
  65. EventBus.$emit('update-area-name', {areaName: this.areaTitle});
  66. //存储请求所带的参数
  67. reqList.push({
  68. level: this.level,
  69. area: this.area,
  70. areaTitle: this.areaTitle,
  71. index: this.index,
  72. endDate: this.endDate,
  73. startDate: this.startDate,
  74. lowLevel: this.lowLevel,
  75. })
  76. }
  77. },
  78. mounted: function() {
  79. //初始化数据
  80. initData(this);
  81. //获得顶部各tab的值
  82. loadData([0, 1, 2], this); //参数组数表示请求的区域为上中下
  83. //存储请求所带的参数
  84. reqList.push({
  85. level: this.level,
  86. area: this.area,
  87. areaTitle: this.areaTitle,
  88. index: this.index,
  89. endDate: this.endDate,
  90. startDate: this.startDate,
  91. lowLevel: this.lowLevel
  92. });
  93. //设置监听器, 监听折线图日期变化
  94. var vm = this;
  95. //监听后退按钮的操作
  96. EventBus.$on("back-click", function(arg) {
  97. EventBus.$emit('update-statistics-time', {}); //更新统计时间
  98. if(reqList.length == 1) {
  99. history.go(-1);
  100. } else {
  101. var preInfo = reqList.pop();
  102. var info = reqList[reqList.length - 1];
  103. vm.level = info.level;
  104. vm.area = info.area;
  105. vm.areaTitle = info.areaTitle;
  106. vm.lowLevel = info.lowLevel;
  107. vm.index = info.index;
  108. loadData([0, 1, 2], vm);
  109. EventBus.$emit('update-area-name', {areaName: vm.areaTitle});
  110. }
  111. });
  112. //监听页面刷新
  113. EventBus.$on("refresh-click", function(arg) {
  114. EventBus.$emit('update-statistics-time', {}); //更新统计时间
  115. loadData([0, 1, 2], vm);
  116. });
  117. $("#main").removeClass("c-hide");
  118. }
  119. })
  120. function initData(vm) {
  121. //获得缓存中缓存的角色权限
  122. var userRole = window.sessionStorage.getItem("selectedRole");
  123. if(!userRole) {
  124. return false;
  125. }
  126. vm.userRole = JSON.parse(userRole);
  127. vm.level = vm.userRole.code == '350200' ? 4 : vm.userRole.code.length == 6 ? 3 : 2;
  128. vm.area = vm.userRole.code;
  129. vm.areaTitle = vm.userRole.name;
  130. var now = new Date();
  131. if(now.getMonth() >= 6 || now.getFullYear()>=2023) {
  132. vm.chooseYear = now.getFullYear();
  133. } else {
  134. vm.chooseYear = now.getFullYear() - 1;
  135. }
  136. vm.startDate = getStartDate(vm.chooseYear);
  137. vm.endDate = getEndDate(vm.chooseYear);
  138. //更新头部信息
  139. EventBus.$emit('update-all-prompt-info', {
  140. areaName: vm.areaTitle,
  141. selectDate: "",
  142. dimensionVal: vm.analysisName
  143. });
  144. }
  145. function getTopReqParams(index1, vm) {
  146. var url = "/statistics/index_all",
  147. data = {
  148. index: index1,
  149. level: vm.level,
  150. area: vm.area,
  151. startDate: vm.startDate,
  152. endDate: vm.endDate
  153. };
  154. return {
  155. url: url,
  156. data: data
  157. };
  158. }
  159. function getTopTagDatas(vm) {
  160. var reqs = [],
  161. indexs = ['2', '9', '10'];
  162. for(i = 0; i < indexs.length; i++) {
  163. var item = getTopReqParams(indexs[i], vm);
  164. reqs.push(httpRequest.get(item.url, {
  165. data: item.data
  166. }));
  167. }
  168. Promise.all(reqs).then(function(ress) {
  169. for(i = 0; i < ress.length; i++) {
  170. var res = ress[i];
  171. if(res.status == 200) {
  172. for(key in res.data) {
  173. vm.topDatas[key] = res.data[key];
  174. }
  175. } else {
  176. console.log(res.msg);
  177. }
  178. }
  179. })
  180. }
  181. function initReqParams(vm) {
  182. reqParam = [{
  183. url: "/statistics/interval_total",
  184. reqType: 'get',
  185. data: {
  186. index: vm.index,
  187. level: vm.level,
  188. area: vm.area,
  189. startDate: vm.startDate,
  190. endDate: vm.endDate,
  191. interval: vm.selectedDateType
  192. }
  193. }, {
  194. url: "/statistics/lowlevel_all",
  195. reqType: 'get',
  196. data: {
  197. sort: 1,
  198. date: vm.endDate,
  199. level: vm.level,
  200. index: vm.index,
  201. area: vm.area
  202. }
  203. }];
  204. if(vm.lowLevel) {
  205. reqParam[1].data.lowLevel = vm.lowLevel;
  206. }
  207. return reqParam;
  208. }
  209. function loadData(loadArr, vm) {
  210. if(loadArr.indexOf(0) > -1) {
  211. getTopTagDatas(vm);
  212. }
  213. //获取其他请求的参数
  214. var reqParams = initReqParams(vm),
  215. reqPromise = [],
  216. newArr = []; //记录非顶部请求的请求数组
  217. for(i = 0; i < loadArr.length; i++) {
  218. if(loadArr[i] == 0) {
  219. // do nothing
  220. } else {
  221. var j = loadArr[i] - 1;
  222. var param = reqParams[j];
  223. reqPromise.push(httpRequest.get(param.url, {
  224. data: param.data
  225. }));
  226. newArr.push(loadArr[i]);
  227. }
  228. }
  229. vm.isloading=true
  230. if(reqPromise.length > 0) {
  231. Promise.all(reqPromise).then(function(ress) {
  232. vm.isloading=false
  233. var res1 = [],
  234. res2 = [];
  235. if(ress.length==2){
  236. res1 = ress[0] || [],
  237. res2 = ress[1] || [];
  238. }
  239. if(loadArr[0]==1){//点击日周月
  240. res1 = ress[0] || [];
  241. }
  242. if(loadArr[0]==2){//点击区、社区
  243. res2 = ress[0] || [];
  244. }
  245. if(res1 && res1.status == 200) {
  246. handleSecondPanelData(res1.data, vm);
  247. }
  248. if(res2) {
  249. if(res2.status == 200) {
  250. listHandle(res2.data, vm);
  251. } else {
  252. console.log(res2.msg);
  253. }
  254. }
  255. })
  256. }
  257. }
  258. function handleSecondPanelData(data, vm) {
  259. var xDatas = [],
  260. yDatas = [],
  261. names = [],
  262. colors = ['#12b7f5'],
  263. labels = {
  264. '2': '退签人数新增趋势',
  265. '9': '待审核数新增趋势',
  266. '10': '改签人数新增趋势'
  267. },
  268. index_names = {
  269. 'index_2': '退签人数',
  270. 'index_9': '待审核数',
  271. 'index_10': '改签人数'
  272. };
  273. for(var p in data) {
  274. names.push(index_names[p]);
  275. var xData = _.map(data[p].data, function(o) {
  276. return o.range;
  277. });
  278. var yData = _.map(data[p].data, function(o) {
  279. return o.amount;
  280. });
  281. xDatas.push(xData);
  282. yDatas.push(yData);
  283. }
  284. EventBus.$emit("draw-line-chart", {
  285. panelName: labels[vm.index],
  286. quotaNames: names,
  287. xData: xDatas[0],
  288. yDatas: yDatas,
  289. colors: colors,
  290. });
  291. }
  292. function listHandle(data, vm) {
  293. for(i in data) {
  294. var list = data[i];
  295. var topArr = [];
  296. topArr = soreRank(getKeyValueArr(list, 'amount'));
  297. var arr = _.map(list, function(o, index) {
  298. var cols = [o.name];
  299. cols.push(o.amount);
  300. return {
  301. rank: topArr[index],
  302. code: o.code,
  303. name: o.name,
  304. cols: cols
  305. }
  306. });
  307. var headers = {
  308. '2': ["排名", "退签人数"],
  309. '9': ["排名", "待审核数"],
  310. '10': ["排名", "改签人数"]
  311. };
  312. EventBus.$emit("render-area-data", {
  313. level: vm.level,
  314. area: vm.area,
  315. lowLevel: vm.lowLevel,
  316. headers: headers[vm.index],
  317. rows: arr
  318. });
  319. }
  320. }