index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  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. console.log(options)
  187. if (options.before) {
  188. this.before = options.before;
  189. }
  190. if (options.after) {
  191. this.after = options.after;
  192. }
  193. this.setType(options.type);
  194. this.setTime(options.time);
  195. this.cWidth = uni.upx2px(690);
  196. this.cHeight = uni.upx2px(500);
  197. // this.handelRenderValues();
  198. // this.getIndex();
  199. this.getInfo();
  200. // this.$scroll(this.$refs.container, () => {
  201. // !this.loading && this.getInfo();
  202. // });
  203. },
  204. computed: {
  205. monthRangeText() {
  206. return this.monthRange.length ? this.$t(`固定`) : this.$t(`指定范围`);
  207. }
  208. },
  209. methods: {
  210. getIndex: function() {
  211. let tempDay = []
  212. let tempNum = []
  213. var that = this;
  214. getStatisticsTime(that.where).then(
  215. res => {
  216. var _info = res.data.chart,
  217. day = [],
  218. num = [];
  219. _info.forEach(function(item) {
  220. day.push(item.time);
  221. num.push(item.num);
  222. });
  223. that.growth_rate = res.data.growth_rate;
  224. that.increase_time = res.data.increase_time;
  225. that.increase_time_status = res.data.increase_time_status;
  226. that.time_price = res.data.time;
  227. res.data.chart.forEach((item, index) => {
  228. tempDay.push(item.time)
  229. tempNum.push(item.num)
  230. })
  231. that.LineA.categories = tempDay
  232. that.LineA.series[0].data = tempNum
  233. that.showLineA("canvasLineA", that.LineA);
  234. },
  235. error => {
  236. that.$util.Tips({
  237. title: error
  238. })
  239. }
  240. );
  241. },
  242. setTime: function(time) {
  243. let self = this
  244. this.time = time;
  245. var year = new Date().getFullYear(),
  246. month = new Date().getMonth() + 1,
  247. day = new Date().getDate();
  248. this.list = [];
  249. this.filter.page = 1;
  250. this.loaded = false;
  251. this.loading = false;
  252. switch (time) {
  253. case "today":
  254. this.where.start =
  255. new Date(Date.parse(year + "/" + month + "/" + day)).getTime() /
  256. 1000;
  257. this.where.stop =
  258. new Date(Date.parse(year + "/" + month + "/" + day)).getTime() /
  259. 1000 +
  260. 24 * 60 * 60 -
  261. 1;
  262. this.title = this.$t(`今天`);
  263. this.getIndex();
  264. this.getInfo();
  265. break;
  266. case "yesterday":
  267. this.where.start =
  268. new Date(Date.parse(year + "/" + month + "/" + day)).getTime() /
  269. 1000 -
  270. 24 * 60 * 60;
  271. this.where.stop =
  272. new Date(Date.parse(year + "/" + month + "/" + day)).getTime() /
  273. 1000 -
  274. 1;
  275. this.title = this.$t(`昨天`);
  276. this.getIndex();
  277. this.getInfo();
  278. break;
  279. case "month":
  280. this.where.start =
  281. new Date(year, new Date().getMonth(), 1).getTime() / 1000;
  282. this.where.stop = new Date(year, month, 1).getTime() / 1000 - 1;
  283. this.title = this.$t(`本月`);
  284. this.getIndex();
  285. this.getInfo();
  286. break;
  287. case "seven":
  288. this.where.start =
  289. new Date(Date.parse(year + "/" + month + "/" + day)).getTime() /
  290. 1000 +
  291. 24 * 60 * 60 -
  292. 7 * 3600 * 24;
  293. this.where.stop =
  294. new Date(Date.parse(year + "/" + month + "/" + day)).getTime() /
  295. 1000 +
  296. 24 * 60 * 60 -
  297. 1;
  298. this.title = this.$t(`最近7天`);
  299. this.getIndex();
  300. this.getInfo();
  301. break;
  302. // #ifdef MP
  303. case "date":
  304. let sArr = self.before.split('-')
  305. let aArr = self.after.split('-')
  306. let star = this.getTimestamp(sArr[0], sArr[1], sArr[2], 0, 0, 0)
  307. let stop = this.getTimestamp(aArr[0], aArr[1], aArr[2], 23, 59, 59)
  308. self.where.start = star
  309. self.where.stop = stop
  310. Promise.all([self.getIndex(), self.getInfo()]);
  311. break;
  312. // #endif
  313. }
  314. },
  315. getTimestamp(year, month, day, hour, min, sec) {
  316. return new Date(year, month - 1, day, hour, min, sec).getTime() / 1000;
  317. },
  318. setType: function(type) {
  319. switch (type) {
  320. case "price":
  321. this.where.type = 1;
  322. break;
  323. case "order":
  324. this.where.type = 2;
  325. break;
  326. }
  327. },
  328. dateTitle: function() {
  329. // #ifdef H5 || APP-PLUS
  330. this.$refs.calendar.open()
  331. this.time = 'date'
  332. // #endif
  333. // #ifdef MP
  334. uni.navigateTo({
  335. url: '/pages/admin/custom_date/index?type=' + this.type
  336. });
  337. // #endif
  338. // this.current = true;
  339. },
  340. close: function() {
  341. this.current = false;
  342. },
  343. getInfo: function() {
  344. var that = this;
  345. if (that.loading || that.loaded) return;
  346. that.loading = true;
  347. that.filter.start = that.where.start;
  348. that.filter.stop = that.where.stop;
  349. getStatisticsMonth(that.filter).then(
  350. res => {
  351. that.loading = false;
  352. that.loaded = res.data.length < that.filter.limit;
  353. that.list.push.apply(that.list, res.data);
  354. that.filter.page = that.filter.page + 1;
  355. },
  356. error => {
  357. that.$util.Tips({
  358. title: error
  359. })
  360. }
  361. );
  362. },
  363. // 创建charts
  364. showLineA(canvasId, chartData) {
  365. let _self = this
  366. canvaLineA = new uCharts({
  367. $this: _self,
  368. canvasId: canvasId,
  369. type: 'line',
  370. fontSize: 11,
  371. padding: [15, 15, 0, 15],
  372. legend: {
  373. show: false,
  374. padding: 5,
  375. lineHeight: 11,
  376. margin: 5,
  377. },
  378. dataLabel: true,
  379. dataPointShape: true,
  380. dataPointShapeType: 'hollow',
  381. background: '#FFFFFF',
  382. pixelRatio: _self.pixelRatio,
  383. categories: chartData.categories,
  384. series: chartData.series,
  385. animation: true,
  386. enableScroll: true, //开启图表拖拽功能
  387. xAxis: {
  388. disableGrid: false,
  389. type: 'grid',
  390. gridType: 'dash',
  391. itemCount: 4,
  392. scrollShow: true,
  393. scrollAlign: 'left'
  394. },
  395. yAxis: {
  396. //disabled:true
  397. gridType: 'dash',
  398. splitNumber: 8,
  399. min: 0,
  400. max: 30,
  401. format: (val) => {
  402. return val.toFixed(0)
  403. } //如不写此方法,Y轴刻度默认保留两位小数
  404. },
  405. width: _self.cWidth * _self.pixelRatio,
  406. height: _self.cHeight * _self.pixelRatio,
  407. extra: {
  408. line: {
  409. type: 'straight'
  410. }
  411. },
  412. });
  413. },
  414. // charts触摸事件
  415. touchLineA(e) {
  416. canvaLineA.scrollStart(e);
  417. },
  418. moveLineA(e) {
  419. canvaLineA.scroll(e);
  420. },
  421. touchEndLineA(e) {
  422. canvaLineA.scrollEnd(e);
  423. },
  424. // 日历确定
  425. confirm(e) {
  426. let self = this
  427. if (e.range.after && e.range.before) {
  428. let star = new Date(e.range.before + ' 00:00:00').getTime() / 1000
  429. let stop = new Date(e.range.after + ' 23:59:59').getTime() / 1000
  430. self.where.start = star
  431. self.where.stop = stop
  432. self.list = [];
  433. self.filter.page = 1;
  434. self.loaded = false;
  435. self.loading = false;
  436. Promise.all([self.getIndex(), self.getInfo()]);
  437. }
  438. },
  439. },
  440. onReachBottom() {
  441. this.getInfo();
  442. }
  443. };
  444. </script>
  445. <style>
  446. /*交易额统计*/
  447. .statistical-page .navs {
  448. width: 100%;
  449. height: 96upx;
  450. background-color: #fff;
  451. overflow: hidden;
  452. line-height: 96upx;
  453. position: fixed;
  454. top: 0;
  455. left: 0;
  456. z-index: 9;
  457. }
  458. .statistical-page .navs .list {
  459. overflow-y: hidden;
  460. overflow-x: auto;
  461. white-space: nowrap;
  462. -webkit-overflow-scrolling: touch;
  463. width: 100%;
  464. }
  465. .statistical-page .navs .item {
  466. font-size: 32upx;
  467. color: #282828;
  468. margin-left: 60upx;
  469. display: inline-block;
  470. }
  471. .statistical-page .navs .item.on {
  472. color: #2291f8;
  473. }
  474. .statistical-page .navs .item .iconfont {
  475. font-size: 25upx;
  476. margin-left: 13upx;
  477. }
  478. .statistical-page .wrapper {
  479. width: 740upx;
  480. background-color: #fff;
  481. border-radius: 10upx;
  482. margin: 119upx auto 0 auto;
  483. padding: 50upx 60upx;
  484. }
  485. .statistical-page .wrapper .title {
  486. font-size: 30upx;
  487. color: #999;
  488. text-align: center;
  489. }
  490. .statistical-page .wrapper .money {
  491. font-size: 72upx;
  492. color: #fba02a;
  493. text-align: center;
  494. margin-top: 10upx;
  495. }
  496. .statistical-page .wrapper .increase {
  497. font-size: 28upx;
  498. color: #999;
  499. margin-top: 20upx;
  500. }
  501. .statistical-page .wrapper .increase .red {
  502. color: #ff6969;
  503. }
  504. .statistical-page .wrapper .increase .green {
  505. color: #1abb1d;
  506. }
  507. .statistical-page .wrapper .increase .iconfont {
  508. font-size: 23upx;
  509. margin-left: 15upx;
  510. }
  511. .statistical-page .chart {
  512. width: 690upx;
  513. background-color: #fff;
  514. border-radius: 10upx;
  515. margin: 23upx auto 0 auto;
  516. /* padding: 25upx 22upx 0 22upx; */
  517. }
  518. .statistical-page .chart .chart-title {
  519. padding: 20upx 20upx 10upx;
  520. font-size: 26upx;
  521. color: #999;
  522. }
  523. .statistical-page .chart canvas {
  524. width: 100%;
  525. height: 530rpx;
  526. }
  527. .statistical-page .chart .company {
  528. font-size: 26upx;
  529. color: #999;
  530. }
  531. .yd-confirm {
  532. background-color: #fff;
  533. font-size: unset;
  534. width: 540upx;
  535. height: 250upx;
  536. border-radius: 40upx;
  537. }
  538. .yd-confirm-hd {
  539. text-align: center;
  540. }
  541. .yd-confirm-title {
  542. color: #030303;
  543. font-weight: bold;
  544. font-size: 36upx;
  545. }
  546. .yd-confirm-bd {
  547. text-align: center;
  548. font-size: 28upx;
  549. color: #333333;
  550. }
  551. .yd-confirm-ft {
  552. line-height: 90upx;
  553. margin-top: 14px;
  554. border-top: 1upx solid #eee;
  555. }
  556. .yd-confirm-ft>a {
  557. color: #e93323;
  558. }
  559. .yd-confirm-ft>a.primary {
  560. border-left: 1upx solid #eee;
  561. color: #e93323;
  562. }
  563. .echarts {
  564. width: 100%;
  565. height: 550upx;
  566. }
  567. .calendar-wrapper {
  568. position: fixed;
  569. bottom: 0;
  570. left: 0;
  571. width: 100%;
  572. z-index: 777;
  573. transform: translate3d(0, 100%, 0);
  574. transition: all 0.3s cubic-bezier(0.25, 0.5, 0.5, 0.9);
  575. }
  576. .calendar-wrapper.on {
  577. transform: translate3d(0, 0, 0);
  578. }
  579. .statistical-page .wrapper .increase {
  580. font-size: 26upx;
  581. }
  582. .statistical-page .wrapper .increase .iconfont {
  583. margin-left: 0;
  584. }
  585. .public-wrapper .title {
  586. font-size: 30upx;
  587. color: #282828;
  588. padding: 0 30upx;
  589. margin-bottom: 20upx;
  590. }
  591. .public-wrapper .title .iconfont {
  592. color: #2291f8;
  593. font-size: 40upx;
  594. margin-right: 13upx;
  595. vertical-align: middle;
  596. }
  597. .public-wrapper {
  598. margin: 18upx auto 0 auto;
  599. width: 690upx;
  600. background-color: #fff;
  601. border-radius: 10upx;
  602. padding-top: 25upx;
  603. }
  604. .public-wrapper .nav {
  605. padding: 0 30upx;
  606. height: 70upx;
  607. line-height: 70upx;
  608. font-size: 24upx;
  609. color: #999;
  610. }
  611. .public-wrapper .data {
  612. width: 210upx;
  613. text-align: left;
  614. }
  615. .public-wrapper .browse {
  616. width: 192upx;
  617. text-align: right;
  618. }
  619. .public-wrapper .turnover {
  620. width: 227upx;
  621. text-align: right;
  622. }
  623. .public-wrapper .conter {
  624. padding: 0 30upx;
  625. }
  626. .public-wrapper .conter .item {
  627. border-bottom: 1px solid #f7f7f7;
  628. height: 70upx;
  629. font-size: 24upx;
  630. }
  631. .public-wrapper .conter .item .turnover {
  632. color: #d84242;
  633. }
  634. </style>