sign-progress.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  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. analysisType: "1", // 筛选维度的id, 1-按任务,2-按人口,3-高血压,4-糖尿病,5-65岁以上人群
  24. analysisName: "按任务",
  25. signRateData: {
  26. signRateText: "",
  27. signRate: "",
  28. signAmount: "",
  29. signRateAll: "",
  30. completeRateText: "",
  31. completeRate: "",
  32. completeAmount: "",
  33. completeRateAll: ""
  34. },
  35. yearHtml: "",
  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. analysisType: this.analysisType,
  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. analysisType: this.analysisType
  91. });
  92. //设置监听器, 监听折线图日期变化
  93. var vm = this;
  94. //监听后退按钮的操作
  95. EventBus.$on("back-click", function(arg) {
  96. EventBus.$emit('update-statistics-time', {}); //更新统计时间
  97. if(reqList.length == 1) {
  98. history.go(-1);
  99. } else {
  100. var preInfo = reqList.pop();
  101. var info = reqList[reqList.length - 1];
  102. vm.level = info.level;
  103. vm.area = info.area;
  104. vm.areaTitle = info.areaTitle;
  105. vm.lowLevel = info.lowLevel;
  106. vm.index = info.index;
  107. vm.lowCode = info.lowCode;
  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. //弹出筛选框
  118. EventBus.$on('filter-click', function(arg) {
  119. //弹框显示筛选条件
  120. Vuedals.Bus.$emit('new', {
  121. title: '条件筛选',
  122. onClose: function(data) {
  123. vm.chooseYear = data.chooseYear;
  124. vm.startDate = getStartDate(vm.chooseYear);
  125. vm.endDate = getEndDate(vm.chooseYear);
  126. vm.lowCode = data.lowCode;
  127. vm.analysisType = data.id;
  128. vm.analysisName = data.name;
  129. // vm.yearHtml = data.yearHtml;
  130. // vm.contentHtml = data.contentHtml;
  131. //请求参数重置,页面类型重新开始
  132. vm.level = vm.userRole.code == '350200' ? 4 : vm.userRole.code.length == 6 ? 3 : 2;
  133. vm.area = vm.userRole.code;
  134. vm.areaTitle = vm.userRole.name;
  135. EventBus.$emit('update-area-name', {
  136. areaName: vm.areaTitle
  137. });
  138. vm.selectedDateType = 1;
  139. //然后清空请求列表数组
  140. reqList.splice(0, reqList.length);
  141. loadData([0, 1, 2], vm); //刷新数据
  142. //存储请求所带的参数
  143. reqList.push({
  144. level: vm.level,
  145. area: vm.area,
  146. areaTitle: vm.areaTitle,
  147. index: vm.index,
  148. endDate: vm.endDate,
  149. startDate: vm.startDate,
  150. lowLevel: vm.lowLevel,
  151. lowCode: vm.lowCode,
  152. analysisType: vm.analysisType
  153. });
  154. EventBus.$emit('update-statistics-year', {
  155. selectDate: vm.chooseYear + "年"
  156. }); //更新年份
  157. EventBus.$emit('update-statistics-time', {}); //更新统计时间
  158. EventBus.$emit('update-dimension-name', {
  159. dimensionVal: data.name
  160. }); //更新维度名称
  161. },
  162. component: 'sign-progress-filter',
  163. props: {
  164. chooseYear: vm.chooseYear,
  165. analysisType: vm.analysisType,
  166. lowCode: vm.lowCode,
  167. analysisName: vm.analysisName
  168. // yearHtml: vm.yearHtml,
  169. // contentHtml: vm.contentHtml
  170. }
  171. });
  172. });
  173. $("#main").removeClass("c-hide");
  174. }
  175. })
  176. function initData(vm) {
  177. //获得缓存中缓存的角色权限
  178. var userRole = window.sessionStorage.getItem("selectedRole");
  179. if(!userRole) {
  180. return false;
  181. }
  182. vm.userRole = JSON.parse(userRole);
  183. vm.level = vm.userRole.code == '350200' ? 4 : vm.userRole.code.length == 6 ? 3 : 2;
  184. vm.area = vm.userRole.code;
  185. vm.areaTitle = vm.userRole.name;
  186. var now = new Date();
  187. if(now.getMonth() >= 6) {
  188. vm.chooseYear = now.getFullYear();
  189. } else {
  190. vm.chooseYear = now.getFullYear() - 1;
  191. }
  192. vm.startDate = getStartDate(vm.chooseYear);
  193. vm.endDate = getEndDate(vm.chooseYear);
  194. //更新头部信息
  195. EventBus.$emit('update-all-prompt-info', {
  196. areaName: vm.areaTitle,
  197. selectDate: vm.chooseYear + "年",
  198. dimensionVal: vm.analysisName
  199. });
  200. }
  201. function initReqParams(vm) {
  202. vm.index = 13;
  203. if(vm.lowCode) {
  204. vm.index = 17;
  205. }
  206. reqParam = [{
  207. url: "/statistics/sign_info",
  208. reqType: 'get',
  209. data: {
  210. level: vm.level,
  211. area: vm.area,
  212. lowCode: vm.lowCode,
  213. year: vm.chooseYear,
  214. endDate: vm.endDate
  215. }
  216. }, {
  217. url: "/statistics/interval_total",
  218. reqType: 'get',
  219. data: {
  220. level: vm.level,
  221. area: vm.area,
  222. startDate: vm.startDate,
  223. endDate: vm.endDate,
  224. interval: vm.selectedDateType,
  225. index: vm.index,
  226. lowCode: vm.lowCode
  227. }
  228. }, {
  229. url: "/statistics/lowlevel_all",
  230. reqType: 'get',
  231. data: {
  232. sort: 1,
  233. date: vm.endDate,
  234. level: vm.level,
  235. index: vm.index,
  236. area: vm.area,
  237. lowCode: vm.lowCode
  238. }
  239. }];
  240. if(vm.lowLevel) {
  241. reqParam[2].data.lowLevel = vm.lowLevel;
  242. }
  243. return reqParam;
  244. }
  245. function getTopTagDatas(data, vm) {
  246. vm.signRateData.signRateText = parseFloat(data.signRate.rate).toFixed(2) + "%"
  247. vm.signRateData.signRate = parseFloat(data.signRate.rate) / 100;
  248. vm.signRateData.signAmount = data.signRate.sign;
  249. vm.signRateData.signRateAll = data.signRate.people;
  250. vm.signRateData.completeRateText = parseFloat(data.signTaskRate.rate).toFixed(2) + "%"
  251. vm.signRateData.completeRate = parseFloat(data.signTaskRate.rate) / 100;
  252. vm.signRateData.completeAmount = data.signTaskRate.sign;
  253. vm.signRateData.completeRateAll = data.signTaskRate.people;
  254. var val1 = vm.signRateData.signRateAll - vm.signRateData.signAmount
  255. var signArr = [{
  256. name: '签约量',
  257. value: vm.signRateData.signAmount
  258. }, {
  259. name: '未签约量',
  260. value: val1 > 0 ? val1 : 0
  261. }];
  262. var val2 = vm.signRateData.completeRateAll - vm.signRateData.completeAmount;
  263. var completeArr = [{
  264. name: '完成量',
  265. value: vm.signRateData.completeAmount
  266. }, {
  267. name: '未达标量',
  268. value: val2 > 0 ? val2 : 0
  269. }];
  270. var signChart = drawPieChart('signMain', signArr, ['#12b7f5', '#ebebf5'], true); //签约率
  271. var completeChart = drawPieChart('completeMain', completeArr, ['#12b7f5', '#ebebf5'], true); //完成率
  272. window.onresize = function() {
  273. signChart.resize();
  274. completeChart.resize();
  275. window.lineCharts.resize(); //日周月折线图
  276. }
  277. }
  278. function loadData(loadArr, vm) {
  279. //获取其他请求的参数
  280. var reqParams = initReqParams(vm),
  281. reqPromise = [],
  282. newArr = []; //记录非顶部请求的请求数组
  283. for(i = 0; i < loadArr.length; i++) {
  284. var j = loadArr[i];
  285. var param = reqParams[j];
  286. reqPromise.push(httpRequest.get(param.url, {
  287. data: param.data
  288. }));
  289. newArr.push(loadArr[i]);
  290. }
  291. if(reqPromise.length > 0) {
  292. Promise.all(reqPromise).then(function(ress) {
  293. var res1, res2, res3;
  294. for(var i = 0; i < loadArr.length; i++) {
  295. var j = loadArr[i] + 1;
  296. if(j == 1) {
  297. res1 = ress[i];
  298. }
  299. if(j == 2) {
  300. res2 = ress[i];
  301. }
  302. if(j == 3) {
  303. res3 = ress[i];
  304. }
  305. }
  306. if(res1 && res1.status == 200) {
  307. getTopTagDatas(res1.data, vm);
  308. }
  309. if(res2 && res2.status == 200) {
  310. handleSecondPanelData(res2.data, vm);
  311. }
  312. if(res3) {
  313. if(res3.status == 200) {
  314. listHandle(res3.data, vm);
  315. } else {
  316. console.log(res3.msg);
  317. }
  318. }
  319. })
  320. }
  321. }
  322. function handleSecondPanelData(data, vm) {
  323. var xDatas = [],
  324. yDatas = [],
  325. names = [],
  326. taskNum = vm.lowCode ? data.index_17.taskNum : data.index_1.taskNum,
  327. colors = ['#12b7f5'],
  328. index_names = {
  329. 'index_1': '总签约人数'
  330. };
  331. for(var p in data) {
  332. names.push(index_names[p]);
  333. var xData = _.map(data[p].data, function(o) {
  334. return o.range;
  335. });
  336. var yData = _.map(data[p].data, function(o) {
  337. return o.amount;
  338. });
  339. xDatas.push(xData);
  340. yDatas.push(yData);
  341. }
  342. EventBus.$emit("draw-line-chart", {
  343. panelName: "签约量趋势",
  344. quotaNames: names,
  345. xData: xDatas[0],
  346. yDatas: yDatas,
  347. colors: colors,
  348. markLineValue: taskNum,
  349. markLineName: "目标量"
  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, 'amount'));
  357. var arr = _.map(list, function(o, index) {
  358. var cols = [o.name];
  359. if(vm.analysisType == "2" && vm.level > 2 && vm.lowLevel != 1) { //按人口
  360. cols.push(o.num);
  361. } else {
  362. cols.push(o.amount);
  363. }
  364. if(vm.level > 2 && vm.lowLevel != 1) {
  365. cols.push(o.signTaskNum);
  366. cols.push(parseFloat(o.rate).toFixed(2) + "%");
  367. } else if(vm.chooseYear != "2016") {
  368. cols.push(o.signRegulationNum);
  369. }
  370. return {
  371. rank: topArr[index],
  372. code: o.code,
  373. name: o.name,
  374. cols: cols
  375. }
  376. });
  377. var headers = ["排名", (vm.analysisType == "2" ? "人口数" : "签约量"), "目标率", "当前签约率"]; //analysisType=2 为按人口
  378. if(vm.lowLevel == 1 || vm.level == 2) { //团队
  379. if(vm.chooseYear =="2016"){
  380. headers = ["排名", (vm.analysisType == "2" ? "人口数" : "签约量")];
  381. }else{
  382. headers = ["排名", (vm.analysisType == "2" ? "人口数" : "签约量"), "调控量"];
  383. }
  384. }
  385. EventBus.$emit("render-area-data", {
  386. level: vm.level,
  387. area: vm.area,
  388. lowLevel: vm.lowLevel,
  389. headers: headers,
  390. rows: arr
  391. });
  392. }
  393. }