index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  1. <template>
  2. <div class="statistical-page" ref="container">
  3. <div class="navs">
  4. <div class="list">
  5. <div class="item" :class="time == 'today' ? 'on' : ''" @click="setTime('today')">
  6. {{ $t(`今天`) }}
  7. </div>
  8. <div class="item" :class="time == 'yesterday' ? 'on' : ''" @click="setTime('yesterday')">
  9. {{ $t(`昨天`) }}
  10. </div>
  11. <div class="item" :class="time == 'seven' ? 'on' : ''" @click="setTime('seven')">
  12. {{ $t(`最近7天`) }}
  13. </div>
  14. <div class="item" :class="time == 'month' ? 'on' : ''" @click="setTime('month')">
  15. {{ $t(`本月`) }}
  16. </div>
  17. <div class="item" :class="time == 'date' ? 'on' : ''" @click="dateTitle">
  18. <!-- <span class="iconfont icon-xiangxia"></span>
  19. <span v-for="(value, index) in renderValues" :key="index">
  20. {{ value }}</span
  21. > -->
  22. {{ $t(`自定义`) }}
  23. </div>
  24. </div>
  25. </div>
  26. <div class="wrapper">
  27. <div class="title">{{ time == 'date' ? '' : title }}{{ where.type == 1 ? $t(`营业额(元)`) : $t(`订单量(份)`) }}</div>
  28. <div class="money">{{ time_price }}</div>
  29. <div class="increase acea-row row-between-wrapper">
  30. <div>
  31. {{ time == 'date' ? '' : title }}{{ $t(`增长率`) }}:
  32. <span :class="increase_time_status === 1 ? 'red' : 'green'">
  33. {{ increase_time_status === 1 ? '' : '-' }}{{ growth_rate }}%
  34. <span class="iconfont" :class="increase_time_status === 1 ? 'icon-xiangshang1' : 'icon-xiangxia2'"></span>
  35. </span>
  36. </div>
  37. <div>
  38. {{ time == 'date' ? '' : title }}{{ $t(`增长`) }}:
  39. <span :class="increase_time_status === 1 ? 'red' : 'green'">
  40. {{ increase_time_status === 1 ? '' : '-' }}{{ increase_time }}
  41. <span class="iconfont" :class="increase_time_status === 1 ? 'icon-xiangshang1' : 'icon-xiangxia2'"></span>
  42. </span>
  43. </div>
  44. </div>
  45. </div>
  46. <div class="chart">
  47. <div class="chart-title">{{ $t(`单位`) }}({{ where.type == 1 ? $t(`元.`) : $t(`份`) }})</div>
  48. <canvas canvas-id="canvasLineA" id="canvasLineA" class="charts" disable-scroll="true" @touchstart="touchLineA" @touchmove="moveLineA" @touchend="touchEndLineA"></canvas>
  49. </div>
  50. <div class="public-wrapper">
  51. <div class="title">
  52. <span class="iconfont icon-xiangxishuju"></span>
  53. {{ $t(`详细数据`) }}
  54. </div>
  55. <div class="nav acea-row row-between-wrapper">
  56. <div class="data">{{ $t(`日期`) }}</div>
  57. <div class="browse">{{ $t(`订单数`) }}</div>
  58. <div class="turnover">{{ $t(`成交额`) }}</div>
  59. </div>
  60. <div class="conter">
  61. <div class="item acea-row row-between-wrapper" v-for="(item, index) in list" :key="index">
  62. <div class="data">{{ item.time }}</div>
  63. <div class="browse">{{ item.count }}</div>
  64. <div class="turnover">{{ item.price }}</div>
  65. </div>
  66. </div>
  67. </div>
  68. <!-- #ifdef H5 || APP-PLUS -->
  69. <uni-calendar
  70. ref="calendar"
  71. :date="info.date"
  72. :insert="info.insert"
  73. :lunar="info.lunar"
  74. :startDate="info.startDate"
  75. :endDate="info.endDate"
  76. :range="info.range"
  77. @confirm="confirm"
  78. :showMonth="info.showMonth"
  79. />
  80. <div class="mask" @touchmove.prevent v-show="current === true" @click="close"></div>
  81. <!-- #endif -->
  82. <!-- <Loading :loaded="loaded" :loading="loading"></Loading> -->
  83. </div>
  84. </template>
  85. <script>
  86. import uCharts from '../components/ucharts/ucharts';
  87. import uniCalendar from '../components/uni-calendar/uni-calendar.vue';
  88. var canvaLineA = null;
  89. // import Calendar from 'mpvue-calendar'
  90. // #ifdef MP-WEIXIN
  91. // import 'mpvue-calendar/src/style.css
  92. // #endif
  93. // #ifdef H5
  94. // import 'mpvue-calendar/src/browser-style.css'
  95. // #endif
  96. import { getStatisticsMonth, getStatisticsTime } from '@/api/admin';
  97. // import Loading from "@components/Loading";
  98. const year = new Date().getFullYear();
  99. const month = new Date().getMonth() + 1;
  100. const day = new Date().getDate();
  101. export default {
  102. name: 'Statistics',
  103. components: {
  104. // Calendar,
  105. // uCharts
  106. uniCalendar
  107. },
  108. props: {},
  109. data: function () {
  110. return {
  111. value: [
  112. [year, month, day - 1],
  113. [year, month, day]
  114. ],
  115. isrange: true,
  116. weekSwitch: false,
  117. ismulti: false,
  118. monFirst: true,
  119. clean: false, //简洁模式
  120. lunar: false, //显示农历
  121. renderValues: [],
  122. monthRange: [],
  123. current: false,
  124. where: {
  125. start: '',
  126. stop: '',
  127. type: ''
  128. },
  129. types: '', //类型|order=订单数|price=营业额
  130. time: '', //时间|today=今天|yesterday=昨天|month=本月
  131. title: '', //时间|today=今天|yesterday=昨天|month=本月
  132. growth_rate: '', //增长率
  133. increase_time: '', //增长率
  134. increase_time_status: '', //增长率
  135. time_price: '', //增长率
  136. loaded: false,
  137. loading: false,
  138. filter: {
  139. page: 1,
  140. limit: 10,
  141. start: '',
  142. stop: ''
  143. },
  144. list: [],
  145. // charts
  146. cWidth: '',
  147. cHeight: '',
  148. pixelRatio: 1,
  149. textarea: '',
  150. LineA: {
  151. categories: ['2012', '2013', '2014', '2015', '2016', '2017'],
  152. series: [
  153. {
  154. data: [35, 8, 25, 37, 4, 20]
  155. }
  156. ]
  157. },
  158. info: {
  159. startDate: '',
  160. endDate: '',
  161. lunar: false,
  162. range: true,
  163. insert: false,
  164. selected: [],
  165. showMonth: false
  166. },
  167. type: '',
  168. before: '',
  169. after: ''
  170. };
  171. },
  172. watch: {
  173. '$route.params': function (newVal) {
  174. var that = this;
  175. if (newVal != undefined) {
  176. that.setType(newVal.type);
  177. that.setTime(newVal.time);
  178. that.getIndex();
  179. }
  180. }
  181. },
  182. onLoad: function (options) {
  183. this.type = options.type;
  184. if (options.before) {
  185. this.before = options.before;
  186. }
  187. if (options.after) {
  188. this.after = options.after;
  189. }
  190. this.setType(options.type);
  191. this.setTime(options.time);
  192. this.cWidth = uni.upx2px(690);
  193. this.cHeight = uni.upx2px(500);
  194. // this.handelRenderValues();
  195. // this.getIndex();
  196. this.getInfo();
  197. // this.$scroll(this.$refs.container, () => {
  198. // !this.loading && this.getInfo();
  199. // });
  200. },
  201. computed: {
  202. monthRangeText() {
  203. return this.monthRange.length ? this.$t(`固定`) : this.$t(`指定范围`);
  204. }
  205. },
  206. methods: {
  207. getIndex: function () {
  208. let tempDay = [];
  209. let tempNum = [];
  210. var that = this;
  211. getStatisticsTime(that.where).then(
  212. (res) => {
  213. var _info = res.data.chart,
  214. day = [],
  215. num = [];
  216. _info.forEach(function (item) {
  217. day.push(item.time);
  218. num.push(item.num);
  219. });
  220. that.growth_rate = res.data.growth_rate;
  221. that.increase_time = res.data.increase_time;
  222. that.increase_time_status = res.data.increase_time_status;
  223. that.time_price = res.data.time;
  224. res.data.chart.forEach((item, index) => {
  225. tempDay.push(item.time);
  226. tempNum.push(item.num);
  227. });
  228. that.LineA.categories = tempDay;
  229. that.LineA.series[0].data = tempNum;
  230. that.showLineA('canvasLineA', that.LineA);
  231. },
  232. (error) => {
  233. that.$util.Tips({
  234. title: error
  235. });
  236. }
  237. );
  238. },
  239. setTime: function (time) {
  240. let self = this;
  241. this.time = time;
  242. var year = new Date().getFullYear(),
  243. month = new Date().getMonth() + 1,
  244. day = new Date().getDate();
  245. this.list = [];
  246. this.filter.page = 1;
  247. this.loaded = false;
  248. this.loading = false;
  249. switch (time) {
  250. case 'today':
  251. this.where.start = new Date(Date.parse(year + '/' + month + '/' + day)).getTime() / 1000;
  252. this.where.stop = new Date(Date.parse(year + '/' + month + '/' + day)).getTime() / 1000 + 24 * 60 * 60 - 1;
  253. this.title = this.$t(`今天`);
  254. this.getIndex();
  255. this.getInfo();
  256. break;
  257. case 'yesterday':
  258. this.where.start = new Date(Date.parse(year + '/' + month + '/' + day)).getTime() / 1000 - 24 * 60 * 60;
  259. this.where.stop = new Date(Date.parse(year + '/' + month + '/' + day)).getTime() / 1000 - 1;
  260. this.title = this.$t(`昨天`);
  261. this.getIndex();
  262. this.getInfo();
  263. break;
  264. case 'month':
  265. this.where.start = new Date(year, new Date().getMonth(), 1).getTime() / 1000;
  266. this.where.stop = new Date(year, month, 1).getTime() / 1000 - 1;
  267. this.title = this.$t(`本月`);
  268. this.getIndex();
  269. this.getInfo();
  270. break;
  271. case 'seven':
  272. this.where.start = new Date(Date.parse(year + '/' + month + '/' + day)).getTime() / 1000 + 24 * 60 * 60 - 7 * 3600 * 24;
  273. this.where.stop = new Date(Date.parse(year + '/' + month + '/' + day)).getTime() / 1000 + 24 * 60 * 60 - 1;
  274. this.title = this.$t(`最近7天`);
  275. this.getIndex();
  276. this.getInfo();
  277. break;
  278. // #ifdef MP
  279. case 'date':
  280. let sArr = self.before.split('-');
  281. let aArr = self.after.split('-');
  282. let star = this.getTimestamp(sArr[0], sArr[1], sArr[2], 0, 0, 0);
  283. let stop = this.getTimestamp(aArr[0], aArr[1], aArr[2], 23, 59, 59);
  284. self.where.start = star;
  285. self.where.stop = stop;
  286. Promise.all([self.getIndex(), self.getInfo()]);
  287. break;
  288. // #endif
  289. }
  290. },
  291. getTimestamp(year, month, day, hour, min, sec) {
  292. return new Date(year, month - 1, day, hour, min, sec).getTime() / 1000;
  293. },
  294. setType: function (type) {
  295. switch (type) {
  296. case 'price':
  297. this.where.type = 1;
  298. break;
  299. case 'order':
  300. this.where.type = 2;
  301. break;
  302. }
  303. },
  304. dateTitle: function () {
  305. // #ifdef H5 || APP-PLUS
  306. this.$refs.calendar.open();
  307. this.time = 'date';
  308. // #endif
  309. // #ifdef MP
  310. uni.navigateTo({
  311. url: '/pages/admin/custom_date/index?type=' + this.type
  312. });
  313. // #endif
  314. // this.current = true;
  315. },
  316. close: function () {
  317. this.current = false;
  318. },
  319. getInfo: function () {
  320. var that = this;
  321. if (that.loading || that.loaded) return;
  322. that.loading = true;
  323. that.filter.start = that.where.start;
  324. that.filter.stop = that.where.stop;
  325. getStatisticsMonth(that.filter).then(
  326. (res) => {
  327. that.loading = false;
  328. that.loaded = res.data.length < that.filter.limit;
  329. that.list.push.apply(that.list, res.data);
  330. that.filter.page = that.filter.page + 1;
  331. },
  332. (error) => {
  333. that.$util.Tips({
  334. title: error
  335. });
  336. }
  337. );
  338. },
  339. // 创建charts
  340. showLineA(canvasId, chartData) {
  341. let _self = this;
  342. canvaLineA = new uCharts({
  343. $this: _self,
  344. canvasId: canvasId,
  345. type: 'line',
  346. fontSize: 11,
  347. padding: [15, 15, 0, 15],
  348. legend: {
  349. show: false,
  350. padding: 5,
  351. lineHeight: 11,
  352. margin: 5
  353. },
  354. dataLabel: true,
  355. dataPointShape: true,
  356. dataPointShapeType: 'hollow',
  357. background: '#FFFFFF',
  358. pixelRatio: _self.pixelRatio,
  359. categories: chartData.categories,
  360. series: chartData.series,
  361. animation: true,
  362. enableScroll: true, //开启图表拖拽功能
  363. xAxis: {
  364. disableGrid: false,
  365. type: 'grid',
  366. gridType: 'dash',
  367. itemCount: 4,
  368. scrollShow: true,
  369. scrollAlign: 'left'
  370. },
  371. yAxis: {
  372. //disabled:true
  373. gridType: 'dash',
  374. splitNumber: 8,
  375. min: 0,
  376. max: 30,
  377. format: (val) => {
  378. return val.toFixed(0);
  379. } //如不写此方法,Y轴刻度默认保留两位小数
  380. },
  381. width: _self.cWidth * _self.pixelRatio,
  382. height: _self.cHeight * _self.pixelRatio,
  383. extra: {
  384. line: {
  385. type: 'straight'
  386. }
  387. }
  388. });
  389. },
  390. // charts触摸事件
  391. touchLineA(e) {
  392. canvaLineA.scrollStart(e);
  393. },
  394. moveLineA(e) {
  395. canvaLineA.scroll(e);
  396. },
  397. touchEndLineA(e) {
  398. canvaLineA.scrollEnd(e);
  399. },
  400. // 日历确定
  401. confirm(e) {
  402. let self = this;
  403. if (e.range.after && e.range.before) {
  404. let star = new Date(e.range.before + ' 00:00:00').getTime() / 1000;
  405. let stop = new Date(e.range.after + ' 23:59:59').getTime() / 1000;
  406. self.where.start = star > stop ? stop :star ;
  407. self.where.stop = star < stop ? stop :star;
  408. self.list = [];
  409. self.filter.page = 1;
  410. self.loaded = false;
  411. self.loading = false;
  412. Promise.all([self.getIndex(), self.getInfo()]);
  413. }
  414. }
  415. },
  416. onReachBottom() {
  417. this.getInfo();
  418. }
  419. };
  420. </script>
  421. <style>
  422. /*交易额统计*/
  423. .statistical-page .navs {
  424. width: 100%;
  425. height: 96upx;
  426. background-color: #fff;
  427. overflow: hidden;
  428. line-height: 96upx;
  429. position: fixed;
  430. top: 0;
  431. left: 0;
  432. z-index: 9;
  433. }
  434. .statistical-page .navs .list {
  435. overflow-y: hidden;
  436. overflow-x: auto;
  437. white-space: nowrap;
  438. -webkit-overflow-scrolling: touch;
  439. width: 100%;
  440. }
  441. .statistical-page .navs .item {
  442. font-size: 32upx;
  443. color: #282828;
  444. margin-left: 60upx;
  445. display: inline-block;
  446. }
  447. .statistical-page .navs .item.on {
  448. color: #2291f8;
  449. }
  450. .statistical-page .navs .item .iconfont {
  451. font-size: 25upx;
  452. margin-left: 13upx;
  453. }
  454. .statistical-page .wrapper {
  455. width: 740upx;
  456. background-color: #fff;
  457. border-radius: 10upx;
  458. margin: 119upx auto 0 auto;
  459. padding: 50upx 60upx;
  460. }
  461. .statistical-page .wrapper .title {
  462. font-size: 30upx;
  463. color: #999;
  464. text-align: center;
  465. }
  466. .statistical-page .wrapper .money {
  467. font-size: 72upx;
  468. color: #fba02a;
  469. text-align: center;
  470. margin-top: 10upx;
  471. }
  472. .statistical-page .wrapper .increase {
  473. font-size: 28upx;
  474. color: #999;
  475. margin-top: 20upx;
  476. }
  477. .statistical-page .wrapper .increase .red {
  478. color: #ff6969;
  479. }
  480. .statistical-page .wrapper .increase .green {
  481. color: #1abb1d;
  482. }
  483. .statistical-page .wrapper .increase .iconfont {
  484. font-size: 23upx;
  485. margin-left: 15upx;
  486. }
  487. .statistical-page .chart {
  488. width: 690upx;
  489. background-color: #fff;
  490. border-radius: 10upx;
  491. margin: 23upx auto 0 auto;
  492. /* padding: 25upx 22upx 0 22upx; */
  493. }
  494. .statistical-page .chart .chart-title {
  495. padding: 20upx 20upx 10upx;
  496. font-size: 26upx;
  497. color: #999;
  498. }
  499. .statistical-page .chart canvas {
  500. width: 100%;
  501. height: 530rpx;
  502. }
  503. .statistical-page .chart .company {
  504. font-size: 26upx;
  505. color: #999;
  506. }
  507. .yd-confirm {
  508. background-color: #fff;
  509. font-size: unset;
  510. width: 540upx;
  511. height: 250upx;
  512. border-radius: 40upx;
  513. }
  514. .yd-confirm-hd {
  515. text-align: center;
  516. }
  517. .yd-confirm-title {
  518. color: #030303;
  519. font-weight: bold;
  520. font-size: 36upx;
  521. }
  522. .yd-confirm-bd {
  523. text-align: center;
  524. font-size: 28upx;
  525. color: #333333;
  526. }
  527. .yd-confirm-ft {
  528. line-height: 90upx;
  529. margin-top: 14px;
  530. border-top: 1upx solid #eee;
  531. }
  532. .yd-confirm-ft > a {
  533. color: #e93323;
  534. }
  535. .yd-confirm-ft > a.primary {
  536. border-left: 1upx solid #eee;
  537. color: #e93323;
  538. }
  539. .echarts {
  540. width: 100%;
  541. height: 550upx;
  542. }
  543. .calendar-wrapper {
  544. position: fixed;
  545. bottom: 0;
  546. left: 0;
  547. width: 100%;
  548. z-index: 777;
  549. transform: translate3d(0, 100%, 0);
  550. transition: all 0.3s cubic-bezier(0.25, 0.5, 0.5, 0.9);
  551. }
  552. .calendar-wrapper.on {
  553. transform: translate3d(0, 0, 0);
  554. }
  555. .statistical-page .wrapper .increase {
  556. font-size: 26upx;
  557. }
  558. .statistical-page .wrapper .increase .iconfont {
  559. margin-left: 0;
  560. }
  561. .public-wrapper .title {
  562. font-size: 30upx;
  563. color: #282828;
  564. padding: 0 30upx;
  565. margin-bottom: 20upx;
  566. }
  567. .public-wrapper .title .iconfont {
  568. color: #2291f8;
  569. font-size: 40upx;
  570. margin-right: 13upx;
  571. vertical-align: middle;
  572. }
  573. .public-wrapper {
  574. margin: 18upx auto 0 auto;
  575. width: 690upx;
  576. background-color: #fff;
  577. border-radius: 10upx;
  578. padding-top: 25upx;
  579. }
  580. .public-wrapper .nav {
  581. padding: 0 30upx;
  582. height: 70upx;
  583. line-height: 70upx;
  584. font-size: 24upx;
  585. color: #999;
  586. }
  587. .public-wrapper .data {
  588. width: 210upx;
  589. text-align: left;
  590. }
  591. .public-wrapper .browse {
  592. width: 192upx;
  593. text-align: right;
  594. }
  595. .public-wrapper .turnover {
  596. width: 227upx;
  597. text-align: right;
  598. }
  599. .public-wrapper .conter {
  600. padding: 0 30upx;
  601. }
  602. .public-wrapper .conter .item {
  603. border-bottom: 1px solid #f7f7f7;
  604. height: 70upx;
  605. font-size: 24upx;
  606. }
  607. .public-wrapper .conter .item .turnover {
  608. color: #d84242;
  609. }
  610. </style>