qianyuetongji-online.js 19 KB

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