renew-progress.js 9.5 KB

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