pay-online-analysis.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665
  1. var self,
  2. initLevel,
  3. type,
  4. level,
  5. area,
  6. title,
  7. startDate = '',
  8. endDate = '',
  9. lowLevel,
  10. dateType = 1, //折线图坐标值1-日,2-周,3-月
  11. analysisType = "1", // 筛选维度的id, 1-按任务,2-按人口,3-高血压,4-糖尿病,5-65岁以上人群
  12. areaType; //标记底部区域选中的tab的值, 4 - 各区, 3 - 社区, 2 - 团队
  13. var userRole;
  14. var CITY_CODE = "350200";//默认厦门市
  15. var reqParam = []; //请求参数
  16. var reqList = []; //请求的链接数据,根据这些信息后退的时候使用
  17. //定义年份
  18. var chooseYear;
  19. var now = new Date();
  20. if(now.getMonth() >= 6){
  21. chooseYear = now.getFullYear();
  22. }else{
  23. chooseYear = now.getFullYear() - 1;
  24. }
  25. mui.plusReady(function(){
  26. var self = plus.webview.currentWebview();
  27. // userRole = plus!=null ? JSON.parse(plus.storage.getItem("selectedRole")) : {};
  28. // initLevel = userRole.code == CITY_CODE ? 4 : userRole.code.length==6 ? 3 : 2;
  29. initLevel = self.level;
  30. level = initLevel;
  31. area = self.code;
  32. title = self.title;
  33. if(self.year){
  34. chooseYear = self.year;
  35. }
  36. startDate = getStartDate();
  37. endDate = getEndDate();
  38. //初始默认选中的时间和类型
  39. $(".choose-label").text(chooseYear);
  40. $("#areaTitle").text(title);
  41. //控制底部各区等tab的显示
  42. showTabs();
  43. initReqParams(); //现获得页面请求的接口参数
  44. //记录返回链接信息
  45. reqList.push({
  46. level: level,
  47. lowLevel: lowLevel,
  48. area: area,
  49. title: title,
  50. analysisType: analysisType,
  51. req: reqParam
  52. });
  53. loadData([0,1,2]); //现获得页面请求的接口参数
  54. initScroller();
  55. shaixuanInit(self);
  56. bindEvents();
  57. });
  58. //获得页面请求的接口参数
  59. function initReqParams(){
  60. var mIndex = 82, //折线图指标index
  61. bIndexs = {"4": "75", "3": "76", "2": "77"};
  62. var bIndex = 82; //bIndexs[level];
  63. reqParam = [{
  64. url: "/statistics/signPayOnline",
  65. reqType: 'get',
  66. data: {level:level, area:area, year: chooseYear}
  67. },{
  68. url: "/statistics/interval_total",
  69. reqType: 'get',
  70. data: {level: level, area: area, startDate: startDate, endDate: endDate, interval: dateType, index: mIndex}
  71. },{
  72. url: "/statistics/lowlevel_all_sign_pay_online",
  73. reqType: 'post',
  74. data: {sort: 1, date: endDate, level: level, index: bIndex, area: area}
  75. }];
  76. if(lowLevel){
  77. reqParam[2].data.lowLevel = lowLevel;
  78. }
  79. }
  80. /*
  81. * 加载页面数据
  82. * @param loadArr array 记录需要请求的区域0-顶部,1-中间,2-底部
  83. */
  84. function loadData(loadArr){
  85. plus.nativeUI.showWaiting();
  86. getJieZhiTime();
  87. var reqPromise = [];
  88. for(var i=0; i<loadArr.length; i++){
  89. var j = loadArr[i];
  90. reqPromise.push(reqParam[j]);
  91. }
  92. getReqPromises(reqPromise, true).then(function(ress){
  93. var res1, res2, res3;
  94. for(var i=0; i<loadArr.length; i++){
  95. var j = loadArr[i] + 1;
  96. if(j == 1){
  97. res1 = ress[i];
  98. }
  99. if(j == 2){
  100. res2 = ress[i];
  101. }
  102. if(j == 3){
  103. res3 = ress[i];
  104. }
  105. }
  106. if(res1 && res1.status == 200){
  107. handleTopData(res1.data);
  108. }
  109. if(res2 && res2.status == 200){
  110. handleSecondPanelData(res2.data);
  111. }
  112. if(res3){
  113. if(res3.status == 200){
  114. listHandle(res3.data);
  115. }else{
  116. $("#listTable").empty();
  117. mui.toast(res3.msg);
  118. }
  119. }
  120. plus.nativeUI.closeWaiting();
  121. });
  122. }
  123. /*
  124. * 加载数据截止时间
  125. */
  126. function getJieZhiTime(){
  127. sendPost("/statistics/time",null,function(res){
  128. },function(res){
  129. if(res.status=="200"){
  130. var date = (res.data && res.data.substring(11,16)) || "";
  131. $(".jiezhi-time").html("("+date+")");
  132. }
  133. });
  134. }
  135. /*
  136. * 处理顶部水球图数据
  137. */
  138. function handleTopData(res){
  139. $(".online-num").text(res.signPayOnlineNum);
  140. $(".online-rate").text(res.signPayOnlineRate);
  141. $(".offline-num").text(res.signPayUnderNum);
  142. $(".offline-rate").text(res.signPayUnderRate);
  143. var pieChart = echarts.init(document.getElementById('pieChart')),
  144. options = {
  145. tooltip: {
  146. trigger: 'item',
  147. formatter: "{b}:<br/> {c} ({d}%)"
  148. },
  149. series: [
  150. {
  151. type:'pie',
  152. radius: ['80%', '70%'],
  153. color:['#ffc800', '#17b3ec'],
  154. avoidLabelOverlap: false,
  155. label: {
  156. normal: {
  157. show: false,
  158. position: 'center'
  159. },
  160. // emphasis: {
  161. // show: true,
  162. // textStyle: {
  163. // fontSize: '16',
  164. // fontWeight: 'bold'
  165. // }
  166. // }
  167. },
  168. labelLine: {
  169. normal: {
  170. show: false
  171. }
  172. },
  173. data:[
  174. {value:res.signPayOnlineNum, name:'线上缴费人数'},
  175. {value:res.signPayUnderNum, name:'线下缴费人数'}
  176. ]
  177. }
  178. ]
  179. };
  180. pieChart.setOption(options);
  181. }
  182. /*
  183. * 处理中间折线图数据
  184. */
  185. function handleSecondPanelData(data){
  186. for(var p in data){
  187. var xData = _.map(data[p].data, function(o){
  188. return o.range;
  189. });
  190. var yData = _.map(data[p].data, function(o){
  191. return o.amount;
  192. });
  193. var lastIndex = yData.length % 10;
  194. if(yData.length >10 ){
  195. var dataZoom_end = 100-(9/yData.length)*100;
  196. }else{
  197. var dataZoom_end = 0;
  198. }
  199. //初始给定第一版页面中时间区间
  200. if(dateType == 3){
  201. var d1 = xData[yData.length - lastIndex],
  202. d2 = xData[yData.length -1];
  203. $("#startValue").text(d1.substr(0,4)+"年"+d1.substr(5,2)+"月");
  204. $("#endValue").text(d2.substr(0,4)+"年"+d2.substr(5,2)+"月");
  205. }else{
  206. $("#startValue").text(xData[yData.length - lastIndex]);
  207. $("#endValue").text(xData[yData.length -1]);
  208. }
  209. var lineCharts = echarts.init(document.getElementById('lineChart'));
  210. var options = {
  211. tooltip: {
  212. trigger: 'axis'
  213. },
  214. legend: {
  215. top: 'bottom',
  216. data:['线上缴费量']
  217. },
  218. grid: {
  219. left: '10px',
  220. right: '10px',
  221. bottom: '30px',
  222. top: '10px',
  223. containLabel: true
  224. },
  225. xAxis: {
  226. type: 'category',
  227. boundaryGap: false,
  228. data: xData,
  229. axisLabel: {
  230. interval:0,//横轴信息全部显示
  231. formatter: function (value, index) {
  232. if(dateType == 1 || dateType == 2){
  233. if(index == 0){
  234. $("#startValue").text(value);
  235. return value.substr(5,2)+"月"+value.substr(8,2);
  236. }else{
  237. if(index == 10){
  238. $("#endValue").text(value);
  239. }
  240. return value.substr(8,2);
  241. }
  242. }else if(dateType == 3){
  243. var val = value.substr(5,2)+"月"
  244. if(index == 0){
  245. $("#startValue").text(value.substr(0,4)+"年"+val);
  246. }else{
  247. if(index == 9){
  248. $("#endValue").text(value.substr(0,4)+"年"+val);
  249. }
  250. }
  251. return val;
  252. }
  253. }
  254. }
  255. },
  256. yAxis: {
  257. type: 'value',
  258. axisPointer: {
  259. snap: true
  260. },
  261. scale: true,
  262. minInterval: 1,
  263. boundaryGap: ['10%', '30%']
  264. },
  265. dataZoom: [{//给x轴设置滚动条
  266. show: false,
  267. start: dataZoom_end,
  268. end: 100,
  269. type: 'slider',
  270. zoomLock: true,
  271. },{ //下面这个属性是内容区域配置
  272. start: dataZoom_end,
  273. end: 100,
  274. type: 'inside',
  275. zoomLock: true,
  276. }],
  277. series: [{
  278. name: '线上缴费量',
  279. type: 'line',
  280. smooth: true,
  281. data: yData,
  282. lineStyle:{
  283. normal: {
  284. color: '#12b7f5'
  285. }
  286. },
  287. itemStyle:{
  288. normal: {
  289. color: '#12b7f5'
  290. }
  291. }
  292. }]
  293. };
  294. lineCharts.setOption(options);
  295. }
  296. }
  297. /*
  298. * 处理底部区域数据
  299. */
  300. function listHandle(res){
  301. for(var k in res){
  302. var list = res[k];
  303. var topArr = soreRank(amountArr(list));
  304. list = _.map(list, function(o, index){
  305. o.top = topArr[index];
  306. o.rate = parseFloat(o.rate).toFixed(2);
  307. o.targetRate = parseFloat(o.targetRate).toFixed(2);
  308. return o;
  309. })
  310. var html = template("data-list", {list: list, level: level, lowLevel: lowLevel, analysisType: analysisType});
  311. $("#listTable").empty().append(html);
  312. }
  313. }
  314. /*
  315. * 控制底部各区等tab的显示,根据level来控制
  316. */
  317. function showTabs(){
  318. $(".area-tab").removeClass("active");
  319. switch(parseInt(level)){
  320. case 4:
  321. $(".area-tab").show();
  322. $(".area-tab").eq(0).addClass("active");
  323. areaType = "4";
  324. break;
  325. case 3:
  326. $(".area-tab").eq(0).hide();
  327. $(".area-tab").eq(1).show();
  328. $(".area-tab").eq(1).addClass("active");
  329. areaType = "3";
  330. break;
  331. case 2:
  332. $(".area-tab").eq(0).hide();
  333. $(".area-tab").eq(1).hide();
  334. $(".area-tab").eq(2).addClass("active");
  335. areaType = "2";
  336. break;
  337. case 1: //团队
  338. $(".area-tab-panel").parent().remove();
  339. break;
  340. }
  341. }
  342. /*
  343. * 初始化scroller
  344. */
  345. function initScroller(){
  346. //阻尼系数
  347. var deceleration = mui.os.ios?0.003:0.0009;
  348. mui('.mui-scroll-wrapper').scroll({
  349. bounce: false,
  350. indicators: true, //是否显示滚动条
  351. deceleration:deceleration
  352. });
  353. mui('.mui-scroll-wrapper').pullRefresh({
  354. down: {
  355. callback: function() {
  356. var self = this;
  357. setTimeout(function() {
  358. initReqParams();
  359. loadData([0,1,2]);
  360. self.endPulldownToRefresh();
  361. }, 1000);
  362. }
  363. }
  364. });
  365. }
  366. /**
  367. * 初始化筛选事件
  368. */
  369. function shaixuanInit(main){
  370. var shaixuan = plus.webview.getWebviewById('shaixuan2.html');
  371. if(!shaixuan){
  372. shaixuan = mui.createWindow({
  373. id: 'shaixuan2.html',
  374. url: 'shaixuan2.html',
  375. styles: {
  376. top: 0,
  377. bottom: 0,
  378. left: '20%',
  379. width: '80%',
  380. scorllIndicator: "none"
  381. },
  382. show:{
  383. aniShow: "slide-in-right",
  384. duration: "400"
  385. },
  386. extras:{
  387. noYear: '2016',
  388. chooseYear: chooseYear
  389. }
  390. });
  391. }
  392. window.addEventListener("hideShaiXuan",function(){
  393. console.log("hideShaiXuan");
  394. main.setStyle({mask:"none"});
  395. shaixuan.hide();
  396. }, false);
  397. window.addEventListener("showShaiXuan", function() {
  398. shaixuan.show();
  399. main.setStyle({mask:"rgba(0,0,0,0.5)"});
  400. main.addEventListener("maskClick",function(){
  401. main.setStyle({mask:"none"});
  402. shaixuan.hide();
  403. }, false);
  404. });
  405. }
  406. function bindEvents(){
  407. //说明信息相关事件
  408. $("#closeBtn").on("tap", function(){
  409. $(".information").hide();
  410. });
  411. $(".info-icon").on("tap", function(){
  412. $(".information").show();
  413. });
  414. //左滑筛选区域的数据
  415. $('.header-link').on("tap", function(){
  416. var self = plus.webview.currentWebview();
  417. mui.fire(self, "showShaiXuan");
  418. });
  419. //日、周、月按钮切换
  420. $(".date-tag").on("tap",function(){
  421. dateType = $(this).attr("data-type");
  422. $(".date-tag").removeClass("active");
  423. $(this).addClass("active");
  424. initReqParams();
  425. loadData([1]); //只加载中间区域的数据
  426. });
  427. //底部各区等区域的tab切换
  428. $(".area-tab").on('tap', function(){
  429. var $this = $(this),
  430. type = $this.attr("data-val"); //4 - 各区, 3 - 社区, 2 - 团队
  431. areaType = type;
  432. if($this.hasClass("active")){
  433. return false;
  434. }
  435. $(".area-tab").removeClass("active");
  436. $this.addClass("active");
  437. if(type == "4"){
  438. lowLevel = 0;
  439. }else if(type == "3"){
  440. lowLevel = 2;
  441. }else{
  442. lowLevel = 1;
  443. }
  444. initReqParams();
  445. loadData([2]);
  446. });
  447. //底部每条记录的点击事件
  448. $("#listTable").on('tap', ".data-row", function(){
  449. var $this = $(this),
  450. name = $this.attr("data-name"),
  451. code = $this.attr("data-code"),
  452. $selectTab = $(".area-tab.active");
  453. if($selectTab.attr("data-val") == "2"){ //获得团队信息,弹框显示数据
  454. showTeamInfo(code);
  455. return false;
  456. }
  457. title = name;
  458. area = code;
  459. var newlevel = level - 1;
  460. //如果是市级管理员,先点击“社区”tab后再往下看下一级的数据,需要将level再-1
  461. if(newlevel == 3 && lowLevel == 2){
  462. newlevel -- ;
  463. }
  464. lowLevel = '';
  465. level = newlevel;
  466. $("#areaTitle").text(title);
  467. showTabs();
  468. initReqParams();
  469. //记录返回链接信息
  470. reqList.push({
  471. level: level,
  472. lowLevel: lowLevel,
  473. area: area,
  474. title: title,
  475. analysisType: analysisType,
  476. req: reqParam
  477. });
  478. loadData([0,1,2]);
  479. });
  480. //弹出遮罩
  481. $(".icon-remark").on("click", function(e) {
  482. $(".modal-overlay").addClass("modal-overlay-visible");
  483. setTimeout(function(){
  484. $(".modal-content").show();
  485. },50)
  486. });
  487. $(".div-close,.modal-overlay").on("click",function(){
  488. $(".modal-overlay").removeClass("modal-overlay-visible");
  489. $(".modal-content").hide();
  490. });
  491. //添加页面监听
  492. window.addEventListener("refresh", function(e){
  493. var year = e.detail.year;
  494. chooseYear = year;
  495. //重置变量值
  496. level = initLevel;
  497. area = userRole.code;
  498. title = userRole.name;
  499. lowLevel = "";
  500. startDate = getStartDate();
  501. endDate = getEndDate();
  502. $("#areaTitle").text(title);
  503. $(".choose-label").text(chooseYear);
  504. showTabs();
  505. initReqParams();
  506. //清空请求数组
  507. reqList.splice(0, reqList.length);
  508. //记录返回链接信息
  509. reqList.push({
  510. level: level,
  511. lowLevel: lowLevel,
  512. area: area,
  513. title: title,
  514. analysisType: analysisType,
  515. req: reqParam
  516. });
  517. loadData([0,1,2]);
  518. });
  519. }
  520. /*
  521. * 获得团队信息
  522. */
  523. function showTeamInfo(teamId){
  524. var url = "/doctor/admin-teams/teams/info",
  525. params = {
  526. teamId: teamId
  527. };
  528. plus.nativeUI.showWaiting();
  529. sendGet(url, params, null, function(res){
  530. if(res.status == 200){
  531. var data = res.data;
  532. data.memberLength = data.members.length;
  533. var html = template("teamInfo", data);
  534. $("#teamInfoBox").empty().append(html);
  535. $(".modal-overlay").addClass("modal-overlay-visible");
  536. setTimeout(function(){
  537. $(".modal-content").show();
  538. },50)
  539. }else{
  540. mui.toast(res.msg);
  541. }
  542. plus.nativeUI.closeWaiting();
  543. }, true);
  544. }
  545. function getStartDate(){
  546. return chooseYear+'-07-01';
  547. }
  548. //获取结束时间
  549. function getEndDate(){
  550. var nowdate = new Date();
  551. var year = nowdate.getFullYear();
  552. var month = nowdate.getMonth() + 1;
  553. var day = nowdate.getDate();
  554. var endDate = new Date((parseInt(chooseYear)+1) + '-06-30');
  555. var now = new Date();
  556. if(now <= endDate){
  557. return now.format("yyyy-MM-dd");
  558. }else{
  559. return (parseInt(chooseYear)+1) + '-06-30';
  560. }
  561. }
  562. //续签量数据集合
  563. function amountArr(list){
  564. var amountArr = [];
  565. for(var k in list){
  566. amountArr.push(list[k].signPayOnlineNum);
  567. }
  568. return amountArr;
  569. }
  570. //排名方法
  571. function soreRank(arr){
  572. var temp = [];
  573. var lis = [];
  574. for(var i=0;i<arr.length;i++){
  575. lis.push(arr[i]);
  576. }
  577. lis = _.uniq(lis);
  578. for(var i=0;i<arr.length;i++){
  579. temp[i] = lis.indexOf(arr[i])+1;
  580. }
  581. return temp;
  582. }
  583. //返回事件
  584. var old_back = mui.back;
  585. mui.back = function(){
  586. if(reqList.length == 1){
  587. old_back();
  588. }
  589. else{
  590. var preInfo = reqList[reqList.length - 1];
  591. if(preInfo.level == level && preInfo.lowLevel == lowLevel){
  592. reqList.pop();
  593. var info = reqList[reqList.length - 1];
  594. }else{
  595. info = preInfo;
  596. }
  597. level = info.level;
  598. area = info.area;
  599. title = info.title;
  600. lowLevel = info.lowLevel;
  601. sumType = info.sumType;
  602. tagCode = info.tagCode;
  603. analysisType = info.analysisType;
  604. $("#areaTitle").html(title);
  605. showTabs();
  606. initReqParams();
  607. loadData([0,1,2]);
  608. }
  609. }