comprehensive-analysis.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951
  1. mui.init();
  2. var selfwv,
  3. userRole,
  4. initLevel,
  5. initAreaCode,
  6. initTitle,
  7. level,
  8. areaCode,
  9. areaTitle,
  10. index = "2", // 顶部tab对应的指标的index
  11. selectedDateType = 1, //折线图中选择的时间类型。 1-日,2-周, 3-月
  12. indexs = ['2','3', '5', '6'], //对应顶部tab的index值
  13. endDate,
  14. startDate,
  15. nowYear = new Date().getYear(),
  16. quShiStartDate,
  17. quShiEndDate,
  18. lowLevel,
  19. indexName = {'index_2': '活跃居民','index_3': '居民咨询量', 'index_5': '健康指导','index_6':'关注人次','index_1':'有效关注', 'index_4': '注册居民','index_83': "健康文章"};
  20. var initTabOffsetTop = 0; //初始化时,底部tab距离顶部的位置
  21. var index_5, index_83; //标记健康教育中健康文章和健康指导的值
  22. var reqParam = []; //请求参数
  23. var reqList = []; //请求的链接数据,根据这些信息后退的时候使用
  24. //初始化计算选择的年份
  25. var chooseYear;
  26. var now = new Date();
  27. if(now.getMonth() >= 6){
  28. chooseYear = now.getFullYear();
  29. }else{
  30. chooseYear = now.getFullYear() - 1;
  31. }
  32. var information = {
  33. "2":"注册居民人数为当前(截止最新时间)累计注册城市爱健康的居民人数总和。",
  34. "3":"居民咨询量为当前(截止最新时间)累计发起咨询的次数总和。",
  35. "5":"健康教育量为当前(截止最新时间)累计发送健康指导和健康文章的数量总和。",
  36. "6":"居民关注数量为当前(截止最新时间)累计关注医生的有效居民人数总和。"
  37. };
  38. mui.plusReady(function(){
  39. selfwv = plus.webview.currentWebview();
  40. userRole = JSON.parse(plus.storage.getItem("selectedRole"));
  41. initLevel = level = 3;//因为总体分析只能看到科室和医生,所以3代表科室级别,2代表医生级别
  42. initAreaCode = areaCode = srOrgCode;//默认是上饶机构code,值在common_http.js文件中
  43. initTitle = areaTitle = userRole.name;
  44. //处理点击首页的tap默认触发本页面的顶部tap
  45. if(selfwv.index){
  46. $(".l-banner li").removeClass("active");
  47. selfwv.index==0?index='2':selfwv.index==1?index='3':selfwv.index==2?index=5:selfwv.index==3?index=6:index=2;
  48. $(".l-banner li").eq(selfwv.index).addClass("active");
  49. }
  50. $("#areaTitle").text(areaTitle);
  51. $("#infoText").text(information[index]);
  52. $(".choose-label").text(chooseYear + '年');
  53. //初始化趋势图时间
  54. nowYear = new Date().getYear()
  55. nowYear += (nowYear < 2000) ? 1900 : 0;
  56. initReqParams(); //初始请求参数信息
  57. loadData([0,1,2]);
  58. //记录返回链接信息
  59. reqList.push({
  60. level: level,
  61. lowLevel: lowLevel,
  62. areaCode: areaCode,
  63. areaTitle: areaTitle,
  64. index: index,
  65. req: reqParam
  66. });
  67. initTabOffsetTop = $(".area-tab-panel").offset().top;
  68. showBottomTab();
  69. bindEvents();
  70. });
  71. initScroller();
  72. function getTopReqParams(){
  73. var url = "/statistics/getIndexTotal",
  74. data = {endDate:getDateFromNow(),area:areaCode,level:3};
  75. return {
  76. url: url,
  77. reqType: 'GET',
  78. data: data
  79. };
  80. }
  81. function initReqParams(){
  82. //初始化开始时间和结束时间
  83. startDate = getStartDate();
  84. endDate = getEndDate();
  85. quShiStartDate = formatDate(new Date(nowYear,0,1));
  86. quShiEndDate = formatDate(new Date(nowYear,11,31));
  87. $(".add-qushi-date-text").html(nowYear.toString())
  88. //增量(注册居民2、居民咨询量3、健康教育5、)到达量(居民关注6)
  89. var url2 = "/statistics/interval",//默认注册居民
  90. url3 = '/statistics/registerRange';;//默认注册居民
  91. if(index=='3' || index == '6'){
  92. url3 = "/statistics/lowlevel_total_mesh"
  93. }else if(index == '5'){
  94. url3 = '/statistics/article_lowlevel_total';
  95. }else if(index=='6'){
  96. url2 = "/statistics/interval_total";
  97. }
  98. if(index==2){//注册居民
  99. reqParam = [{//请求中间部分
  100. url: url2,
  101. reqType: 'POST',
  102. data:{
  103. index: '2,4',
  104. level: level, //等级(1 团队,2 科室,3 机构,4 区)
  105. area: areaCode, //默认是49229004X
  106. startDate: quShiStartDate,
  107. endDate: quShiEndDate,
  108. interval: selectedDateType
  109. }
  110. },{ //如果是注册居民,则增加置顶展示当面层级的注册率及关注平台人数、 注册人数.只针对注册居民时使用
  111. url: url3,
  112. reqType: 'POST',
  113. data: {}
  114. }];
  115. }else{//居民咨询量3、健康教育5、居民关注6
  116. reqParam = [{//请求中间部分
  117. url: url2,
  118. reqType: 'POST',
  119. data:{
  120. index: index == 5 ? '5,83' : (index==6)?"1,6":index,
  121. level: level, //等级(1 团队,2 科室,3 机构,4 区)
  122. area: areaCode, //默认是49229004X
  123. startDate: quShiStartDate,
  124. endDate: quShiEndDate,
  125. interval: selectedDateType
  126. }
  127. },{//请求底部部分
  128. url: url3,
  129. reqType: 'POST',
  130. data: {
  131. index: (index == 3) ? "3,22" : (index==6)?"1,6":index,
  132. endDate: endDate,
  133. level: level,
  134. area: areaCode,
  135. sort: 1
  136. }
  137. }];
  138. if(lowLevel){
  139. reqParam[1].data.lowLevel = lowLevel;
  140. }
  141. }
  142. }
  143. /*
  144. * 加载页面数据
  145. * @param loadArr array 记录需要请求的区域0-顶部,1-中间,2-底部
  146. */
  147. function loadData(loadArr){
  148. plus.nativeUI.showWaiting();
  149. getJieZhiTime();
  150. var reqPromise = [],
  151. newArr = []; //记录非顶部请求的请求数组
  152. if(loadArr.indexOf(0) > -1){
  153. //请求加载了头部的内容
  154. var url = "/statistics/getIndexTotal",
  155. data = {endDate:getDateFromNow(),area:areaCode,level:level};
  156. var reqs = [{url: url,reqType: 'GET',data: data}];
  157. getReqPromises(reqs, true).then(function(ress){
  158. handleTopPanelData(ress);
  159. }).then(function(){
  160. //如果饼图已经显示了,则这边需要重新绘制新的数据
  161. if($("#pieChartsPanel").hasClass("show")){
  162. $("#pieChartsPanel").show();
  163. $("#pieChartsPanel").addClass("show");
  164. $(".wz-num").text(index_83);
  165. $(".zd-num").text(index_5);
  166. var allindex=(index_83+index_5)*0.01;
  167. console.log(allindex+" "+index_83/allindex +" "+index_5/allindex)
  168. var wzNumP = allindex==0?"0%":(index_83/allindex).toFixed(2)+"%";
  169. var zdNumP = allindex==0?"0%":(index_5/allindex).toFixed(2)+"%";
  170. $(".wz-num-p").text(wzNumP);
  171. $(".zd-num-p").text(zdNumP);
  172. var arr = [{
  173. name: '健康文章',
  174. value: index_83
  175. },{
  176. name: '健康指导',
  177. value: index_5
  178. }];
  179. drawPie('pieChart', arr, ['#ffc800', '#17b3ec']);
  180. }else{
  181. $("#pieChartsPanel").hide();
  182. $("#pieChartsPanel").removeClass("show");
  183. }
  184. });
  185. }
  186. for(var i=0; i<loadArr.length; i++){
  187. if(loadArr[i] == 0){
  188. // do nothing
  189. }else{
  190. var j = loadArr[i] - 1;
  191. reqPromise.push(reqParam[j]);
  192. newArr.push(loadArr[i]);
  193. }
  194. }
  195. if(index == '2'){//注册居民
  196. $("#pieChartsPanel2").show();
  197. $(".area-panel").addClass("bgc-fff").hide();
  198. }else{
  199. $("#pieChartsPanel2").hide();
  200. $(".area-panel").removeClass("bgc-fff").show();
  201. }
  202. if(index == '5' ){
  203. //如果饼图还没有显示了,说明当前操作是点击了”健康教育“tab,此时需要绘制饼图,这样才会有动画效果
  204. if(!$("#pieChartsPanel").hasClass("show")){
  205. $("#pieChartsPanel").show();
  206. $("#pieChartsPanel").addClass("show");
  207. $(".wz-num").text(index_83);
  208. $(".zd-num").text(index_5);
  209. var allindex=(index_83+index_5)*0.01;
  210. console.log(allindex+" "+index_83/allindex +" "+index_5/allindex)
  211. var wzNumP = allindex==0?"0%":(index_83/allindex).toFixed(2)+"%";
  212. var zdNumP = allindex==0?"0%":(index_5/allindex).toFixed(2)+"%";
  213. $(".wz-num-p").text(wzNumP);
  214. $(".zd-num-p").text(zdNumP);
  215. var arr = [{
  216. name: '健康文章',
  217. value: index_83
  218. },{
  219. name: '健康指导',
  220. value: index_5
  221. }];
  222. drawPie('pieChart', arr, ['#ffc800', '#17b3ec']);
  223. }
  224. }else{
  225. $("#pieChartsPanel").hide();
  226. $("#pieChartsPanel").removeClass("show");
  227. }
  228. if(reqPromise.length > 0){
  229. getReqPromises(reqPromise, true).then(function(ress){
  230. var res2, res3;
  231. for(var i=0; i<newArr.length; i++){
  232. var j = newArr[i] + 1;
  233. if(j == 2){
  234. res2 = ress[i];
  235. }
  236. if(j == 3){
  237. res3 = ress[i];
  238. }
  239. }
  240. if(res2){
  241. if(res2.status == 200){
  242. handleSecondPanelData(res2.data);
  243. }else{
  244. mui.toast(res2.msg);
  245. }
  246. }
  247. if(res3){
  248. if(index=='2'){//注册居民
  249. if(res3.status == 200){
  250. $("#pieChartsPanel2").show();
  251. handleZCGKData(res3.data);
  252. }else{
  253. $("#pieChartsPanel2").hide();
  254. mui.toast(res3.msg);
  255. }
  256. }else{
  257. if(res3.status == 200){
  258. listHandle(res3.data);
  259. }else{
  260. $("#listTable").empty();
  261. mui.toast(res3.msg);
  262. }
  263. }
  264. }
  265. plus.nativeUI.closeWaiting();
  266. }).catch(function(e){
  267. console.log(e);
  268. plus.nativeUI.closeWaiting();
  269. });
  270. }
  271. }
  272. /*
  273. * 加载数据截止时间
  274. */
  275. function getJieZhiTime(){
  276. sendPost("/statistics/time",null,function(res){
  277. },function(res){
  278. if(res.status=="200"){
  279. var date = (res.data && res.data.substring(11,16)) || "";
  280. $(".jiezhi-time").html("("+date+")");
  281. }
  282. });
  283. }
  284. /*
  285. * 处理顶部各tab的值
  286. */
  287. function handleTopPanelData(ress){
  288. if(ress[0].status==200){
  289. var data = ress[0].data;
  290. $("#index_2 .span-account").html(data.reginNum);
  291. $("#index_3 .span-account").html(data.consultNum);
  292. $("#index_5 .span-account").html(parseInt(data.educateNum)+parseInt(data.guideNum));
  293. $("#index_6 .span-account").html(data.concernNum);
  294. index_83 = data.educateNum;
  295. index_5 = data.guideNum;
  296. }else{
  297. mui.toast(ress[0].msg);
  298. }
  299. }
  300. /*
  301. * 处理中间折线图区域的数据
  302. */
  303. function handleSecondPanelData(data){
  304. var dataZoom_end,
  305. xDatas = [],
  306. yDatas = [],
  307. names = [],
  308. colors = ['#12b7f5', '#cd67fd'];
  309. for(var p in data){
  310. if(selectedDateType=="3"){
  311. _.each(data[p], function(o){
  312. o.range=o.range.substr(0,7)
  313. });
  314. }
  315. names.push(indexName[p]);
  316. var xData = _.map(data[p], function(o){
  317. return o.range;
  318. });
  319. var yData = _.map(data[p], function(o){
  320. return o.amount;
  321. });
  322. xDatas.push(xData);
  323. yDatas.push(yData);
  324. var lastIndex = yData.length % 10;
  325. if(yData.length >10 ){
  326. dataZoom_end = 100-(9/yData.length)*100;
  327. }else{
  328. dataZoom_end = 0;
  329. }
  330. //初始给定第一版页面中时间区间
  331. if(selectedDateType == 3){
  332. var d1 = lastIndex > 0 ? xData[yData.length - lastIndex] : xData[yData.length - 10],
  333. d2 = xData[yData.length -1];
  334. if(d1){
  335. $("#startValue").text(d1.substr(0,4)+"年"+d1.substr(5,2)+"月");
  336. $("#endValue").text(d2.substr(0,4)+"年"+d2.substr(5,2)+"月");
  337. }else{
  338. $("#startValue").text(d1);
  339. $("#endValue").text(d2);
  340. }
  341. }else{
  342. $("#startValue").text(lastIndex > 0 ? xData[yData.length - lastIndex] : xData[yData.length - 10]);
  343. $("#endValue").text(xData[yData.length -1]);
  344. }
  345. }
  346. drawLine(names, dataZoom_end, xDatas[0], yDatas, colors);
  347. }
  348. /*
  349. * 处理底部科室、医生的数据
  350. */
  351. function listHandle(data){
  352. for(var k in data){
  353. var list = data[k];
  354. if(index=="3"){//咨询量
  355. for(var i=0;i<list.length;i++){
  356. var amount = list[i].amount.split(",");
  357. list[i].amount = amount[0];//咨询量
  358. list[i].noAmount = amount[1];//未回复咨询量
  359. }
  360. }
  361. if(index=="6"){//关注居民
  362. for(var i=0;i<list.length;i++){
  363. var amount = list[i].amount.split(",");
  364. list[i].amount = amount[0];//关注居民数
  365. list[i].noAmount = amount[1];//关注人次
  366. }
  367. }
  368. var topArr = [];
  369. topArr = soreRank(amountArr(list, 'amount'));
  370. for(var j in list){
  371. list[j].top = topArr[j];
  372. }
  373. var html = template("data-list", {
  374. list: list,
  375. level: level,
  376. index: index,
  377. lowLevel: lowLevel
  378. });
  379. $("#listTable").empty().append(html);
  380. }
  381. }
  382. /*
  383. * 处理注册居民-注册率概况的数据
  384. */
  385. function handleZCGKData(data){
  386. $("#pieChartsPanel2 .title").text("注册率概况");
  387. $(".jf-num").text(data.wxUser);
  388. $(".wjf-num").text(data.reginNum);
  389. $(".num").text(data.registeRange || 0);
  390. var arr = [{
  391. name: '关注平台人数',
  392. value: data.wxUser
  393. },{
  394. name: '注册人数',
  395. value: data.reginNum
  396. }];
  397. drawPie('pieChart2', arr, ['#17b3ec', '#909090']);
  398. }
  399. /*
  400. * 获得团队信息
  401. */
  402. function showTeamInfo(teamId){
  403. var url = "/doctor/admin-teams/teams/info",
  404. params = {
  405. teamId: teamId
  406. };
  407. plus.nativeUI.showWaiting();
  408. sendGet(url, params, null, function(res){
  409. if(res.status == 200){
  410. var data = res.data;
  411. data.memberLength = data.members.length;
  412. var html = template("teamInfo", data);
  413. $("#teamInfoBox").empty().append(html);
  414. $(".modal-overlay").addClass("modal-overlay-visible");
  415. setTimeout(function(){
  416. $(".modal-content").show();
  417. },50)
  418. }else{
  419. mui.toast(res.msg);
  420. }
  421. plus.nativeUI.closeWaiting();
  422. }, true);
  423. }
  424. /*
  425. * 控件事件绑定
  426. */
  427. function bindEvents(){
  428. //说明信息相关事件
  429. $("#closeBtn").on("tap", function(){
  430. $(".information").hide();
  431. });
  432. $(".info-icon").on("tap", function(){
  433. $(".information").show();
  434. });
  435. //点击顶部tab切换
  436. $(".l-banner").on('tap', 'li', function(){
  437. var $this = $(this),
  438. val = $this.attr("data-index");
  439. if($this.hasClass("active")){
  440. return false;
  441. }
  442. $(".l-banner li.active").removeClass("active");
  443. $this.addClass("active");
  444. index = val;
  445. $("#infoText").text(information[index]);
  446. var tagName = index == '5' ? '推送量' : indexName['index_'+index];
  447. if(index=='6'){//居民关注
  448. $(".qushi-span").text("居民关注趋势");
  449. }else{
  450. $(".qushi-span").text(tagName+"新增趋势");
  451. }
  452. //加载数据
  453. initReqParams();
  454. loadData([1,2]);
  455. //记录返回链接信息
  456. reqList=[];
  457. reqList.push({
  458. level: level,
  459. lowLevel: lowLevel,
  460. areaCode: areaCode,
  461. areaTitle: areaTitle,
  462. index: index,
  463. req: reqParam
  464. });
  465. });
  466. //日月周切换
  467. $(".date-tag").on('tap', function(){
  468. var $this = $(this),
  469. val = $this.attr("data-type");
  470. if($this.hasClass("active")){
  471. return false;
  472. }
  473. $(".date-tag").removeClass("active");
  474. $this.addClass("active");
  475. selectedDateType = val;
  476. initReqParams();
  477. loadData([1]);
  478. });
  479. //底部各区,社区,团队tab切换
  480. $(".area-tab").on('tap', function(){
  481. var $this = $(this),
  482. type = $this.attr("data-val"); //4 - 各区, 3 - 社区, 2 - 团队
  483. if($this.hasClass("active")){
  484. return false;
  485. }
  486. $(".area-tab").removeClass("active");
  487. $this.addClass("active");
  488. if(type == "3"){
  489. lowLevel = 2;
  490. }else{
  491. lowLevel = 1;
  492. }
  493. initReqParams();
  494. loadData([2]);
  495. });
  496. //点击列表查看下一级数据
  497. $("#listTable").on('tap', '.data-row', function(){
  498. var $this = $(this),
  499. code = $this.attr("data-code"),
  500. name = $this.attr("data-name");
  501. if($this.find(".fa-angle-right").length == 0){
  502. //团队内容
  503. showTeamInfo(code);
  504. return false;
  505. }
  506. areaTitle = name;
  507. areaCode = code;
  508. var newlevel = level - 1;
  509. //如果是市级管理员,先点击“社区”tab后再往下看下一级的数据,需要将level再-1
  510. if(newlevel == 3 && lowLevel == 2){
  511. newlevel -- ;
  512. }
  513. lowLevel = '';
  514. level = newlevel;
  515. $("#areaTitle").text(areaTitle);
  516. //判断当前tab的位置
  517. var top = $(".area-tab-panel").offset().top;
  518. if(top < 0){
  519. mui(".mui-scroll-wrapper").scroll().scrollTo(0, -(parseInt(initTabOffsetTop)/2), 500);
  520. }
  521. showBottomTab();
  522. initReqParams();
  523. loadData([0,1,2]);
  524. //记录返回链接信息
  525. reqList.push({
  526. level: level,
  527. lowLevel: lowLevel,
  528. areaCode: areaCode,
  529. areaTitle: areaTitle,
  530. index: index,
  531. req: reqParam
  532. });
  533. });
  534. //弹出遮罩
  535. $(".icon-remark").on("click", function(e) {
  536. $(".modal-overlay").addClass("modal-overlay-visible");
  537. setTimeout(function(){
  538. $(".modal-content").show();
  539. },50)
  540. });
  541. $(".div-close,.modal-overlay").on("click",function(){
  542. $(".modal-overlay").removeClass("modal-overlay-visible");
  543. $(".modal-content").hide();
  544. });
  545. //左滑筛选区域的数据
  546. $('.header-link').on("tap", function(){
  547. var self = plus.webview.currentWebview();
  548. mui.fire(self, "showShaiXuan");
  549. });
  550. //添加页面监听
  551. window.addEventListener("refresh", function(e){
  552. var year = e.detail.year;
  553. //重置变量值
  554. chooseYear = year;
  555. level = initLevel;
  556. areaCode = initAreaCode
  557. areaTitle = initTitle;
  558. lowLevel = "";
  559. startDate = getStartDate();
  560. endDate = getEndDate();
  561. $("#areaTitle").text(areaTitle);
  562. $(".choose-label").text(chooseYear+"年");
  563. showBottomTab();
  564. initReqParams();
  565. //清空请求数组
  566. reqList.splice(0, reqList.length);
  567. //记录返回链接信息
  568. reqList.push({
  569. level: level,
  570. lowLevel: lowLevel,
  571. areaCode: areaCode,
  572. areaTitle: areaTitle,
  573. index: index,
  574. req: reqParam
  575. });
  576. loadData([0,1,2]);
  577. })
  578. //中间趋势图左箭头事件
  579. $(".zuoJiao-img").on("tap",function(){
  580. nowYear = nowYear - 1;
  581. quShiStartDate = formatDate(new Date(nowYear,0,1));
  582. quShiEndDate = formatDate(new Date(nowYear,11,31));
  583. $(".add-qushi-date-text").html(nowYear.toString());
  584. initReqParams();
  585. loadData([1]);
  586. })
  587. //中间趋势图又箭头事件
  588. $(".youJiao-img").on("tap",function(){
  589. nowYear = nowYear + 1;
  590. quShiStartDate = formatDate(new Date(nowYear,0,1));
  591. quShiEndDate = formatDate(new Date(nowYear,11,31));
  592. $(".add-qushi-date-text").html(nowYear.toString());
  593. initReqParams();
  594. loadData([1]);
  595. })
  596. }
  597. /*
  598. * 控制底部科室,医生
  599. */
  600. function showBottomTab(){
  601. $(".area-tab").removeClass("active");
  602. switch(level){
  603. case 3:
  604. $(".area-tab").eq(0).addClass("active").show();
  605. $(".area-tab").eq(1).show();
  606. break;
  607. case 2:
  608. $(".area-tab").eq(0).hide();
  609. $(".area-tab").eq(1).addClass("active").show();
  610. break;
  611. }
  612. }
  613. /*
  614. * 初始化scroller
  615. */
  616. function initScroller(){
  617. //阻尼系数
  618. var deceleration = mui.os.ios?0.003:0.0009;
  619. mui('.mui-scroll-wrapper').scroll({
  620. bounce: false,
  621. indicators: true, //是否显示滚动条
  622. deceleration:deceleration
  623. });
  624. mui('.mui-scroll-wrapper').pullRefresh({
  625. down: {
  626. callback: function() {
  627. var self = this;
  628. setTimeout(function() {
  629. initReqParams();
  630. loadData([0,1,2]);
  631. self.endPulldownToRefresh();
  632. }, 1000);
  633. }
  634. }
  635. });
  636. }
  637. /*
  638. * 绘制折线图
  639. */
  640. function drawLine(name, dataZoom_end, xData, yDatas, colors){
  641. var lineCharts = echarts.init(document.getElementById('lineChart'));
  642. var options = {
  643. tooltip: {
  644. trigger: 'axis'
  645. },
  646. color: colors,
  647. legend: {
  648. bottom: '0px',
  649. data: name,
  650. borderColor: "#f1f1f1"
  651. },
  652. grid: {
  653. show: false,
  654. left: '10px',
  655. right: '10px',
  656. bottom: '30px',
  657. top: '10px',
  658. containLabel: true
  659. },
  660. xAxis: {
  661. type: 'category',
  662. boundaryGap: false,
  663. data: xData,
  664. axisLabel: {
  665. interval:0,//横轴信息全部显示
  666. formatter: function (value, index) {
  667. if(selectedDateType == 1 || selectedDateType == 2){
  668. if(index == 0){
  669. $("#startValue").text(value);
  670. return value.substr(5,2)+"月"+value.substr(8,2);
  671. }else{
  672. if(index == 10){
  673. $("#endValue").text(value);
  674. }
  675. return value.substr(8,2);
  676. }
  677. }else if(selectedDateType == 3){
  678. var val = value.substr(5,2)+"月"
  679. if(index == 0){
  680. $("#startValue").text(value.substr(0,4)+"年"+val);
  681. }else{
  682. if(index == 9){
  683. $("#endValue").text(value.substr(0,4)+"年"+val);
  684. }
  685. }
  686. return val;
  687. }
  688. }
  689. }
  690. },
  691. yAxis: {
  692. type: 'value',
  693. axisPointer: {
  694. snap: true
  695. },
  696. scale: true,
  697. minInterval: 1,
  698. boundaryGap: ['10%', '30%']
  699. },
  700. dataZoom: [{//给x轴设置滚动条
  701. show: false,
  702. start: dataZoom_end,
  703. end: 100,
  704. type: 'slider',
  705. zoomLock: true,
  706. },{ //下面这个属性是内容区域配置
  707. start: dataZoom_end,
  708. end: 100,
  709. type: 'inside',
  710. zoomLock: true,
  711. }]
  712. // series: [{
  713. // name: name,
  714. // type: 'line',
  715. // smooth: true,
  716. // data: yData,
  717. // lineStyle:{
  718. // normal: {
  719. // color: '#12b7f5'
  720. // }
  721. // }
  722. // }]
  723. };
  724. var series = [],
  725. legend = [];
  726. for(var i=0; i<yDatas.length; i++){
  727. var obj = {
  728. name: name[i],
  729. type: 'line',
  730. smooth: true,
  731. data: yDatas[i],
  732. lineStyle:{
  733. normal:{
  734. color: colors[i]
  735. }
  736. }
  737. };
  738. series.push(obj);
  739. }
  740. options.series = series;
  741. $("#lineChart").removeAttr('_echarts_instance_')
  742. lineCharts.setOption(options);
  743. }
  744. /*
  745. * 绘制饼图
  746. */
  747. function drawPie(elId, arry, color){
  748. var myChart = echarts.init(document.getElementById(elId));
  749. var option = {
  750. tooltip: {
  751. trigger: 'item',
  752. formatter: "{b} : {c} ({d}%)",
  753. position: ['50%', '50%']
  754. },
  755. color: color,
  756. series: [
  757. {
  758. type:'pie',
  759. radius: ['80%', '99%'],
  760. startAngle: 270,
  761. legendHoverLink: false,
  762. hoverAnimation: false,
  763. avoidLabelOverlap: false,
  764. label: {
  765. normal: {
  766. show: false,
  767. textStyle: {
  768. color: "#000"
  769. }
  770. }
  771. },
  772. labelLine: {
  773. normal: {
  774. show: false
  775. }
  776. },
  777. data:arry
  778. }]
  779. };
  780. myChart.setOption(option);
  781. }
  782. /*
  783. * 获取用来排序的字段值,返回数组
  784. * 参数: list - 列表, key - 字段的名称
  785. */
  786. function amountArr(list, key){
  787. var amountArr = [];
  788. for(var k in list){
  789. amountArr.push(list[k][key]);
  790. }
  791. return amountArr;
  792. }
  793. /*
  794. * 排名
  795. */
  796. function soreRank(arr){
  797. var temp = [];
  798. var lis = [];
  799. for(var i=0;i<arr.length;i++){
  800. lis.push(arr[i]);
  801. }
  802. lis = _.uniq(lis);
  803. for(var i=0;i<arr.length;i++){
  804. temp[i] = lis.indexOf(arr[i])+1;
  805. }
  806. return temp;
  807. }
  808. function getStartDate(){
  809. // 按年度来计算的时候,开始时间是该年度7月1号还是到下一个年的6月30号结束
  810. if(chooseYear == 2016){
  811. return chooseYear + "-08-01";
  812. }else{
  813. return chooseYear+'-07-01';
  814. }
  815. }
  816. //获取结束时间
  817. function getEndDate(){
  818. chooseYear = parseInt(chooseYear);
  819. var endDate = new Date((chooseYear+1) + '-06-30'),
  820. now = new Date();
  821. if(now <= endDate){
  822. var month = now.getMonth()+1,
  823. date1 = now.getDate();
  824. if(month < 10){
  825. month = "0"+month;
  826. }
  827. if(date1 < 10){
  828. date1 = "0"+date1;
  829. }
  830. return now.getFullYear()+"-"+month+"-"+date1;
  831. }else{
  832. return (chooseYear+1) + '-06-30';
  833. }
  834. }
  835. //获取当前时间
  836. function getDateFromNow(days) {
  837. if(!days) {
  838. return new Date().format("yyyy-MM-dd")
  839. }
  840. var now = new Date().getTime()
  841. var diff = 24 * 3600 * 1000 * days
  842. return new Date(now + diff).format("yyyy-MM-dd")
  843. }
  844. //格局化日期:yyyy-MM-dd
  845. function formatDate(date) {
  846. var myyear = date.getFullYear();
  847. var mymonth = date.getMonth() + 1;
  848. var myweekday = date.getDate();
  849. if(mymonth < 10) {
  850. mymonth = "0" + mymonth;
  851. }
  852. if(myweekday < 10) {
  853. myweekday = "0" + myweekday;
  854. }
  855. return(myyear + "-" + mymonth + "-" + myweekday);
  856. }
  857. //返回事件
  858. var old_back = mui.back;
  859. mui.back = function(){
  860. if(reqList.length == 1){
  861. old_back();
  862. }
  863. else{
  864. var preInfo = reqList.pop();
  865. var info = reqList[reqList.length - 1];
  866. level = info.level;
  867. areaCode = info.areaCode;
  868. areaTitle = info.areaTitle;
  869. lowLevel = info.lowLevel;
  870. index = info.index;
  871. if(!$(".l-banner li[data-index="+index+"]").hasClass("active")){
  872. $(".l-banner li").removeClass("active");
  873. $(".l-banner li[data-index="+index+"]").addClass("active");
  874. }
  875. $("#areaTitle").html(areaTitle);
  876. showBottomTab();
  877. initReqParams();
  878. loadData([0,1,2]);
  879. }
  880. }