sign-progress.js 11 KB

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