renew-analysis.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563
  1. var scroller1,
  2. initLevel,
  3. level,
  4. code,
  5. title,
  6. preIndex = 0, //记录前一次请求时发送的index
  7. currType = 0; //记录当前选中的是签入(1)还是签出(0)
  8. var tags=[];
  9. var colorArr = ['ff5442', 'ffc800 ','4ce428', '24bbfa','fb5dab', "9b5ffd"],
  10. colorArr2 = ['9b5ffd', 'ffc800', 'fb5dab'];
  11. //记录index的对应的值, 签出和签入和转签对应的各个level的值
  12. var indexArr = [{4: 41, 3: 39, 2: 35}, {4: 40, 3: 38, 2: 34}, {4: 35, 3: 35}];
  13. var reqArr = []; //记录请求的信息
  14. var now = new Date(),
  15. endDate = now.getFullYear()+"-"+(now.getMonth()+1)+"-"+now.getDate();
  16. mui.init();
  17. mui.plusReady(function(){
  18. var self = plus.webview.currentWebview();
  19. initLevel = level = self.level;
  20. code = self.code;
  21. title = self.title;
  22. $("#title").text(title);
  23. plus.nativeUI.showWaiting();
  24. initPage();
  25. initScroller();
  26. bindEvents();
  27. });
  28. function initScroller(){
  29. scroller1 = $("#wrapper1").initScroll(
  30. {
  31. pullDownAction: function(){
  32. plus.nativeUI.showWaiting();
  33. var info = reqArr[reqArr.length - 1];
  34. getAnalysisData();
  35. loadListData(info.tags, info.params);
  36. },pullUpAction: function() {
  37. $(".pullUp").hide();
  38. return false;
  39. }
  40. }
  41. );
  42. }
  43. function initPage(){
  44. getAnalysisData();
  45. var index;
  46. switch (parseInt(level)){
  47. case 4: //市级
  48. index = indexArr[0][level]; //初始查看区签出数据
  49. tags = ["各区","社区","团队"];
  50. break;
  51. case 3://区级
  52. index = indexArr[0][level]; //初始查看机构的签出数据
  53. tags = ["社区","团队"];
  54. break;
  55. case 2: //社区级
  56. index = indexArr[0][level]; //初始查看团队的签出数据
  57. tags = ["团队"];
  58. break;
  59. default:
  60. break;
  61. }
  62. var params2 = {
  63. sort:1,
  64. level:level,
  65. area:code,
  66. date: endDate,
  67. index: index
  68. };
  69. reqArr.push({tags: tags, params: params2, currType: currType, title: title});
  70. loadListData(tags, params2);
  71. }
  72. //获得顶部统计数据和饼图的数据
  73. function getAnalysisData(){
  74. var url = "/statistics/getRenewAnalysis",
  75. params = {level: level, code: code};
  76. sendGet(url, params, null, getAnalysisHandler);
  77. }
  78. //获得底部tab的值
  79. function loadListData(tags, params, notReloadTag){
  80. //加载数据截止时间
  81. sendPost("/statistics/time",null,function(res){
  82. },function(res){
  83. if(res.status=="200"){
  84. var date = (res.data && res.data.substring(11,16)) || "";
  85. $(".jiezhi-time").html(date)
  86. }
  87. });
  88. //加载显示tab
  89. if(!notReloadTag){
  90. var tagStr = "",
  91. index = 0;
  92. for(var i=0;i<tags.length;i++){
  93. var classz = "";
  94. var dataClick = "false";//是否已点击过
  95. if(params.lowLevel){ //如果存在之前点击tab的记录
  96. if(tags.length == 3){
  97. if(params.lowLevel == 2 && i == 1){
  98. classz="hit";
  99. dataClick="true";
  100. index = i;
  101. }
  102. if(params.lowLevel == 1 && i == 2){
  103. classz="hit";
  104. dataClick="true";
  105. index = i;
  106. }
  107. }else if(tags.length == 2){
  108. if(params.lowLevel == 1 && i == 1){
  109. classz="hit";
  110. dataClick="true";
  111. index = i;
  112. }
  113. }
  114. }else{
  115. if(i == 0){
  116. classz="hit";
  117. dataClick="true";
  118. }
  119. }
  120. tagStr += '<li id="tab_'+i+'" class="'+classz+'" data-click="'+dataClick+'"><a href="#" class="c-f16">'+tags[i]+'</a></li>';
  121. }
  122. $(".c-lab-mor").html(tagStr);
  123. //将其他的内容tab隐藏
  124. $(".tab-panel").addClass("c-hide").eq(index).removeClass("c-hide");
  125. }
  126. $(".group1").show();
  127. $(".group2").hide();
  128. //选中选择“签入”“签出”的tab
  129. var selectedId = $(".c-lab-mor li.hit").attr("id").split("tab_")[1];
  130. var $aList = $("#list"+selectedId).find(".tab a");
  131. var tabText = $(".c-lab-mor li.hit a").text();
  132. if(tabText == "团队"){
  133. $(".group1").hide();
  134. $(".group2").show();
  135. }
  136. $aList.removeClass("active");
  137. $("#list"+selectedId).find(".tab a[data-val="+currType+"]").addClass("active");
  138. var url = "/statistics/lowlevel_all";
  139. sendPost(url, params, null, listHandler);
  140. }
  141. function getAnalysisHandler(res){
  142. if(res.status == 200){
  143. if(level == 4){
  144. $("#totalNum").text(res.data.thisYearSwithch);
  145. $("#card1").show();
  146. $("#card2").hide();
  147. }else{
  148. $("#switchNum").text(res.data.thisYearSwithch);
  149. $("#outNum").text(res.data.outNum);
  150. $("#inNum").text(res.data.inNum);
  151. $("#card1").hide();
  152. $("#card2").show();
  153. }
  154. var len = res.data.switchHealth.length,
  155. sum = 0;
  156. for(var i=0; i<len; i++){
  157. sum += res.data.switchHealth[i].num;
  158. }
  159. var arrObj = [];
  160. for(var j=0; j<len; j++){
  161. var obj = res.data.switchHealth[j];
  162. obj.color = colorArr[j];
  163. if(sum == 0){
  164. obj.value = "0.00";
  165. }else{
  166. var rate = (obj.num / sum * 100).toFixed(2);
  167. obj.value = rate;
  168. }
  169. arrObj.push(obj);
  170. }
  171. echartsZQFun(arrObj);
  172. var html = template("reson_tmp", {list:arrObj});
  173. $("#reasonList").empty().append(html);
  174. //填充转签分布图
  175. var fenbuArrObj = [{
  176. color: colorArr2[0],
  177. name: "跨区",
  178. value: parseFloat(res.data.switchTown).toFixed(2)
  179. },{
  180. color: colorArr2[1],
  181. name: '跨社区',
  182. value: parseFloat(res.data.switchHospital).toFixed(2)
  183. },{
  184. color: colorArr2[2],
  185. name: '跨团队',
  186. value: parseFloat(res.data.switchTeam).toFixed(2)
  187. }];
  188. echartsFBFun(fenbuArrObj);
  189. var html = template("reson_tmp", {list:fenbuArrObj});
  190. $("#fenbuList").empty().append(html);
  191. }else{
  192. mui.toast(res.msg);
  193. }
  194. plus.nativeUI.closeWaiting();
  195. }
  196. function listHandler(res){
  197. if(res.status == 200){
  198. var data = res.data;
  199. var curIndex;
  200. for(var k in data){
  201. curIndex = k.split("index_")[1];
  202. var list = data[k];
  203. var topArr = soreRank(amountArr(list));
  204. for(var j in list){
  205. list[j].top = topArr[j];
  206. }
  207. data.all = assAmount(list);
  208. switch(parseInt(currType)){
  209. case 0:
  210. data.amountName = "签出数";
  211. break;
  212. case 1:
  213. data.amountName = "签入数";
  214. break;
  215. case 2:
  216. data.amountName = "转签数";
  217. break;
  218. }
  219. data.list = list;
  220. data.level = level;
  221. //查找对应的tab的内容显示区域
  222. var id = $(".c-lab-mor li.hit").attr("id"),
  223. tabText = $(".c-lab-mor li.hit a").text(),
  224. selectedId = id.split("tab_")[1];
  225. if(tabText == "团队"){
  226. data.level = 2; //团队时不需要显示向右箭头
  227. }
  228. //判断是否存在上一次请求显示的内容
  229. var $preDiv = $("#listPanel"+selectedId).find(".l_index_"+preIndex);
  230. if($preDiv.length > 0){
  231. $preDiv.hide();
  232. }
  233. //判断是否存在div
  234. var $div = $("#listPanel"+selectedId).find(".l_"+k);
  235. var html = template('list_tmpl', data);
  236. if($div.length == 0){
  237. var ulHtml = '<ul class="l_'+k+' l-gq-list">'+html+'<ul>';
  238. $("#listPanel"+selectedId).empty().append(ulHtml);
  239. }else{
  240. $div.empty().append(html);
  241. $div.show();
  242. }
  243. }
  244. preIndex = curIndex;
  245. scroller1.refresh();
  246. }else{
  247. mui.toast(res.msg);
  248. }
  249. }
  250. template.helper("setRate", function(all, amount){
  251. if(all == 0)
  252. return 0;
  253. return (amount / all * 100).toFixed(2);
  254. });
  255. //排序
  256. function soreRank(arr) {
  257. var temp = [];
  258. var lis = [];
  259. for(var i=0;i<arr.length;i++)
  260. lis.push(arr[i])
  261. lis = _.uniq(lis);
  262. // lis.sort();
  263. // lis.reverse();
  264. for(var i=0;i<arr.length;i++)
  265. temp[i] = lis.indexOf(arr[i])+1;
  266. return temp;
  267. }
  268. //数量数组
  269. function amountArr(list){
  270. var amountArr = [];
  271. for(var k in list){
  272. amountArr.push(list[k].amount);
  273. }
  274. return amountArr;
  275. }
  276. //格式化数量
  277. function assAmount(list){
  278. var all = 0;
  279. for(var k in list){
  280. all += list[k].amount;
  281. }
  282. return all;
  283. }
  284. //绘制转签原因分析的图
  285. function echartsZQFun(arry){
  286. var m=this;
  287. var myChart = echarts.init(document.getElementById('reasonMain'));
  288. var option = {
  289. tooltip: {
  290. trigger: 'item',
  291. formatter: "{a} <br/>{b}: {c}%",
  292. position: ['50%', '50%']
  293. },
  294. color:['#ff5442', '#ffc800 ','#4ce428', '#24bbfa','#fb5dab', "#9b5ffd"],
  295. series: [
  296. {
  297. name:'转签原因',
  298. type:'pie',
  299. radius : '65%',
  300. center:[70,'50%'],
  301. label: {
  302. normal: {
  303. show: false,
  304. textStyle: {
  305. color: "#000"
  306. }
  307. }
  308. },
  309. labelLine: {
  310. normal: {
  311. show: false
  312. }
  313. },
  314. data:arry
  315. }]
  316. };
  317. myChart.setOption(option);
  318. }
  319. //绘制分布图
  320. function echartsFBFun(arry){
  321. var m=this;
  322. var myChart = echarts.init(document.getElementById('fenbuMain'));
  323. var option = {
  324. tooltip: {
  325. trigger: 'item',
  326. formatter: "{a} <br/>{b}: {c}%",
  327. position: ['50%', '50%']
  328. },
  329. color:['#9b5ffd', '#ffc800', '#fb5dab'],
  330. series: [
  331. {
  332. name:'转签分布',
  333. type:'pie',
  334. radius : '65%',
  335. center:[70,'50%'],
  336. label: {
  337. normal: {
  338. show: false,
  339. textStyle: {
  340. color: "#000"
  341. }
  342. }
  343. },
  344. labelLine: {
  345. normal: {
  346. show: false
  347. }
  348. },
  349. data:arry
  350. }]
  351. };
  352. myChart.setOption(option);
  353. }
  354. function bindEvents(){
  355. //数据点击查看下一级数据
  356. $("body").on('tap',".l-gq-list li", function(){
  357. var tabText = $(".c-lab-mor li.hit a").text();
  358. var nextLevel = 3; //传递去下一个页面的level值
  359. if(tabText == "各区"){
  360. tags = ["社区","团队"];
  361. }else if(tabText == "社区"){
  362. if(currType == 2){
  363. currType = 0;
  364. }
  365. nextLevel = 2;
  366. tags = ["团队"];
  367. if((initLevel == level) && (initLevel == 4)){
  368. level --;
  369. }
  370. }else{
  371. //点击的是团队下的item
  372. return false;
  373. }
  374. //跳转去下一级页面的分析
  375. title = $(this).attr("data-name");
  376. code = $(this).attr("data-code");
  377. // mui.openWindow({
  378. // url: "renew-analysis2.html",
  379. // id: "renew-analysis2.html",
  380. // extras:{
  381. // level:nextLevel,
  382. // code:code1,
  383. // title: title1
  384. // }
  385. // });
  386. $("#title").text(title);
  387. level --;
  388. var params = {
  389. sort:1,
  390. level:level,
  391. area:code,
  392. date: endDate,
  393. index: indexArr[currType][level]
  394. };
  395. reqArr.push({tags: tags, params: params, currType: currType, title: title});
  396. getAnalysisData();
  397. loadListData(tags, params);
  398. });
  399. //tab切换
  400. $("body").on('tap', '.c-lab-mor li', function(){
  401. var $this = $(this);
  402. if($this.hasClass("hit")){
  403. return false;
  404. }
  405. $(".c-lab-mor li").removeClass("hit");
  406. $this.addClass("hit");
  407. var selectedId = $this.attr("id").split("tab_")[1];
  408. $(".tab-panel").addClass("c-hide");
  409. $("#list"+selectedId).removeClass("c-hide");
  410. currType = 0;
  411. var tabText = $(".c-lab-mor li.hit a").text(),
  412. lowLevel = 0,
  413. index = indexArr[0][level];
  414. if(tabText == "社区"){
  415. if(initLevel == 4){
  416. lowLevel = 2;
  417. }
  418. index = indexArr[0][3];
  419. }else if(tabText == "团队"){
  420. if(initLevel >= 3){
  421. lowLevel = 1;
  422. }
  423. index = indexArr[0][2];
  424. //团队下只有2个tab
  425. }else{
  426. index = indexArr[0][4];
  427. }
  428. var params = {
  429. sort:1,
  430. level:level,
  431. area:code,
  432. date: endDate,
  433. index: index
  434. };
  435. if(lowLevel){
  436. params.lowLevel = lowLevel;
  437. }
  438. // reqArr.push({tags: tags, params: params, currType: currType, title: title});
  439. loadListData(tags, params, 1);
  440. });
  441. //签入签出切换
  442. $("body").on('tap', '.tab a', function(){
  443. var $this = $(this);
  444. if($this.hasClass("active")){
  445. return false;
  446. }
  447. $this.siblings("a").removeClass("active");
  448. $this.addClass("active");
  449. var val = $this.attr("data-val"),
  450. tabText = $(".c-lab-mor li.hit").find("a").text(),
  451. lowLevel = 0,
  452. index = indexArr[val][level];
  453. currType = val;
  454. if(tabText == "社区"){
  455. if(initLevel == 4){
  456. lowLevel = 2;
  457. }
  458. index = indexArr[val][3];
  459. }else if(tabText == "团队"){
  460. if(initLevel >= 3){
  461. lowLevel = 1;
  462. }
  463. index = indexArr[val][2];
  464. }else{
  465. index = indexArr[val][4];
  466. }
  467. var params = {
  468. sort:1,
  469. level:level,
  470. area:code,
  471. date: endDate,
  472. index: index
  473. };
  474. if(lowLevel){
  475. params.lowLevel = lowLevel;
  476. }
  477. // reqArr.push({tags: tags, params: params, currType: currType});
  478. loadListData(tags, params, 1);
  479. });
  480. //说明信息相关事件
  481. $("#closeBtn").on("tap", function(){
  482. $(".information").hide();
  483. scroller1.refresh();
  484. });
  485. $(".info-icon").on("tap", function(){
  486. $(".information").show();
  487. scroller1.refresh();
  488. });
  489. }
  490. //返回事件
  491. var old_back = mui.back;
  492. mui.back = function(){
  493. if(reqArr.length == 1){
  494. var self = plus.webview.currentWebview(),
  495. opener = self.opener();
  496. opener.show();
  497. mui.later(function(){
  498. self.close();
  499. }, 300);
  500. }
  501. else{
  502. var preInfo = reqArr.pop();
  503. var info = reqArr[reqArr.length - 1];
  504. level = info.params.level;
  505. code = info.params.area;
  506. title = info.title;
  507. currType = info.currType;
  508. if(preInfo.params.level != level){
  509. getAnalysisData();
  510. }
  511. tags = info.tags;
  512. $("#title").html(title);
  513. loadListData(info.tags, info.params);
  514. }
  515. }