income-time.html 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8"/>
  5. <meta name="author" content=""/>
  6. <meta name="description" content=""/>
  7. <meta name="keywords" content="扫码支付,线上投币,运营数据,物联网"/>
  8. <meta name="format-detection" content="telphone=no,email=no"/>
  9. <meta name="viewport"
  10. content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
  11. <meta http-equiv="pragma" content="no-cache">
  12. <meta http-equiv="cache-control" content="no-cache">
  13. <meta http-equiv="expires" content="0">
  14. <title>趋势</title>
  15. <link rel="stylesheet" href="https://cdn.washpayer.com/components/lib/mui.min.css"/>
  16. <link rel="stylesheet" href="https://cdn.washpayer.com/components/lib/mui.picker.min.css"/>
  17. <link rel="stylesheet" href="../components/custom/css/common.css"/>
  18. <link rel="stylesheet" href="css/xyf.common.min.css">
  19. <style>
  20. [my-control-content] {
  21. display: none;
  22. }
  23. [my-control-content].active {
  24. display: block;
  25. }
  26. /*避免键盘导致半屏显示*/
  27. .income-segmented {
  28. display: none;
  29. position: relative;
  30. }
  31. .income-segmented.active {
  32. display: block;
  33. }
  34. </style>
  35. </head>
  36. <body class="income-trend income-time income-panel">
  37. <div class="mui-input-group ">
  38. <div class="mui-row">
  39. <div class="mui-col-xs-9 mui-col-sm-9 padding-l-10" style="padding-top: 6px">
  40. <span class="mui-btn mui-btn-outlined btn-outlined-check filter-btn-custom" my-control-item="month"
  41. key="chartMonth">月统计</span>
  42. <span class="mui-btn mui-btn-outlined btn-outlined-check filter-btn-custom" my-control-item="year0" range="0"
  43. key="chartYear">今年</span>
  44. <span class="mui-btn mui-btn-outlined btn-outlined-check filter-btn-custom" my-control-item="year1" range="1"
  45. key="chartYear">去年</span>
  46. <span class="mui-btn mui-btn-outlined btn-outlined-check filter-btn-custom" my-control-item="year2" range="2"
  47. key="chartYear">前年</span>
  48. </div>
  49. <div class="mui-col-xs-3 mui-col-sm-3 mui-text-right">
  50. <div class="filter-btn padding-l-r-5" onclick="goDownload()" id="goDownload"><i
  51. class="iconfont icon-download font-18"></i></div>
  52. <div class="filter-btn padding-l-r-5" onclick="showChart()"><i
  53. class="iconfont icon-chart-line font-18"></i></div>
  54. </div>
  55. </div>
  56. </div>
  57. <div class="filter-panel" style="display: none" id="options">
  58. <div class="input-group-vertical mui-table-view clear-b-border">
  59. <div style="background: #def;color: #333;font-size: 12px;padding: 10px;">
  60. 注:为加速查询性能,提供更好的查询体验,系统仅支持查询最近3年的订单统计数据。
  61. </div>
  62. <div class="mui-input-row input-clear or-order-status" id="targetMonthRow">
  63. <label class="or-label-text">选择月份</label>
  64. <span class="mui-icon mui-icon-arrowright"></span>
  65. <span class="or-order-status-font selected-text" id="targetMonth"></span>
  66. </div>
  67. <div class="mui-input-row filter-panel-btn flexbox">
  68. <span class="ok-btn flex">确定</span>
  69. </div>
  70. </div>
  71. </div>
  72. <div class="filter-panel" style="display: none" id="options2">
  73. <div class="input-group-vertical mui-table-view clear-b-border datepicker">
  74. <!-- 暂时隐藏-->
  75. <div class="mui-input-row input-clear or-order-status" id="targetYearRow" style="">
  76. <label class="or-label-text">选择年份</label>
  77. <span class="mui-icon mui-icon-arrowright"></span>
  78. <span class="or-order-status-font selected-text" id="targetYear"></span>
  79. </div>
  80. <div class="mui-input-row filter-panel-btn flexbox">
  81. <span class="ok-btn flex">确定</span>
  82. </div>
  83. </div>
  84. </div>
  85. <div class="mui-table-view clear-before">
  86. <div class="mui-row head-status">
  87. <div class="font-bold mui-col-xs-6 mui-col-sm-6" id="categoryName">
  88. 收益情况
  89. </div>
  90. <div class="mui-col-xs-6 mui-col-sm-6 per-box">
  91. <div class="mui-pull-right" id="toggleCategory" onclick="toggleCategory()">
  92. <div class="mui-btn"><span style="-webkit-transform: rotate(0deg);">查看消费</span></div>
  93. <div class="mui-btn"><span style="-webkit-transform: rotate(0deg);">查看收益</span></div>
  94. </div>
  95. </div>
  96. </div>
  97. </div>
  98. <div class="mui-content income-segmented active" id="incomePanel">
  99. <div id="monthItem" my-control-content="month">
  100. <div class="chart-box" id="chartMonth-income"></div>
  101. <div class="index-hd " id="indexHdDay30">
  102. <i class="iconfont icon-purse purse-logo-back"></i>
  103. <a href="javascript:;" class="hd-tab">
  104. 本月总收益(元)<span id="monthIncome">0.00</span>
  105. </a>
  106. <div class="mui-table hd-cell " id="hdCellDay30">
  107. <div class="mui-table-cell mui-ellipsis">
  108. <span>在线支付</span><em id="payIncome">0.00元</em>
  109. </div>
  110. <div class="mui-table-cell mui-ellipsis mui-hidden">
  111. <span>线下投币</span><em id="offlineCoins">0.00次</em>
  112. </div>
  113. </div>
  114. </div>
  115. <ul class="mui-table-view" id="monthIncomeList"></ul>
  116. </div>
  117. <div id="yearItem" my-control-content="year">
  118. <div class="chart-box" id="chartYear-income"></div>
  119. </div>
  120. </div>
  121. <div class="mui-content income-segmented" id="consumePanel">
  122. <div id="consumeMonthItem" my-control-content="month">
  123. <div class="chart-box" id="chartMonth-consume"></div>
  124. <ul class="mui-table-view" id="monthConsumeList"></ul>
  125. </div>
  126. <div my-control-content="year">
  127. <div class="chart-box" id="chartYear-consume"></div>
  128. <ul class="mui-table-view" id="yearConsumeList"></ul>
  129. </div>
  130. </div>
  131. <script src="https://cdn.washpayer.com/components/lib/echarts.js"></script>
  132. <script src="https://cdn.washpayer.com/components/lib/echarts-theme/macarons.js"></script>
  133. <script src="https://cdn.washpayer.com/components/lib/jquery.min.js"></script>
  134. <script src="https://cdn.washpayer.com/components/lib/mui.min.js"></script>
  135. <script src="https://cdn.washpayer.com/components/lib/mui.picker.min.js"></script>
  136. <script src="https://cdn.washpayer.com/components/lib/moment.min.js"></script>
  137. <script src="/components/custom/js/common.js"></script>
  138. <script src="js/xyf.common.js"></script>
  139. <script>
  140. var targetMonth = moment().format("YYYY-MM");
  141. var targetYear = moment().format("YYYY");
  142. var thisRange = "month";// 或 year
  143. var categoryBtn = "income";// 或 consume
  144. $(function () {
  145. $('#targetMonth').text(targetMonth);
  146. $('#targetYear').text(targetYear);
  147. var targetMonthRow = $('#targetMonthRow');
  148. var targetMonthPicker = new mui.DtPicker({
  149. type: "month",
  150. beginDate: moment().add(-2, 'year').startOf("year").toDate(),
  151. endDate: new Date()
  152. });
  153. targetMonthPicker.setSelectedValue(targetMonth);//默认选中开始时间
  154. targetMonthRow[0].addEventListener('tap', function () {
  155. targetMonthPicker.show(function (time) {
  156. targetMonth = time.y.text + '-' + time.m.text;
  157. $('#targetMonth').text(targetMonth);
  158. });
  159. }, false);
  160. var targetYearRow = $('#targetYearRow');
  161. var targetYearPicker = new mui.PopPicker();
  162. var yearList = []
  163. var startY = moment().add(-2, 'year').format('YYYY')
  164. startY = parseInt(startY)
  165. for (var index = startY; index <= new Date().getFullYear(); index++) {
  166. yearList.push({
  167. value: index + "",
  168. text: index + "",
  169. })
  170. }
  171. targetYearPicker.setData(yearList);
  172. targetYearPicker.pickers[0].setSelectedValue(targetYear)
  173. targetYearRow[0].addEventListener('tap', function () {
  174. targetYearPicker.show(function (items) {
  175. targetYear = items[0].value;
  176. $('#targetYear').text(targetYear);
  177. });
  178. }, false);
  179. //快速选择年
  180. $('[range]').tap(function () {
  181. var range = $(this).attr('range');
  182. targetYear = moment().add(-range, "year").format("YYYY");
  183. triggerYear(range)
  184. });
  185. })
  186. FilterComponent(
  187. [
  188. {
  189. trigger: "[my-control-item='month']",
  190. panel: "#options",
  191. cancel: function () {
  192. if (thisRange !== 'month') {
  193. togActive(thisRange, theNum)
  194. }
  195. },
  196. ok: function () {
  197. thisRange = 'month';
  198. togActive(thisRange);
  199. if (categoryBtn === 'income') {
  200. initIncomePageData()
  201. } else {
  202. initConsumePageData()
  203. }
  204. $('#goDownload').show()
  205. }
  206. },
  207. {
  208. trigger: "[my-control-item='year']",
  209. panel: "#options2",
  210. cancel: function () {
  211. if (thisRange === 'month') {
  212. togActive("month")
  213. }
  214. },
  215. ok: function () {
  216. triggerYear()
  217. }
  218. },
  219. ]
  220. );
  221. let theNum = null
  222. function triggerYear(num) {
  223. thisRange = 'year';
  224. theNum = num
  225. togActive(thisRange, num);
  226. if (categoryBtn === 'income') {
  227. initIncomePageData()
  228. } else {
  229. initConsumePageData()
  230. }
  231. }
  232. function togActive(range, num) {
  233. $("[my-control-item]").removeClass("active");
  234. $("[my-control-content]").removeClass("active");
  235. let itemKey = range
  236. if (num != null) {
  237. itemKey = range + num
  238. }
  239. console.log(itemKey)
  240. $("[my-control-item='" + itemKey + "']").addClass("active");
  241. $("[my-control-content='" + range + "']").addClass("active");
  242. if (itemKey.includes('year')) {
  243. $('#goDownload').hide()
  244. } else {
  245. $('#goDownload').show()
  246. }
  247. }
  248. // 只加载一次
  249. var consumeLoaded = false;
  250. // 切换统计类目
  251. function toggleCategory() {
  252. var toggleCategoryDom = $("#toggleCategory");
  253. if (toggleCategoryDom.hasClass("disabled")) {
  254. return
  255. }
  256. toggleCategoryDom.addClass("disabled");
  257. if (categoryBtn == "income") {
  258. categoryBtn = "consume";
  259. $("#categoryName").text("消费情况");
  260. toggleCategoryDom.addClass("rotate");
  261. $("#incomePanel").animate({left: "-100%"}, function () {
  262. $("#incomePanel").removeClass("active");
  263. $("#consumePanel").addClass("active").css({left: "0"});
  264. refreshData()
  265. });
  266. } else {
  267. categoryBtn = "income";
  268. $("#categoryName").text("收益情况");
  269. toggleCategoryDom.removeClass("rotate");
  270. $("#consumePanel").animate({left: "100%"}, function () {
  271. $("#incomePanel").addClass("active").css({left: "0"});
  272. $("#consumePanel").removeClass("active");
  273. refreshData();
  274. });
  275. }
  276. function refreshData() {
  277. if (categoryBtn == "consume") {
  278. initConsumePageData()
  279. } else {
  280. initIncomePageData()
  281. }
  282. // 动画结束后,还是需要等待 列表加载完,页面的mask才移除
  283. toggleCategoryDom.removeClass("disabled");
  284. }
  285. }
  286. //初始化
  287. var featureList = {};
  288. getFeatureList("dealer", {list: ['show_offline_coins']}, function (payload) {
  289. featureList = payload;
  290. togActive("month");
  291. // 加载收益
  292. initIncomePageData();
  293. });
  294. function initIncomePageData(callback) {
  295. var mask = new Mask({text: "正在加载数据...", performance: true}).show(true);//禁止动画,否则顶部的tab渲染有问题
  296. if (thisRange === 'month') {
  297. var url = "/dealer/lastMonthIncome";
  298. sendRequest(url, "GET", {time: targetMonth}, function (response) {
  299. var payload = response.payload
  300. if (response.result === 1) {
  301. var monthIncomeList = "";
  302. var monthPayIncome = parseFloat(payload.payIncome) >= 0 ? ('+' + payload.payIncome) : payload.payIncome;
  303. var monthLineCoins = payload.offlineCoins;
  304. for (var i = 0, len = payload.dataList.length; i < len; i++) {
  305. var item = payload.dataList[i];
  306. var eq0 = parseFloat(item.payIncome) >= 0
  307. var payIncome = eq0 ? ('+' + item.payIncome) : item.payIncome;//线上支付
  308. var offlineCoins = parseFloat(item.offlineCoins) >= 0 ? ('+' + item.offlineCoins) : item.offlineCoins;//线下支付
  309. var startTime = moment(item.dateStr).format("YYYY-MM-DD");
  310. var endTime = startTime;
  311. monthIncomeList += '<li class="mui-table-view-cell"><a class="mui-navigate-right" ' +
  312. 'onclick="goIncomeList(\'' + startTime + '\', \'' + endTime + '\')" >' +
  313. item.dateText +
  314. (featureList.show_offline_coins ? '<span class="mui-pull-right custom-right font-12">线下<em>' + offlineCoins + '</em> </span>' : '') +
  315. '<span class="mui-pull-right custom-right font-12">在线<em class="' + (eq0? "c-red" : "") + '">' + payIncome + '</em> </span>' +
  316. '</a></li>';
  317. }
  318. readyChartData(payload.dataList, "chartMonth-income");
  319. $("#payIncome").html(monthPayIncome);
  320. if (featureList.show_offline_coins) {
  321. $("#offlineCoins").html((monthLineCoins) + "次").parent().removeClass("mui-hidden");
  322. }
  323. $("#monthIncome").html(payload.totalIncome);//30天总收入【!!!注意,不统计线下投币!!!】
  324. // 渲染页面
  325. $("#monthIncomeList").html(monthIncomeList);
  326. } else {
  327. mui.toast(response.description);
  328. }
  329. mask.remove();
  330. });
  331. }
  332. if (thisRange === 'year') {
  333. url = "/dealer/lastYearIncome";
  334. sendRequest(url, "GET", {time: targetYear}, function (response) {
  335. if (response.result == 1) {
  336. var payload = response.payload
  337. var halfYearIncomeList = "";
  338. for (var i = 0, len = payload.dataList.length; i < len; i++) {
  339. var item = payload.dataList[i];
  340. var offlineCoins = (item.offlineCoins);//线下支付
  341. var payIncome = parseFloat(item.payIncome) >= 0 ? ('+' + item.payIncome) : item.payIncome;//在线支付
  342. var totalIncome = (item.totalIncome);//广告加线上
  343. var startTime = moment(item.dateStr).format("YYYY-MM-DD");
  344. var endTime = moment(item.dateStr).endOf('month').format("YYYY-MM-DD");
  345. halfYearIncomeList += '<div class="index-hd custom-bottom">' +
  346. '<i class="iconfont icon-purse purse-logo-back"></i>' +
  347. '<a onclick="goIncomeList(\'' + startTime + '\', \'' + endTime + '\')" class="hd-tab">' +
  348. '' + item.dateText + '收益(元)<span id="halfYearIncome">' + (totalIncome) + '</span>' + //【!!!注意,不统计线下投币!!!】
  349. '</a>' +
  350. '<div class="mui-table hd-cell">' +
  351. '<div class="mui-table-cell mui-ellipsis">' +
  352. '<span>在线支付</span>' + payIncome + '' +
  353. '</div>' +
  354. (featureList.show_offline_coins ? '<div class="mui-table-cell mui-ellipsis">' +
  355. '<span>线下投币</span>' + offlineCoins + '次' +
  356. '</div>' : '') +
  357. '</div>' +
  358. '</div></div>';
  359. }
  360. readyChartData(payload.dataList, "chartYear-income");
  361. $("#yearItem .index-hd").remove();
  362. $("#yearItem").append(halfYearIncomeList);
  363. } else {
  364. mui.toast(response.description);
  365. }
  366. mask.remove();
  367. });
  368. }
  369. }
  370. function initConsumePageData(callback) {
  371. var mask = new Mask({text: "正在加载数据...", performance: true}).show(true);//禁止动画,否则顶部的tab渲染有问题
  372. if (thisRange === 'month') {
  373. var url = "/dealer/lastMonthConsumption";
  374. sendRequest(url, "GET", {time: targetMonth}, function (response) {
  375. toHtml(response, "month");
  376. mask.remove();
  377. });
  378. }
  379. if (thisRange === 'year') {
  380. url = "/dealer/lastYearConsumption";
  381. sendRequest(url, "GET", {time: targetYear}, function (response) {
  382. toHtml(response, "year");
  383. mask.remove();
  384. });
  385. }
  386. function toHtml(response, range) {
  387. if (response.result == 1) {
  388. var htmlMod = "";
  389. for (var i = 0, len = response.para.dataList.length; i < len; i++) {
  390. var item = response.para.dataList[i];
  391. var startTime = moment(item.dateStr).format("YYYY-MM-DD");
  392. var endTime = startTime;
  393. if (range === 'year') {
  394. endTime = moment(item.dateStr).endOf('month').format("YYYY-MM-DD");
  395. }
  396. var consumptionListDom = '';
  397. for (var index in item.consumptionList) {
  398. var itemIn = item.consumptionList[index];
  399. consumptionListDom = consumptionListDom + '<p class="font-b-6">' + itemIn.name + '<span class="mui-pull-right font-b font-b-12">' + itemIn.value + itemIn.unit + '</span></p>';
  400. }
  401. // 如果没有数据,则显示 无数据
  402. if (consumptionListDom === '') {
  403. consumptionListDom = consumptionListDom + '<p class="font-b-6">没有记录<span class="mui-pull-right font-b font-b-12"></span></p>';
  404. }
  405. htmlMod += '<li class="mui-table-view-cell"><a class="mui-navigate-right" ' +
  406. 'onclick="goConsumeList(\'' + startTime + '\', \'' + endTime + '\')" >' +
  407. item.dateText +
  408. '<div class="padding-r-10 margin-t-10">' +
  409. consumptionListDom +
  410. '</div></a></li>';
  411. }
  412. var chartDomId = "";
  413. if (range == "month") {
  414. chartDomId = "chartMonth-consume";
  415. $("#monthConsumeList").html(htmlMod);
  416. } else if (range == "year") {
  417. chartDomId = "chartYear-consume";
  418. $("#yearConsumeList").html(htmlMod);
  419. }
  420. readyChartData(response.para.dataList, chartDomId);
  421. } else {
  422. mui.toast(response.description);
  423. }
  424. }
  425. }
  426. var chartData = {};
  427. var chartEntity = {};
  428. //缓存echarts数据
  429. function readyChartData(list, id) {
  430. // 目前只需要补全消费数据,收益数据结构有所不同
  431. if (id.indexOf("consume") > -1) {
  432. fixChartData(list);
  433. }
  434. chartData[id] = list;
  435. initChartAndData(id)
  436. }
  437. //初始化echarts到页面
  438. function initChartAndData(id) {
  439. var list = chartData[id];
  440. // 数据没准备好也不用渲染
  441. if (!chartData[id]) {
  442. console.log(id + "数据为空,无法渲染echart")
  443. return
  444. }
  445. // 如果视图还看不见,则不用渲染,避免性能浪费; 因为用了 visibility, 通过高度 和 is(':visible')不准
  446. if ($("#" + id).css('visibility') === 'hidden') {
  447. console.log(id + "视图visibility = hidden,不可见,不用渲染echart")
  448. return
  449. }
  450. console.log("渲染echarts:" + id)
  451. var xData = [];
  452. var payIncome = [];
  453. var offlineCoins = [];
  454. var consumeSeriesMap = {};
  455. var length = list.length;
  456. for (var index in list) {
  457. // 正序时间排列
  458. var item = list[length - 1 - index];
  459. if (id.indexOf("chartYear") > -1) {
  460. xData.push(moment(item.dateStr).format("YY-MM"));
  461. } else if (id.indexOf("chartMonth") > -1) {
  462. xData.push(moment(item.dateStr).format("MM-DD"));
  463. }
  464. if (id.indexOf("income") > -1) {
  465. payIncome.push(parseFloat(item.payIncome));
  466. offlineCoins.push(parseFloat(item.offlineCoins));
  467. } else if (id.indexOf("consume") > -1) {
  468. var list2 = item.consumptionList;
  469. for (var index2 in list2) {
  470. var item2 = list2[index2];
  471. var name = item2.name;
  472. var value = item2.value;
  473. if (!consumeSeriesMap[name]) {
  474. consumeSeriesMap[name] = [];
  475. }
  476. consumeSeriesMap[name].push(value);
  477. }
  478. }
  479. }
  480. var option = {
  481. tooltip: {
  482. trigger: 'axis',
  483. axisPointer: {
  484. lineStyle: {
  485. color: '#108EE9',
  486. width: .3,
  487. }
  488. }
  489. },
  490. grid: {
  491. x: 40,
  492. x2: 15,
  493. y: 30,
  494. y2: 54,
  495. },
  496. //显示legend,因为有些数据很小,趋势不太明细
  497. legend: {
  498. bottom: 0,
  499. data: []
  500. },
  501. xAxis: [
  502. {
  503. type: 'category',
  504. axisLabel: {
  505. textStyle: {
  506. color: "#aaa",
  507. fontSize: "12px"
  508. }
  509. },
  510. axisTick: {
  511. show: false,
  512. },
  513. axisLine: {
  514. show: false,
  515. },
  516. data: xData
  517. }
  518. ],
  519. yAxis: [
  520. {
  521. type: 'value',
  522. axisLabel: {
  523. textStyle: {
  524. color: "#aaa",
  525. fontSize: "12px"
  526. }
  527. },
  528. axisTick: {
  529. show: false,
  530. },
  531. axisLine: {
  532. show: false,
  533. },
  534. splitLine: {
  535. lineStyle: {
  536. color: '#ccc',
  537. width: 0.3,
  538. type: 'dotted'
  539. }
  540. },
  541. },
  542. ],
  543. series: []
  544. };
  545. var legendData = [];
  546. // 收入和消费显示不同的图形
  547. if (id.indexOf("income") > -1) {
  548. legendData.push('在线支付')
  549. option.series.push({
  550. name: '在线支付',
  551. stack: '收入',
  552. type: 'bar',
  553. itemStyle: {
  554. color: "rgba(16,142,233,1)",
  555. },
  556. data: payIncome
  557. });
  558. if (featureList.show_offline_coins) {
  559. legendData.push('线下投币')
  560. option.series.push({
  561. name: '线下投币',
  562. stack: '收入',
  563. type: 'bar',
  564. itemStyle: {
  565. color: "#ACD8F7",
  566. },
  567. data: offlineCoins
  568. });
  569. }
  570. } else if (id.indexOf("consume") > -1) {
  571. for (var key in consumeSeriesMap) {
  572. legendData.push(key)
  573. var dataList = consumeSeriesMap[key];
  574. option.series.push({
  575. name: key,
  576. type: 'line',
  577. data: dataList
  578. });
  579. }
  580. }
  581. option.legend.data = legendData
  582. if (chartEntity[id]) {
  583. } else {
  584. var container = document.getElementById(id);
  585. chartEntity[id] = echarts.init(container);
  586. }
  587. chartEntity[id].setOption(option);
  588. chartEntity[id].resize();
  589. }
  590. // 由于早期的消费可能没有数据,需要给源数据,需要补齐 0,否则折现的时间轴和数据对应错误;
  591. function fixChartData(list) {
  592. // 找到所有key
  593. var allConsumKey = {};
  594. for (var index in list) {
  595. var item = list[index];
  596. var list2 = item.consumptionList;
  597. for (var index2 in list2) {
  598. var item2 = list2[index2];
  599. var name = item2.name;
  600. allConsumKey[name] = name;
  601. }
  602. }
  603. //修复该条数据。 这里只是多循环一次,性能问题不大。
  604. for (var index in list) {
  605. var item = list[index];
  606. if (!item.consumptionList) {
  607. item.consumptionList = []
  608. }
  609. var list2 = item.consumptionList;
  610. for (var key in allConsumKey) {
  611. var hasKeyFlag = false;
  612. for (var index2 in list2) {
  613. var item2 = list2[index2];
  614. var name = item2.name;
  615. // 如果有 key的消费数据,则找下一个key
  616. if (key === name) {
  617. hasKeyFlag = true;
  618. break;
  619. }
  620. }
  621. // 如果list2循环结束后,找不到key,则补全数据;
  622. if (!hasKeyFlag) {
  623. item.consumptionList.push({
  624. name: key,
  625. value: 0,
  626. });
  627. }
  628. }
  629. }
  630. }
  631. function goIncomeList(startTime, endTime) {
  632. var halfYear = moment().add(-6, 'month').startOf("month").format("YYYY-MM-DD");
  633. console.log(startTime, halfYear)
  634. if (startTime && moment(startTime).isBefore(halfYear)) {
  635. mui.toast('系统目前仅支持查询最近半年的订单明细数据(当前可查询' + halfYear + '起的数据)');
  636. } else {
  637. goPage('income-list.html?typeShow=income&startTime=' + startTime + '&endTime=' + endTime);
  638. }
  639. }
  640. function goConsumeList(startTime, endTime) {
  641. var halfYear = moment().add(-6, 'month').startOf("month").format("YYYY-MM-DD");
  642. console.log(startTime, halfYear)
  643. if (startTime && moment(startTime).isBefore(halfYear)) {
  644. mui.toast('系统目前仅支持查询最近半年的订单明细数据(当前可查询' + halfYear + '起的数据)');
  645. } else {
  646. goPage('income-list.html?typeShow=consume&startTime=' + startTime + '&endTime=' + endTime);
  647. }
  648. }
  649. // 列表和echarts模式切换
  650. var showChartFlag = false;
  651. function showChart() {
  652. var id = $("[my-control-content]:visible .chart-box").attr("id");
  653. if (showChartFlag) {
  654. $("[my-control-content]").removeClass("chart-active");
  655. $(".icon-chart-line").removeClass("active");
  656. } else {
  657. $("[my-control-content]").addClass("chart-active");
  658. $(".icon-chart-line").addClass("active");
  659. }
  660. showChartFlag = !showChartFlag;
  661. initChartAndData(id);
  662. }
  663. //因为该a标签已经用在mui的特性中,必须重新加上mui的tap事件,点击a标签才有反应
  664. mui('body').on('tap', '.mui-tab-item[data-href]', function () {
  665. replacePage($(this).attr("data-href"));
  666. });
  667. function goDownload(){
  668. var query = {
  669. kind: "monthly_bill",
  670. time: targetMonth
  671. }
  672. sendRequest({
  673. url: '/dealer/exportBusinessStats',
  674. data: query,
  675. type: 'GET',
  676. success: (data) => {
  677. var searchKey = ''
  678. if (data.result == 1) {
  679. searchKey = data.payload;
  680. }
  681. goPage('/dealer/index.html#/export/exportList?searchKey=' + searchKey);
  682. },
  683. })
  684. }
  685. </script>
  686. </body>
  687. </html>