index.vue 16 KB

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