xuqiantongji-online.js 19 KB

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