renew-progress.js 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  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: true,
  10. isopen: false,
  11. //请求页面所需参数
  12. level: '',
  13. area: '',
  14. areaTitle: '',
  15. index: '3',
  16. selectedDateType: 1, //折线图坐标值1-日,2-周,3-月
  17. endDate: '',
  18. startDate: '',
  19. lowLevel: '',
  20. lowCode: '',
  21. chooseYear: '',
  22. userRole: '',
  23. analysisName: "所有居民",
  24. renewRange: {
  25. renewRangeText: "",
  26. renewRange: "",
  27. renewAmount: "",
  28. renewRateAll: ""
  29. },
  30. switchRange: {
  31. switchRangeText: "",
  32. switchRange: "",
  33. switchAmount: "",
  34. switchRateAll: ""
  35. },
  36. contentHtml: "",
  37. isloading:false, //加载中
  38. },
  39. components: {
  40. vuedals: Vuedals.Component
  41. },
  42. methods: {
  43. getNewLineData: function(arg) {
  44. this.selectedDateType = arg.dateType;
  45. loadData([1], this);
  46. },
  47. getAreaData: function(arg) {
  48. //如果level改变,则需要重新加载整个页面的数据,否则只需加载底部区域数据
  49. if(arg.level == this.level) {
  50. this.lowLevel = arg.lowLevel;
  51. loadData([2], this);
  52. } else {
  53. this.level = arg.level;
  54. this.lowLevel = arg.lowLevel;
  55. this.area = arg.area;
  56. this.areaTitle = arg.areaTitle;
  57. loadData([0, 1, 2], this);
  58. }
  59. EventBus.$emit('update-area-name', {
  60. areaName: this.areaTitle
  61. });
  62. //存储请求所带的参数
  63. reqList.push({
  64. level: this.level,
  65. area: this.area,
  66. areaTitle: this.areaTitle,
  67. index: this.index,
  68. endDate: this.endDate,
  69. startDate: this.startDate,
  70. lowLevel: this.lowLevel,
  71. lowCode: this.lowCode,
  72. })
  73. }
  74. },
  75. mounted: function() {
  76. //初始化数据
  77. initData(this);
  78. //获得顶部各tab的值
  79. loadData([0, 1, 2], this); //参数组数表示请求的区域为上中下
  80. //存储请求所带的参数
  81. reqList.push({
  82. level: this.level,
  83. area: this.area,
  84. areaTitle: this.areaTitle,
  85. index: this.index,
  86. endDate: this.endDate,
  87. startDate: this.startDate,
  88. lowLevel: this.lowLevel,
  89. lowCode: this.lowCode,
  90. });
  91. //设置监听器, 监听折线图日期变化
  92. var vm = this;
  93. //监听后退按钮的操作
  94. EventBus.$on("back-click", function(arg) {
  95. EventBus.$emit('update-statistics-time', {}); //更新统计时间
  96. if(reqList.length == 1) {
  97. history.go(-1);
  98. } else {
  99. var preInfo = reqList.pop();
  100. var info = reqList[reqList.length - 1];
  101. vm.level = info.level;
  102. vm.area = info.area;
  103. vm.areaTitle = info.areaTitle;
  104. vm.lowLevel = info.lowLevel;
  105. vm.index = info.index;
  106. vm.lowCode = info.lowCode;
  107. loadData([0, 1, 2], vm);
  108. EventBus.$emit('update-area-name', {areaName: vm.areaTitle});
  109. }
  110. });
  111. //监听页面刷新
  112. EventBus.$on("refresh-click", function(arg) {
  113. EventBus.$emit('update-statistics-time', {}); //更新统计时间
  114. loadData([0, 1, 2], vm);
  115. });
  116. //弹出筛选框
  117. EventBus.$on('filter-click', function(arg) {
  118. //弹框显示筛选条件
  119. Vuedals.Bus.$emit('new', {
  120. title: '条件筛选',
  121. onClose: function(data) {
  122. vm.chooseYear = data.chooseYear;
  123. vm.lowCode = data.lowCode;
  124. vm.analysisName = data.name;
  125. vm.startDate = getStartDate(vm.chooseYear);
  126. vm.endDate = getEndDate(vm.chooseYear);
  127. //请求参数重置,页面类型重新开始
  128. vm.level = vm.userRole.code == '350200' ? 4 : vm.userRole.code.length == 6 ? 3 : 2;
  129. vm.area = vm.userRole.code;
  130. vm.areaTitle = vm.userRole.name;
  131. EventBus.$emit('update-area-name', {
  132. areaName: vm.areaTitle
  133. });
  134. vm.selectedDateType = 1;
  135. //然后清空请求列表数组
  136. reqList.splice(0, reqList.length);
  137. loadData([0, 1, 2], vm); //刷新数据
  138. //存储请求所带的参数
  139. reqList.push({
  140. level: vm.level,
  141. area: vm.area,
  142. areaTitle: vm.areaTitle,
  143. index: vm.index,
  144. endDate: vm.endDate,
  145. startDate: vm.startDate,
  146. lowLevel: vm.lowLevel,
  147. lowCode: vm.lowCode,
  148. analysisType: vm.analysisType
  149. });
  150. EventBus.$emit('update-statistics-year', {
  151. selectDate: vm.chooseYear + "年"
  152. }); //更新年份
  153. EventBus.$emit('update-dimension-name', {
  154. dimensionVal: data.name
  155. }); //更新维度名称
  156. EventBus.$emit('update-statistics-time', {}); //更新统计时间
  157. },
  158. component: 'renew-progress-filter',
  159. props: {
  160. chooseYear: vm.chooseYear,
  161. analysisType: vm.analysisType,
  162. lowCode: vm.lowCode,
  163. analysisName: vm.analysisName
  164. }
  165. });
  166. });
  167. $("#main").removeClass("c-hide");
  168. }
  169. })
  170. function initData(vm) {
  171. //获得缓存中缓存的角色权限
  172. var userRole = window.sessionStorage.getItem("selectedRole");
  173. if(!userRole) {
  174. return false;
  175. }
  176. vm.userRole = JSON.parse(userRole);
  177. vm.level = vm.userRole.code == '350200' ? 4 : vm.userRole.code.length == 6 ? 3 : 2;
  178. vm.area = vm.userRole.code;
  179. vm.areaTitle = vm.userRole.name;
  180. var now = new Date();
  181. if(now.getMonth() >= 6) {
  182. vm.chooseYear = now.getFullYear();
  183. } else {
  184. vm.chooseYear = now.getFullYear() - 1;
  185. }
  186. vm.startDate = getStartDate(vm.chooseYear);
  187. vm.endDate = getEndDate(vm.chooseYear);
  188. //更新头部信息
  189. EventBus.$emit('update-all-prompt-info', {
  190. areaName: vm.areaTitle,
  191. selectDate: vm.chooseYear + "年",
  192. dimensionVal: vm.analysisName
  193. });
  194. }
  195. function initReqParams(vm) {
  196. var topIndex = {
  197. "4": "29",
  198. "3": "44",
  199. "2": "43"
  200. }, //顶部区域对应的level : index
  201. bottomIndex = {
  202. "4": "44",
  203. "3": "43",
  204. "2": "42"
  205. }; //与选中的当前底部区域tab的值有关 areaType
  206. if(vm.lowCode && vm.lowCode != "0") {
  207. var topIndex = {
  208. "4": "51",
  209. "3": "54",
  210. "2": "53"
  211. }, //顶部区域对应的level : index
  212. bottomIndex = {
  213. "4": "54",
  214. "3": "53",
  215. "2": "52"
  216. }; //与选中的当前底部区域tab的值有关 areaType
  217. }
  218. var areaType = vm.lowLevel==2 ? "3" : vm.lowLevel==1?"2":vm.level;
  219. var index = topIndex[vm.level],
  220. bIndex = bottomIndex[areaType];
  221. reqParam = [{
  222. url: "/statistics/getRenewPercentAndChangePercent",
  223. reqType: 'get',
  224. data: {
  225. level: vm.level,
  226. code: vm.area,
  227. year: vm.chooseYear,
  228. index: index,
  229. lowCode: vm.lowCode
  230. }
  231. }, {
  232. url: "/statistics/interval_total",
  233. reqType: 'get',
  234. data: {
  235. level: vm.level,
  236. area: vm.area,
  237. startDate: vm.startDate,
  238. endDate: vm.endDate,
  239. interval: vm.selectedDateType,
  240. index: index,
  241. lowCode: vm.lowCode
  242. }
  243. }, {
  244. url: "/statistics/lowlevel_all_sign_renew",
  245. reqType: 'post',
  246. data: {
  247. sort: 1,
  248. date: vm.endDate,
  249. level: vm.level,
  250. index: bIndex,
  251. area: vm.area,
  252. lowCode: vm.lowCode,
  253. year: vm.chooseYear
  254. }
  255. }];
  256. if(vm.lowLevel) {
  257. reqParam[2].data.lowLevel = vm.lowLevel;
  258. }
  259. return reqParam;
  260. }
  261. function getTopTagDatas(data, vm) {
  262. vm.renewRange.renewRangeText = data.renewRange;
  263. vm.renewRange.renewRange = parseFloat(data.renewRange) / 100;
  264. vm.renewRange.renewAmount = data.thisYearRenew;
  265. vm.renewRange.renewRateAll = data.yesterYearSign;
  266. vm.switchRange.switchRangeText = data.switchRange;
  267. vm.switchRange.switchRange = parseFloat(data.switchRange) / 100;
  268. vm.switchRange.switchAmount = data.thisYearSwithch;
  269. vm.switchRange.switchRateAll = data.thisYearRenew;
  270. var val1 = vm.renewRange.renewRateAll - vm.renewRange.renewAmount;
  271. var renewArr = [{
  272. name: '续签量',
  273. value: vm.renewRange.renewAmount
  274. }, {
  275. name: '未达标量',
  276. value: val1 > 0 ? val1 : 0
  277. }];
  278. var val2 = vm.switchRange.switchRateAll - vm.switchRange.switchAmount;
  279. var switchArr = [{
  280. name: '转签量',
  281. value: vm.switchRange.switchAmount
  282. }, {
  283. name: '未达标量',
  284. value: val2 > 0 ? val2 : 0
  285. }];
  286. var renewChart = drawPieChart('renewMain', renewArr, ['#12b7f5', '#ebebf5'], true); //续签率
  287. var switchChart = drawPieChart('switchMain', switchArr, ['#12b7f5', '#ebebf5'], true); //转签率
  288. window.onresize = function() {
  289. renewChart.resize();
  290. switchChart.resize();
  291. window.lineCharts.resize(); //日周月折线图
  292. }
  293. }
  294. function loadData(loadArr, vm) {
  295. //获取其他请求的参数
  296. var reqParams = initReqParams(vm),
  297. reqPromise = [],
  298. newArr = []; //记录非顶部请求的请求数组
  299. for(i = 0; i < loadArr.length; i++) {
  300. var j = loadArr[i];
  301. var param = reqParams[j];
  302. reqPromise.push(httpRequest.get(param.url, {
  303. data: param.data
  304. }));
  305. newArr.push(loadArr[i]);
  306. }
  307. vm.isloading=true
  308. if(reqPromise.length > 0) {
  309. Promise.all(reqPromise).then(function(ress) {
  310. vm.isloading=false
  311. var res1, res2, res3;
  312. for(var i = 0; i < loadArr.length; i++) {
  313. var j = loadArr[i] + 1;
  314. if(j == 1) {
  315. res1 = ress[i];
  316. }
  317. if(j == 2) {
  318. res2 = ress[i];
  319. }
  320. if(j == 3) {
  321. res3 = ress[i];
  322. }
  323. }
  324. if(res1 && res1.status == 200) {
  325. getTopTagDatas(res1.data, vm);
  326. }
  327. if(res2 && res2.status == 200) {
  328. handleSecondPanelData(res2.data, vm);
  329. }
  330. if(res3) {
  331. if(res3.status == 200) {
  332. listHandle(res3.data, vm);
  333. } else {
  334. console.log(res3.msg);
  335. }
  336. }
  337. })
  338. }
  339. }
  340. function handleSecondPanelData(data, vm) {
  341. var xDatas = [],
  342. yDatas = [],
  343. names = [],
  344. colors = ['#12b7f5'];
  345. for(var p in data) {
  346. names.push("总续签人数");
  347. var xData = _.map(data[p].data, function(o) {
  348. return o.range;
  349. });
  350. var yData = _.map(data[p].data, function(o) {
  351. return o.amount;
  352. });
  353. xDatas.push(xData);
  354. yDatas.push(yData);
  355. }
  356. EventBus.$emit("draw-line-chart", {
  357. panelName: "续签趋势",
  358. quotaNames: names,
  359. xData: xDatas[0],
  360. yDatas: yDatas,
  361. colors: colors
  362. });
  363. }
  364. function listHandle(data, vm) {
  365. for(i in data) {
  366. var list = data[i];
  367. var topArr = [];
  368. topArr = soreRank(getKeyValueArr(list, 'renewNum'));
  369. var arr = _.map(list, function(o, index) {
  370. var cols = [o.name];
  371. cols.push(o.rate);
  372. cols.push(o.renewNum);
  373. cols.push(o.signNum);
  374. return {
  375. rank: topArr[index],
  376. code: o.code,
  377. name: o.name,
  378. cols: cols
  379. }
  380. });
  381. var headers = ["排名", "续签率", "续签量", "去年签约量"];
  382. EventBus.$emit("render-area-data", {
  383. level: vm.level,
  384. area: vm.area,
  385. lowLevel: vm.lowLevel,
  386. headers: headers,
  387. rows: arr
  388. });
  389. }
  390. }