index.vue 15 KB

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