index.vue 16 KB

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