prescription-analysis.js 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971
  1. var self, userRole,
  2. scroller,
  3. initLevel,
  4. initCode,
  5. initTitle,
  6. level,
  7. code,
  8. areaTitle,
  9. tagCode = 1, //顶部各个tag标签对应的值
  10. sumType = 1, //记录从筛选页面选择的统计维度 1-订单统计,2-费用统计,3-配送统计,4-年龄统计
  11. disease = "", //疾病类型
  12. lowlevel,
  13. dateType = 1, //折线图坐标值1-日,2-周,3-月
  14. startDate = "",
  15. endDate = "";
  16. var reqParam = []; //请求参数
  17. var reqList = []; //请求的链接数据,根据这些信息后退的时候使用
  18. mui.init();
  19. mui.plusReady(function(){
  20. var self = plus.webview.currentWebview();
  21. userRole = JSON.parse(plus.storage.getItem("selectedRole"));
  22. initLevel = level = userRole.code == '350200' ? 4 : userRole.code.length==6 ? 3 : 2;
  23. lowlevel = level - 1;
  24. initCode = code = userRole.code;
  25. initTitle = areaTitle = userRole.name;
  26. $("#areaTitle").text(areaTitle);
  27. $("#header-subtitle").text("订单统计");
  28. showLabs();
  29. initReqParams(); //现获得页面请求的接口参数
  30. //记录返回链接信息
  31. reqList.push({
  32. level: level,
  33. lowlevel: lowlevel,
  34. code: code,
  35. areaTitle: areaTitle,
  36. sumType: sumType,
  37. tagCode: tagCode,
  38. req: reqParam
  39. });
  40. loadData([0,1,2]);
  41. initScroller();
  42. shaixuanInit(self);
  43. bindEvents();
  44. });
  45. function initReqParams(){
  46. //sumType: 1-订单统计,2-费用统计,3-配送统计,4-年龄统计
  47. switch(sumType){
  48. case 1:
  49. //tagCode: 1.总量,2.已完成,3.居民取消,4.审核不通过,5.进行中,6.其他原因取消
  50. reqParam = [{
  51. url: "/statistics/getPrescriptionCount",
  52. reqType: 'get',
  53. data: {level: level, area: code, disease: disease}
  54. },{
  55. url: "/statistics/getPrescriptionTotalHistogram",
  56. reqType: 'get',
  57. data: {level: level, area: code, disease: disease, type: tagCode, interval: dateType}
  58. },{
  59. url: "/statistics/getPrescriptionTotalLowLevel",
  60. reqType: 'get',
  61. data: {level: level, lowlevel: lowlevel, area: code, disease: disease, type: tagCode}
  62. }];
  63. break;
  64. case 2:
  65. //dateType: 折线图坐标值1-日,2-周,3-月
  66. //tagCode: 1.总量,2.平均值
  67. getStartDate(3, dateType);
  68. getEndDate();
  69. reqParam = [{
  70. url: "/statistics/getPrescriptionCost",
  71. reqType: 'get',
  72. data: {level: level, area: code, disease: disease}
  73. },{
  74. url: "/statistics/getPrescriptionCostAvgLine",
  75. reqType: 'get',
  76. data: {level: level, area: code, disease: disease, type: dateType, startDate: startDate, endDate: endDate}
  77. },{
  78. url: "/statistics/getPrescriptionCostLowLevel",
  79. reqType: 'get',
  80. data: {level: level, lowlevel: lowlevel, area: code, disease: disease, type: tagCode}
  81. }];
  82. break;
  83. case 3:
  84. //tagCode: 1.自取,2.快递配送,3.健管师配送
  85. reqParam = [{
  86. url: "/statistics/getPrescriptionDispatchingTotal",
  87. reqType: 'get',
  88. data: {level: level, area: code, disease: disease}
  89. },{
  90. url: "/statistics/getPrescriptionDispatchingHistogram",
  91. reqType: 'get',
  92. data: {level: level, area: code, disease: disease, type: tagCode, interval: dateType}
  93. },{
  94. url: "/statistics/getPrescriptionDispatchingLowLevel",
  95. reqType: 'get',
  96. data: {level: level, lowlevel: lowlevel, area: code, disease: disease, type: tagCode}
  97. }];
  98. break;
  99. case 4:
  100. reqParam = [{
  101. url: "/statistics/getPrescriptionAgeTotal",
  102. reqType: 'get',
  103. data: {level: level, area: code, disease: disease}
  104. },{
  105. url: "/statistics/getPrescriptionAgeHistogram",
  106. reqType: 'get',
  107. data: {level: level, area: code, disease: disease}
  108. },{
  109. url: "/statistics/getPrescriptionAgeLowLevel",
  110. reqType: 'get',
  111. data: {level: level, lowlevel: lowlevel, area: code, disease: disease}
  112. }];
  113. break;
  114. default:
  115. reqParam = [];
  116. break;
  117. };
  118. }
  119. /*
  120. * 加载页面数据
  121. * @param loadArr array 记录需要请求的区域0-顶部,1-中间,2-底部
  122. */
  123. function loadData(loadArr){
  124. plus.nativeUI.showWaiting();
  125. getJieZhiTime();
  126. var reqPromise = [];
  127. for(var i=0; i<loadArr.length; i++){
  128. var j = loadArr[i];
  129. reqPromise.push(reqParam[j]);
  130. }
  131. console.log();
  132. getReqPromises(reqPromise, true).then(function(ress){
  133. var res1, res2, res3;
  134. for(var i=0; i<loadArr.length; i++){
  135. var j = loadArr[i] + 1;
  136. if(j == 1){
  137. res1 = ress[i];
  138. }
  139. if(j == 2){
  140. res2 = ress[i];
  141. }
  142. if(j == 3){
  143. res3 = ress[i];
  144. }
  145. }
  146. if(res1 && res1.status == 200){
  147. showTags(res1.data);
  148. }
  149. if(res2 && res2.status == 200){
  150. handleSecondPanelData(res2.data);
  151. }
  152. if(res3){
  153. if(res3.status == 200){
  154. listHandle(res3.data);
  155. }else{
  156. $("#listUl").empty();
  157. mui.toast(res3.msg);
  158. }
  159. }
  160. plus.nativeUI.closeWaiting();
  161. });
  162. }
  163. /*
  164. * 加载数据截止时间
  165. */
  166. function getJieZhiTime(){
  167. sendPost("/statistics/time",null,function(res){
  168. },function(res){
  169. if(res.status=="200"){
  170. var date = (res.data && res.data.substring(11,16)) || "";
  171. $(".jiezhi-time").html("("+date+")");
  172. }
  173. });
  174. }
  175. /*
  176. * 处理年龄分布饼图
  177. */
  178. function handleAgeData(data){
  179. var color = ['#ff5442', '#ffc800 ','#4ce428', '#24bbfa','#fb5dab', "#9b5ffd"],
  180. name = ['0~6岁', '7~18岁', '19~30岁', '31~50岁', '51~64岁', '65岁以上'],
  181. objName = ['0age', '7age', '19age', '31age', '51age', '65age'];
  182. var arr = [];
  183. for(i=0; i<6; i++){
  184. var obj = {
  185. name: name[i],
  186. value: data[objName[i]],
  187. color: color[i]
  188. }
  189. arr.push(obj);
  190. }
  191. var html = template("age_tmp", {list: arr});
  192. $("#fenbuList").empty().append(html);
  193. drawPie(arr, color);
  194. }
  195. /*
  196. * 处理第二块区域的数据内容
  197. */
  198. function handleSecondPanelData(data){
  199. switch(sumType){
  200. case 1:
  201. case 3:
  202. //绘制柱状图
  203. $("#barTitle").text("近半年统计");
  204. var el = document.getElementById("barChart"),
  205. color = "#17b3ec",
  206. xAxisData = [],
  207. seriesData = [];
  208. for(i=0; i<data.length; i++){
  209. var item = data[i];
  210. xAxisData.push(item.date);
  211. seriesData.push(item.count);
  212. }
  213. var names;
  214. if(sumType == 1){
  215. names = ["续方总量", "已完成", "居民取消", "审核未通过", "进行中", "其他原因取消"];
  216. }else if(sumType == 3){
  217. names = ["居民自取", "物流配送", "健管师配送"];
  218. }
  219. var dataZoom = 1;
  220. drawBars(el, xAxisData, seriesData, color, names[tagCode -1], dataZoom);
  221. break;
  222. case 2:
  223. //绘制人均费用折线图
  224. drawChart(data);
  225. break;
  226. case 4:
  227. //绘制柱状图
  228. $("#barTitle").text("人均使用次数");
  229. var el = document.getElementById("barChart"),
  230. color = "#17b3ec",
  231. xAxisData = ['0~6', '7~18', '19~30', '31~50', '51~64', '65以上'],
  232. fieldName = ['0ageRate', '7ageRate', '19ageRate', '31ageRate', '51ageRate', '65ageRate']
  233. seriesData = [];
  234. for(i=0; i<6; i++){
  235. seriesData.push(data[fieldName[i]]);
  236. }
  237. drawBars(el, xAxisData, seriesData, color, '人均使用次数');
  238. break;
  239. }
  240. }
  241. /*
  242. * 根据统计类型显示对应的顶部tag内容
  243. */
  244. function showTags(data){
  245. switch(parseInt(sumType)){
  246. case 1:
  247. $(".tag-panel").empty().append(template("dd_tmp", {data: data, selected: tagCode}));
  248. $(".tag-panel").show();
  249. $("#dateDiv").show();
  250. $("#barInfoDiv").show();
  251. $("#barChartsPanel").show();
  252. $("#pieChartsPanel").hide();
  253. $("#lineChartsPanel").hide();
  254. break;
  255. case 2:
  256. $(".tag-panel").empty().append(template("fy_tmp", {data: data, selected: tagCode}));
  257. $(".tag-panel").show();
  258. $("#lineChartsPanel").show();
  259. $("#barChartsPanel").hide();
  260. $("#pieChartsPanel").hide();
  261. break;
  262. case 3:
  263. $(".tag-panel").empty().append(template("ps_tmp", {data: data, selected: tagCode}));
  264. $(".tag-panel").show();
  265. $("#dateDiv").show();
  266. $("#barInfoDiv").show();
  267. $("#barChartsPanel").show();
  268. $("#pieChartsPanel").hide();
  269. $("#lineChartsPanel").hide();
  270. break;
  271. case 4:
  272. $(".tag-panel").hide();
  273. $("#dateDiv").hide();
  274. $("#barInfoDiv").hide();
  275. $("#barChartsPanel").show();
  276. $("#pieChartsPanel").show();
  277. $("#lineChartsPanel").hide();
  278. handleAgeData(data);
  279. break;
  280. }
  281. // mui('.mui-scroll-wrapper').pullRefresh().refresh();
  282. }
  283. /*
  284. * 显示底部的tab
  285. */
  286. function showLabs(){
  287. $(".area-tab").removeClass("active");
  288. switch(level){
  289. case 4:
  290. $(".area-tab").show();
  291. $(".area-tab").eq(0).addClass("active");
  292. areaType = "4";
  293. break;
  294. case 3:
  295. $(".area-tab").eq(0).hide();
  296. $(".area-tab").eq(1).show();
  297. $(".area-tab").eq(1).addClass("active");
  298. areaType = "3";
  299. break;
  300. case 2:
  301. $(".area-tab").eq(0).hide();
  302. $(".area-tab").eq(1).hide();
  303. $(".area-tab").eq(2).addClass("active");
  304. areaType = "2";
  305. break;
  306. }
  307. }
  308. /*
  309. * 初始化scroller
  310. */
  311. function initScroller(){
  312. //阻尼系数
  313. var deceleration = mui.os.ios?0.003:0.0009;
  314. mui('.mui-scroll-wrapper').scroll({
  315. bounce: false,
  316. indicators: true, //是否显示滚动条
  317. deceleration:deceleration
  318. });
  319. mui('.mui-scroll-wrapper').pullRefresh({
  320. down: {
  321. callback: function() {
  322. var self = this;
  323. setTimeout(function() {
  324. initReqParams();
  325. loadData([0,1,2]);
  326. self.endPulldownToRefresh();
  327. }, 1000);
  328. }
  329. }
  330. });
  331. }
  332. /**
  333. * 初始化筛选事件
  334. */
  335. function shaixuanInit(main){
  336. var shaixuan = plus.webview.getWebviewById('prescription-shaixuan.html');
  337. if(!shaixuan){
  338. shaixuan = mui.createWindow({
  339. id: 'prescription-shaixuan.html',
  340. url: 'prescription-shaixuan.html',
  341. styles: {
  342. top: 0,
  343. bottom: 0,
  344. left: '20%',
  345. width: '80%',
  346. scorllIndicator: "none"
  347. },
  348. show:{
  349. aniShow: "slide-in-right",
  350. duration: "400"
  351. },
  352. extras:{
  353. }
  354. });
  355. }
  356. window.addEventListener("hideShaiXuan",function(){
  357. console.log("hideShaiXuan");
  358. main.setStyle({mask:"none"});
  359. shaixuan.hide();
  360. }, false);
  361. window.addEventListener("showShaiXuan", function() {
  362. shaixuan.show();
  363. main.setStyle({mask:"rgba(0,0,0,0.5)"});
  364. main.addEventListener("maskClick",function(){
  365. main.setStyle({mask:"none"});
  366. shaixuan.hide();
  367. }, false);
  368. });
  369. }
  370. /*
  371. * 控件事件绑定
  372. */
  373. function bindEvents(){
  374. //顶部tag切换
  375. $(".tag-panel").on('tap', '.tag', function(){
  376. var $this = $(this);
  377. tagCode = $this.data("code");
  378. if($this.hasClass("active")){
  379. return false;
  380. }
  381. $(".tag-panel .tag").removeClass("active");
  382. $this.addClass("active");
  383. initReqParams();
  384. if(sumType == 2){
  385. loadData([2]);
  386. }else{
  387. loadData([1,2]);
  388. }
  389. })
  390. //底部区,社区,团队切换
  391. $(".area-tab-panel").on('tap', '.area-tab', function(){
  392. var $this = $(this),
  393. type = $this.attr("data-val"); //4 - 各区, 3 - 社区, 2 - 团队
  394. areaType = type;
  395. if($this.hasClass("active")){
  396. return false;
  397. }
  398. $(".area-tab").removeClass("active");
  399. $this.addClass("active");
  400. if(type == "4"){
  401. lowlevel = 3;
  402. }else if(type == "3"){
  403. lowlevel = 2;
  404. }else{
  405. lowlevel = 1;
  406. }
  407. initReqParams();
  408. loadData([2]);
  409. });
  410. //列表点击跳转下一级内容
  411. $("#listUl").on('tap', ".data-row", function(){
  412. var $this = $(this);
  413. if($this.data("next") == "0"){
  414. return false;
  415. }
  416. code = $this.data("code");
  417. areaTitle = $this.data("name");
  418. if(level == 4 && lowlevel == 2){
  419. level --;
  420. }
  421. level --;
  422. lowlevel = level - 1;
  423. $("#areaTitle").text(areaTitle);
  424. showLabs();
  425. initReqParams();
  426. //记录返回链接信息
  427. reqList.push({
  428. level: level,
  429. lowlevel: lowlevel,
  430. code: code,
  431. areaTitle: areaTitle,
  432. sumType: sumType,
  433. tagCode: tagCode,
  434. req: reqParam
  435. });
  436. loadData([0,1,2]);
  437. });
  438. //日,月,年选择
  439. $(".l-zxt-con .div-btn").on('tap', function(){
  440. var $this = $(this);
  441. if($this.hasClass("active")){
  442. return false;
  443. }
  444. $(".l-zxt-con .div-btn").removeClass("active");
  445. $this.addClass("active");
  446. dateType = $this.data("id");
  447. initReqParams();
  448. loadData([1]);
  449. });
  450. //日、周、月按钮切换
  451. $(".date-tag").on("tap",function(){
  452. dateType = $(this).attr("data-type");
  453. $(".date-tag").removeClass("active");
  454. $(this).addClass("active");
  455. initReqParams();
  456. loadData([1]); //只加载中间区域的数据
  457. });
  458. template.helper("setRate", function(all, amount){
  459. if(all == 0)
  460. return 0;
  461. var val = amount;
  462. if(sumType == 2){
  463. val = (amount+"").replace(",", "");
  464. }
  465. return (parseFloat(val) / all * 100).toFixed(2);
  466. });
  467. template.helper("formatAmount", function(str){
  468. return formatAmount(str+"");
  469. })
  470. //左滑筛选区域的数据
  471. $('.header-link').on("tap", function(){
  472. var self = plus.webview.currentWebview();
  473. mui.fire(self, "showShaiXuan");
  474. });
  475. //添加页面监听
  476. window.addEventListener("refresh", function(e){
  477. console.log(e);
  478. var sumType1 = e.detail.sumType,
  479. sumName = e.detail.sumName,
  480. lowCode = e.detail.lowCode,
  481. name = e.detail.name;
  482. sumType = sumType1;
  483. disease = lowCode;
  484. level = initLevel;
  485. code = initCode;
  486. areaTitle = initTitle;
  487. lowlevel = level - 1;
  488. tagCode = 1;
  489. dateType = 1;
  490. //日,周,月的标签默认选中日
  491. $(".l-zxt-con .div-btn").removeClass("active");
  492. $(".l-zxt-con .div-btn").eq(0).addClass("active");
  493. $("#dateDiv .date-tag").removeClass("active");
  494. $("#dateDiv .date-tag").eq(0).addClass("active");
  495. //清空请求数组
  496. reqList.splice(0, reqList.length);
  497. showLabs();
  498. initReqParams();
  499. //记录返回链接信息
  500. reqList.push({
  501. level: level,
  502. lowlevel: lowlevel,
  503. code: code,
  504. areaTitle: areaTitle,
  505. sumType: sumType,
  506. tagCode: tagCode,
  507. req: reqParam
  508. });
  509. loadData([0,1,2]);
  510. $("#areaTitle").text(areaTitle);
  511. $("#header-subtitle").text(sumName);
  512. if(name == "全部"){
  513. name = "所有病种";
  514. }
  515. $(".choose-label").text(name);
  516. })
  517. }
  518. //底部列表显示
  519. function listHandle(list){
  520. var topArr = soreRank(list);
  521. for(var j in list){
  522. list[j].top = topArr[j];
  523. }
  524. console.log(list);
  525. var data = {};
  526. data.all = assAmount(list);
  527. if(sumType == 4){
  528. data.amountName = '总人数';
  529. }else{
  530. data.amountName = $(".tag[data-code="+tagCode+"] div").eq(1).text();
  531. }
  532. data.list = _.map(list, function(o){
  533. if(sumType == 2 && tagCode == 1){
  534. o.val = formatAmount(o.val + "");
  535. }
  536. return o;
  537. });
  538. data.lowlevel = lowlevel;
  539. data.level = level;
  540. console.log(data);
  541. var html = template('list-tmp', data);
  542. $("#listUl").empty().append(html);
  543. // mui(".mui-scroll-wrapper").pullRefresh().refresh(true);
  544. }
  545. //绘制柱状图
  546. function drawBars(el, xAxisData, seriesData, color, name, dataZoom, grid){
  547. var myChart = echarts.init(el);
  548. // 指定图表的配置项和数据
  549. var option = {
  550. tooltip: {
  551. trigger: 'item'
  552. },
  553. toolbox: {
  554. dataZoom: true,
  555. show: true,
  556. orient: 'vertical',
  557. x: 'right',
  558. y: 'center'
  559. },
  560. grid: grid ? grid : {
  561. x: 35,
  562. y: 20,
  563. x2: 20,
  564. y2: 30
  565. },
  566. xAxis: [{
  567. type: 'category',
  568. data: xAxisData,
  569. axisLabel: {
  570. interval:0,//横轴信息全部显示
  571. formatter: function (value, index) {
  572. if(sumType == 1 || sumType ==3){
  573. if(dateType == 1 || dateType == 2){
  574. if(index == 0){
  575. $("#startValue").text(value);
  576. return value.substr(5,2)+"月"+value.substr(8,2);
  577. }else{
  578. if(index == 7){
  579. $("#endValue").text(value);
  580. }
  581. return value.substr(8,2);
  582. }
  583. }else if(dateType == 3){
  584. var val = value.substr(5,2)+"月"
  585. if(index == 0){
  586. $("#startValue").text(value.substr(0,4)+"年"+val);
  587. }else{
  588. if(index == 7){
  589. $("#endValue").text(value.substr(0,4)+"年"+val);
  590. }
  591. }
  592. return val;
  593. }
  594. }
  595. return value;
  596. }
  597. },
  598. splitLine: {
  599. show: false
  600. }
  601. }],
  602. yAxis: [{
  603. type: 'value'
  604. }],
  605. series: [{
  606. clickable: true,
  607. name: name || "",
  608. itemStyle : {
  609. normal: {
  610. label : {
  611. show: true, position: 'top'
  612. },
  613. color: color || '#fbba31'
  614. }
  615. },
  616. barWidth: 20,
  617. type: 'bar',
  618. data: seriesData
  619. }]
  620. };
  621. if(dataZoom == 1){
  622. var len = seriesData.length,
  623. lastIndex = len % 7;
  624. if(len > 7 ){
  625. var dataZoom_end = 100-(6/len)*100;
  626. }else{
  627. var dataZoom_end = 0;
  628. }
  629. //初始给定第一版页面中时间区间
  630. if(dateType == 3){
  631. var d1 = xAxisData[len - lastIndex],
  632. d2 = xAxisData[len -1];
  633. $("#startValue").text(d1.substr(0,4)+"年"+d1.substr(5,2)+"月");
  634. $("#endValue").text(d2.substr(0,4)+"年"+d2.substr(5,2)+"月");
  635. }else{
  636. $("#startValue").text(xAxisData[len - lastIndex]);
  637. $("#endValue").text(xAxisData[len -1]);
  638. }
  639. option.dataZoom = [{//给x轴设置滚动条
  640. show: false,
  641. start: dataZoom_end,
  642. end: 100,
  643. type: 'slider',
  644. zoomLock: true,
  645. },{ //下面这个属性是内容区域配置
  646. start: dataZoom_end,
  647. end: 100,
  648. type: 'inside',
  649. zoomLock: true,
  650. }];
  651. }
  652. // 使用刚指定的配置项和数据显示图表。
  653. myChart.setOption(option);
  654. if(sumType == 1 || sumType == 3){
  655. myChart.on('click',function(a,b){
  656. var arg = {
  657. date: a.name,
  658. dateType: dateType,
  659. disease: disease,
  660. area: code,
  661. areaTitle: areaTitle
  662. }
  663. if(sumType == 1){
  664. arg.status = tagCode;
  665. }
  666. if(sumType == 3){
  667. arg.status = 2; // 配送统计的默认是已完成的订单
  668. arg.expressType = tagCode;
  669. }
  670. openWebview("../../prescription/html/prescription-records.html", arg);
  671. });
  672. }
  673. }
  674. //绘制折线图
  675. function drawChart(data){
  676. var recordCount = 10;//一页显示几条数据
  677. var allData = data.reverse();
  678. var allRecordData = _.map(allData, function(o){
  679. return o.avg;
  680. })
  681. var dateArr = _.map(allData, function(o){
  682. return o.date.substring(5);
  683. });
  684. var resultData = _.groupBy(allRecordData,function(item,i){
  685. return Math.floor(i/recordCount)
  686. });
  687. var dateArrData = _.groupBy(dateArr,function(item,i){
  688. return Math.floor(i/recordCount)
  689. });
  690. //以下为折线图处理
  691. var gnum = Math.ceil(allRecordData.length / recordCount);
  692. var HandStartX,HandStartY,HandEndX,HandEndY,CountX,CountY,startPos,isScrolling,
  693. number=allRecordData.length,
  694. times=allRecordData.length%recordCount;
  695. var canvasStr = '<div class="div-layer"></div>';
  696. for(var x in resultData){
  697. canvasStr = '<canvas id="wcMotion'+x+'" class="canvas-wc animated" style="display:block"></canvas>'+canvasStr;
  698. }
  699. $(".l-zxt-inner").html(canvasStr);
  700. var dateType = $(".div-btn-group .div-btn.active").attr("data-id");
  701. window.setTimeout(function() {
  702. for(var x in resultData){
  703. // var startDay = new Date(getDateBefore(times-1));
  704. var resultDateArr = dateArrData[x].reverse();
  705. var yAxis = maxData(resultData[x]);//求数据的最大值
  706. $('#wcMotion'+x).wcChart({
  707. height: 200, // width and height must be set if change
  708. yAxis:yAxis,
  709. day: new Date(startDate),
  710. points: [],
  711. dateType:dateType,
  712. dateArr:resultDateArr,
  713. data: resultData[x].reverse(),
  714. fill: {gradient: [["#17B3EC",.1], ["#17B3EC",.5]], gradientAngle: Math.PI * -45/180},
  715. animation: null, // 修复bug#3298 【医生端】总体分析排版优化。(vivo手机)
  716. event: 'tap'
  717. });
  718. if(x==0){
  719. $('#wcMotion'+x).show();
  720. }
  721. times+=recordCount;
  722. //折线图画布添加左滑和右滑效果
  723. var wcMotion = document.getElementById('wcMotion'+x);
  724. wcMotion.addEventListener('touchstart', function(event) {
  725. HandStartX=event.touches[0].clientX;
  726. HandStartY=event.touches[0].clientY;
  727. //touches数组对象获得屏幕上所有的touch,取第一个touch
  728. var touch = event.targetTouches[0];
  729. //取第一个touch的坐标值
  730. startPos = {x:touch.pageX,y:touch.pageY,time:+new Date};
  731. //这个参数判断是垂直滚动还是水平滚动
  732. isScrolling = 0;
  733. }, false);
  734. wcMotion.addEventListener('touchend', function(event) {
  735. HandEndX=event.changedTouches[0].clientX;
  736. HandEndY=event.changedTouches[0].clientY;
  737. CountX=HandEndX-HandStartX;
  738. CountY=HandEndY-HandStartY;
  739. if((Math.abs(CountX)>Math.abs(CountY))&& Math.abs(CountX)>50){
  740. var targetMotion = $(event.target);
  741. if(CountX<0){
  742. if(targetMotion.next().length>0 && !targetMotion.next().hasClass("div-layer")){
  743. targetMotion.siblings().hide();
  744. targetMotion.addClass("fadeOutLeft");
  745. targetMotion.next().removeClass("fadeOutRight").removeClass("fadeOutLeft").removeClass("fadeInLeft").addClass("fadeInRight").show();
  746. }
  747. console.log("左滑");
  748. }else{
  749. if(targetMotion.prev().length>0 && !targetMotion.prev().hasClass("div-layer")){
  750. targetMotion.siblings().hide();
  751. targetMotion.addClass("fadeOutRight");
  752. targetMotion.prev().removeClass("fadeOutRight").removeClass("fadeOutLeft").removeClass("fadeInRight").addClass("fadeInLeft").show();
  753. }
  754. console.log("右滑");
  755. }
  756. }
  757. }, false);
  758. wcMotion.addEventListener('touchmove', function(event) {
  759. //当屏幕有多个touch或者页面被缩放过,就不执行move操作
  760. if(event.targetTouches.length > 1 || event.scale && event.scale !== 1) return;
  761. var touch = event.targetTouches[0];
  762. endPos = {x:touch.pageX - startPos.x,y:touch.pageY - startPos.y};
  763. //isScrolling为1时,表示纵向滑动,0为横向滑动
  764. isScrolling = Math.abs(endPos.x) < Math.abs(endPos.y) ? 1:0;
  765. if(isScrolling === 0){
  766. //阻止触摸事件的默认行为,即阻止滚屏
  767. event.preventDefault();
  768. }
  769. }, false);
  770. }
  771. }, 500);
  772. }
  773. //绘制饼图
  774. function drawPie(arry, color){
  775. var myChart = echarts.init(document.getElementById('fenbuMain'));
  776. var option = {
  777. tooltip: {
  778. trigger: 'item',
  779. formatter: "{a} <br/>{b} : {c} ({d}%)",
  780. position: ['50%', '50%']
  781. },
  782. color: color,
  783. series: [
  784. {
  785. name:'年龄',
  786. type:'pie',
  787. radius : '65%',
  788. center:['50%','50%'],
  789. label: {
  790. normal: {
  791. show: false,
  792. textStyle: {
  793. color: "#000"
  794. }
  795. }
  796. },
  797. labelLine: {
  798. normal: {
  799. show: false
  800. }
  801. },
  802. data:arry
  803. }]
  804. };
  805. myChart.setOption(option);
  806. }
  807. //排序
  808. function soreRank(arr) {
  809. var temp = [];
  810. var lis = [];
  811. for(var i=0;i<arr.length;i++)
  812. lis.push(arr[i].val)
  813. lis = _.uniq(lis);
  814. for(var i=0;i<arr.length;i++)
  815. temp[i] = lis.indexOf(arr[i].val)+1;
  816. return temp;
  817. }
  818. //格式化数量
  819. function assAmount(list){
  820. var all = 0;
  821. for(var k in list){
  822. var b = list[k].val;
  823. if(sumType == 2){
  824. b = (list[k].val + "").replace(",", "");
  825. }
  826. all += parseFloat(b);
  827. }
  828. return all;
  829. }
  830. //获取近阶段时间的开始时间和结束时间
  831. var now = new Date();
  832. /*
  833. * months : 月份差距(例如months=3,则获取今天往前数3个月的那天的值)
  834. */
  835. function getStartDate(months,type){
  836. //type: 折线图坐标值1-日,2-周,3-月
  837. //从1号开始算每个月开始的时间
  838. var sDate = new Date();
  839. sDate.setMonth(now.getMonth() - months + 1);// 包含本月算一个月
  840. var sDateStr = sDate.format("yyyy-MM-dd");
  841. if(type == '3'){
  842. startDate = sDateStr.substr(0,8)+"01";
  843. }else{
  844. startDate = sDateStr;
  845. }
  846. }
  847. function getEndDate(){
  848. endDate = now.format("yyyy-MM-dd");
  849. }
  850. //获取数据最大值
  851. function maxData(data){
  852. var maxData = Math.max.apply(Math,data);
  853. var yAxis = maxData<10?10:maxData;
  854. return yAxis;
  855. }
  856. //给金额数值加上逗号
  857. function formatAmount(str) {
  858. var newStr = "";
  859. var count = 0;
  860. if(str.indexOf(".") == -1) {
  861. for(var i = str.length - 1; i >= 0; i--) {
  862. if(count % 3 == 0 && count != 0) {
  863. newStr = str.charAt(i) + "," + newStr;
  864. } else {
  865. newStr = str.charAt(i) + newStr;
  866. }
  867. count++;
  868. }
  869. str = newStr + ".00"; //自动补小数点后两位
  870. } else {
  871. for(var i = str.indexOf(".") - 1; i >= 0; i--) {
  872. if(count % 3 == 0 && count != 0) {
  873. newStr = str.charAt(i) + "," + newStr;
  874. } else {
  875. newStr = str.charAt(i) + newStr; //逐个字符相接起来
  876. }
  877. count++;
  878. }
  879. str = newStr + (str + "00").substr((str + "00").indexOf("."), 3);
  880. }
  881. return str;
  882. }
  883. //返回事件
  884. var old_back = mui.back;
  885. mui.back = function(){
  886. if(reqList.length == 1){
  887. old_back();
  888. }
  889. else{
  890. var preInfo = reqList.pop();
  891. var info = reqList[reqList.length - 1];
  892. level = info.level;
  893. code = info.code;
  894. areaTitle = info.areaTitle;
  895. lowlevel = info.lowlevel;
  896. sumType = info.sumType;
  897. tagCode = info.tagCode;
  898. $("#areaTitle").html(areaTitle);
  899. showLabs();
  900. initReqParams();
  901. loadData([0,1,2]);
  902. }
  903. }