health-management-analysis.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  1. var reqList = []; //记录请求的参数和url,用于后退时使用
  2. var pieChart1,
  3. pieChart2; //全局设置饼图的对象,window.resize时,触发chart的resize方法
  4. Vue.use(Vuedals.default);
  5. new Vue({
  6. el: "#main",
  7. data: {
  8. appname: "健康管理分析",
  9. isback: true,
  10. isrefresh: true,
  11. isfilter: true,
  12. isopen: true,
  13. //请求页面所需参数
  14. level: '',
  15. area: '',
  16. areaTitle: '',
  17. index: '21',
  18. selectedDateType: 1,
  19. endDate: '',
  20. startDate: '',
  21. lowLevel: '',
  22. chooseYear: '',
  23. userRole: '',
  24. //数据结果
  25. topDatas: {
  26. index_149: 0,
  27. index_21: 0,
  28. },
  29. //微信绑定统计数据
  30. wxTotal:{
  31. label: '',
  32. amount1: '', //已缴费人数
  33. amount2: '', //未缴费人数
  34. rate: ''//绑定率
  35. },
  36. isloading:false, //加载中
  37. },
  38. components: {
  39. vuedals: Vuedals.Component
  40. },
  41. methods: {
  42. changeTag: function(val){
  43. this.index = val;
  44. loadData([1,2], this);
  45. //存储请求所带的参数
  46. reqList.push({
  47. level: this.level,
  48. area: this.area,
  49. areaTitle: this.areaTitle,
  50. index: this.index,
  51. endDate: this.endDate,
  52. startDate: this.startDate,
  53. lowLevel: this.lowLevel
  54. })
  55. },
  56. getNewLineData: function(arg){
  57. this.selectedDateType = arg.dateType;
  58. loadData([1], this);
  59. },
  60. getAreaData: function(arg){
  61. //如果level改变,则需要重新加载整个页面的数据,否则只需加载底部区域数据
  62. if(arg.level == this.level){
  63. this.lowLevel = arg.lowLevel;
  64. loadData([2], this);
  65. }else{
  66. this.level = arg.level;
  67. this.lowLevel = arg.lowLevel;
  68. this.area = arg.area;
  69. this.areaTitle = arg.areaTitle;
  70. loadData([0,1,2], this);
  71. }
  72. EventBus.$emit('update-area-name', {areaName: this.areaTitle});
  73. //存储请求所带的参数
  74. reqList.push({
  75. level: this.level,
  76. area: this.area,
  77. areaTitle: this.areaTitle,
  78. index: this.index,
  79. endDate: this.endDate,
  80. startDate: this.startDate,
  81. lowLevel: this.lowLevel,
  82. selectedDateType: this.selectedDateType
  83. })
  84. }
  85. },
  86. mounted: function(){
  87. //初始化数据
  88. initData(this);
  89. //获得顶部各tab的值
  90. loadData([0,1,2], this); //参数组数表示请求的区域为上中下
  91. //存储请求所带的参数
  92. reqList.push({
  93. level: this.level,
  94. area: this.area,
  95. areaTitle: this.areaTitle,
  96. index: this.index,
  97. endDate: this.endDate,
  98. startDate: this.startDate,
  99. lowLevel: this.lowLevel,
  100. selectedDateType: this.selectedDateType
  101. });
  102. //设置监听器, 监听折线图日期变化
  103. var vm = this;
  104. //监听后退按钮的操作
  105. EventBus.$on("back-click", function(arg){
  106. EventBus.$emit('update-statistics-time', {}); //更新统计时间
  107. if(reqList.length == 1){
  108. history.go(-1);
  109. }
  110. else{
  111. var preInfo = reqList.pop();
  112. var info = reqList[reqList.length - 1];
  113. vm.level = info.level;
  114. vm.area = info.area;
  115. vm.areaTitle = info.areaTitle;
  116. vm.lowLevel = info.lowLevel;
  117. vm.index = info.index;
  118. loadData([0,1,2], vm);
  119. EventBus.$emit('update-area-name', {areaName: vm.areaTitle});
  120. }
  121. });
  122. //监听页面刷新
  123. EventBus.$on("refresh-click", function(arg){
  124. loadData([0,1,2], vm);
  125. });
  126. //弹出筛选框
  127. EventBus.$on('filter-click', function(arg) {
  128. //弹框显示筛选条件
  129. Vuedals.Bus.$emit('new', {
  130. title: '条件筛选',
  131. onClose:function(data){
  132. vm.chooseYear = data.chooseYear;
  133. vm.startDate = getStartDate(vm.chooseYear);
  134. vm.endDate = getEndDate(vm.chooseYear);
  135. //请求参数重置,页面类型重新开始
  136. vm.level = vm.userRole.code == '350200' ? 4 : vm.userRole.code.length == 6 ? 3 : 2;
  137. vm.area = vm.userRole.code;
  138. vm.areaTitle = vm.userRole.name;
  139. EventBus.$emit('update-area-name', {areaName: vm.areaTitle});
  140. vm.selectedDateType = 1;
  141. //然后清空请求列表数组
  142. reqList.splice(0, reqList.length);
  143. loadData([0, 1, 2], vm);//刷新数据
  144. //存储请求所带的参数
  145. reqList.push({
  146. level: vm.level,
  147. area: vm.area,
  148. areaTitle: vm.areaTitle,
  149. index: vm.index,
  150. endDate: vm.endDate,
  151. startDate: vm.startDate,
  152. lowLevel: vm.lowLevel,
  153. selectedDateType: vm.selectedDateType
  154. });
  155. EventBus.$emit('update-statistics-year', {selectDate: vm.chooseYear + "年"});//更新年份
  156. EventBus.$emit('update-statistics-time', {});//更新统计时间
  157. },
  158. component: 'year-filter',
  159. props: {
  160. selectedYear: vm.chooseYear
  161. }
  162. });
  163. });
  164. $("#main").removeClass("c-hide");
  165. window.onresize = function() {
  166. if(pieChart1){
  167. pieChart1.resize();
  168. }
  169. if(pieChart2){
  170. pieChart2.resize();
  171. }
  172. window.lineCharts.resize(); //日周月折线图
  173. }
  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. EventBus.$emit('update-area-name', {areaName: vm.areaTitle});
  187. var now = new Date();
  188. if(now.getMonth() >= 6 || now.getFullYear()>=2023){
  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. EventBus.$emit('update-statistics-year', {selectDate: vm.chooseYear + "年"});
  196. }
  197. function initReqParams(vm){
  198. //增量(咨询量3、随访量4、健康教育5、代预约量27),到达量(绑定微信21、绑定设备20)
  199. if(vm.index == '149' || vm.index == '21'){
  200. url2 = "statistics/interval_total";
  201. url3 = "statistics/lowlevel_all";
  202. }
  203. reqParam = [{
  204. url: url2,
  205. data:{
  206. index: vm.index,
  207. level: vm.level,
  208. area: vm.area,
  209. startDate: vm.startDate,
  210. endDate: vm.endDate,
  211. interval: vm.selectedDateType
  212. }
  213. },{
  214. url: url3,
  215. data: {
  216. index: vm.index,
  217. level: vm.level,
  218. area: vm.area,
  219. sort: 1,
  220. year: vm.chooseYear
  221. }
  222. },{
  223. //如果是微信绑定,则增加置顶展示当面层级的总绑定率及已缴费 未缴费居民数.只针对微信绑定时使用
  224. url: '/statistics/getLevelTotalSingle',
  225. data: {
  226. date: vm.endDate,
  227. level: vm.level,
  228. area: vm.area
  229. }
  230. }];
  231. if(vm.index == '149' || vm.index == '21' ){
  232. reqParam[1].data.date = vm.endDate;
  233. }else{
  234. reqParam[1].data.endDate = vm.endDate;
  235. }
  236. if(vm.lowLevel){
  237. reqParam[1].data.lowLevel = vm.lowLevel;
  238. }
  239. return reqParam;
  240. }
  241. function getTopReqParams(index1, vm){
  242. var url = "statistics/total",
  243. data = {
  244. index: index1,
  245. level: vm.level,
  246. area: vm.area,
  247. year: vm.chooseYear,
  248. endDate: vm.endDate,
  249. startDate: vm.startDate
  250. };
  251. if(index1 == '149' || index1 == '21'){
  252. url = "statistics/index_all";
  253. }
  254. return {
  255. url: url,
  256. data: data
  257. };
  258. }
  259. function getTopTagDatas(vm){
  260. var reqs = [],
  261. indexs = ['21', '149'];
  262. for(i=0; i<indexs.length; i++){
  263. var item = getTopReqParams(indexs[i], vm);
  264. reqs.push(httpRequest.get(item.url, {data: item.data}));
  265. }
  266. Promise.all(reqs).then(function(ress){
  267. for(i=0; i<ress.length; i++){
  268. var res = ress[i];
  269. if(res.status == 200){
  270. for(key in res.data){
  271. vm.topDatas[key] = res.data[key];
  272. }
  273. }else{
  274. console.log(res.msg);
  275. }
  276. }
  277. })
  278. }
  279. function loadData(loadArr, vm){
  280. if(loadArr.indexOf(0) > -1){
  281. getTopTagDatas(vm);
  282. }
  283. vm.isloading=true
  284. //获取其他请求的参数
  285. var reqParams = initReqParams(vm),
  286. reqPromise = [],
  287. newArr = []; //记录非顶部请求的请求数组
  288. for(i=0; i<loadArr.length; i++){
  289. if(loadArr[i] == 0){
  290. // do nothing
  291. }else{
  292. var j = loadArr[i] - 1;
  293. var param = reqParams[j];
  294. reqPromise.push(httpRequest.get(param.url, {data: param.data}));
  295. newArr.push(loadArr[i]);
  296. }
  297. }
  298. if(vm.index == 21){ //微信绑定的数据需要再请求一个数据
  299. reqPromise.push(httpRequest.get(reqParams[2].url, {data: reqParams[2].data}))
  300. newArr.push(3);
  301. }
  302. if(reqPromise.length > 0){
  303. Promise.all(reqPromise).then(function(ress){
  304. vm.isloading=false
  305. var res2, res3, res4;
  306. for(var i=0; i<newArr.length; i++){
  307. var j = newArr[i] + 1;
  308. if(j == 2){
  309. res2 = ress[i];
  310. }
  311. if(j == 3){
  312. res3 = ress[i];
  313. }
  314. //微信绑定时,多获取一个请求数据
  315. if(j == 4){
  316. res4 = ress[i];
  317. }
  318. }
  319. if(res2){
  320. if(res2.status == 200){
  321. handleSecondPanelData(res2.data, vm);
  322. }else{
  323. console.log(res2.msg);
  324. }
  325. }
  326. if(res3){
  327. if(res3.status == 200){
  328. listHandle(res3.data, vm);
  329. }else{
  330. console.log(res3.msg);
  331. }
  332. }
  333. if(res4){
  334. if(res4.status == 200){
  335. handleWXBindData(res4.data, vm);
  336. }else{
  337. console.log(res4.msg);
  338. }
  339. }
  340. })
  341. }
  342. }
  343. function handleSecondPanelData(data, vm){
  344. var xDatas = [],
  345. yDatas = [],
  346. names = [],
  347. colors = ['#12b7f5', '#cd67fd','#FF9526'],
  348. labels = {'149': '健康管理人数新增趋势', '21': '绑定微信新增趋势'},
  349. index_names = {'index_21': '绑定微信','index_149': '管理人数'};
  350. for(var p in data){
  351. names.push(index_names[p]);
  352. if(p == 'index_21' || p == 'index_149' ){
  353. xData = _.map(data[p].data, function(o){
  354. return o.range;
  355. });
  356. yData = _.map(data[p].data, function(o){
  357. return o.amount;
  358. });
  359. }else{
  360. if(data[p][0].range){
  361. xData = _.map(data[p], function(o){
  362. return o.range;
  363. });
  364. yData = _.map(data[p], function(o){
  365. return o.amount;
  366. });
  367. }
  368. }
  369. xDatas.push(xData);
  370. yDatas.push(yData);
  371. }
  372. EventBus.$emit("draw-line-chart", {
  373. panelName : labels[vm.index],
  374. quotaNames : names,
  375. xData : xDatas[0],
  376. yDatas : yDatas,
  377. colors : colors,
  378. selectedDateType: vm.selectedDateType,
  379. nowlineid : "lineChart"
  380. });
  381. }
  382. function listHandle(data, vm){
  383. for(i in data){
  384. var list = data[i];
  385. var topArr = [];
  386. if(vm.index == "21"){
  387. topArr = soreRank(getKeyValueArr(list, 'bindRate'));
  388. }else if(vm.index == "149"){
  389. topArr = soreRank(getKeyValueArr(list, 'manageRate'));
  390. }else{
  391. topArr = soreRank(getKeyValueArr(list, 'amount'));
  392. }
  393. var arr = _.map(list, function(o, index){
  394. var cols = [o.name];
  395. if(vm.index == '21'){
  396. cols.push(o.bindRate + '%');
  397. cols.push(o.weChatAmount1);
  398. cols.push(o.weChatAmount0);
  399. }else if(vm.index == '149'){
  400. cols.push(o.manageTotal1Amount);
  401. cols.push(o.manageRate + '%');
  402. }
  403. return {
  404. rank: topArr[index],
  405. code: o.code,
  406. name: o.name,
  407. cols: cols
  408. }
  409. });
  410. var headers = {
  411. '149': ["排名", "管理人数","管理率"],
  412. '21': ["排名", "绑定率", "已缴费", "未缴费"],
  413. };
  414. EventBus.$emit("render-area-data",{
  415. index: vm.index,
  416. level: vm.level,
  417. area: vm.area,
  418. lowLevel: vm.lowLevel,
  419. headers: headers[vm.index],
  420. year:vm.chooseYear,
  421. rows: arr
  422. });
  423. }
  424. }
  425. function handleWXBindData(data, vm){
  426. switch(vm.level){
  427. case 4:
  428. vm.wxTotal.label = "全市概况";
  429. break;
  430. case 3:
  431. vm.wxTotal.label = "全区概况";
  432. break;
  433. case 2:
  434. vm.wxTotal.label = "全社区概况";
  435. break;
  436. }
  437. vm.wxTotal.rate = (data.bindRate || 0) + "%";
  438. vm.wxTotal.amount1 = data.weChatAmount1;
  439. vm.wxTotal.amount2 = data.weChatAmount0;
  440. var arr = [{
  441. name: '已缴费人数',
  442. value: data.weChatAmount1
  443. },{
  444. name: '未缴费人数',
  445. value: data.weChatAmount0
  446. }];
  447. pieChart1 = drawPieChart('pieChart2', arr, ['#17b3ec', '#909090']);
  448. }
  449. /*
  450. * 获取用来排序的字段值,返回数组
  451. * 参数: list - 列表, key - 字段的名称
  452. */
  453. function getKeyValueArr2(list, key){
  454. var arr = [];
  455. for(var k in list){
  456. var item = list[k][key].split(",");
  457. arr.push(item[0]);
  458. }
  459. return arr;
  460. }