blessing-analysis.js 9.7 KB

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