index.vue 17 KB

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