index.vue 15 KB

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