index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511
  1. <template>
  2. <view class="pagebox">
  3. <!-- #ifdef MP || APP-PLUS -->
  4. <NavBar titleText="数据统计" :iconColor="iconColor" :textColor="iconColor" :isScrolling="isScrolling" showBack></NavBar>
  5. <!-- #endif -->
  6. <view class="headerBg">
  7. <view :style="{ height: `${getHeight.barTop}px` }"></view>
  8. <view :style="{ height: `${getHeight.barHeight}px` }"></view>
  9. <view class="inner"></view>
  10. </view>
  11. <view class="order-index" ref="container">
  12. <view class="header">
  13. <view class="">销售额(元)</view>
  14. <view class="money">{{ after_price }}</view>
  15. <view class="info">
  16. 较昨日同比增长:{{ increase_time_status == 1 ? '' : '-' }}{{ growth_rate }}%
  17. <text :class="['iconfont', increase_time_status == 1 ? 'icon-ic_up2' : 'icon-ic_down2']"></text>
  18. </view>
  19. <view class="picker">
  20. <picker mode="selector" :range="array" @change="bindPickerChange">
  21. <view>{{ array[index] }}<text class="iconfont icon-ic_downarrow"></text></view>
  22. </picker>
  23. </view>
  24. </view>
  25. <view class="wrapper">
  26. <view class="list acea-row">
  27. <view class="item">
  28. <view class="num">{{ after_number }}</view>
  29. <view>订单数</view>
  30. </view>
  31. <view class="item">
  32. <view class="num">{{ after_pay_number }}</view>
  33. <view>支付人数</view>
  34. </view>
  35. <view class="item">
  36. <view class="num">{{ today_visits }}</view>
  37. <view>浏览量</view>
  38. </view>
  39. </view>
  40. </view>
  41. <div class="chart">
  42. <view class="title">
  43. 销售订单趋势图
  44. </view>
  45. <canvas canvas-id="canvasMix" id="canvasMix" class="charts" disable-scroll @touchstart="touchMix" @touchmove="moveMix" @touchend="touchEndMix">
  46. <!-- <cover-view class="cover-view"></cover-view> -->
  47. </canvas>
  48. </div>
  49. <view class="public-wrapper">
  50. <view class="title">
  51. 详细数据
  52. </view>
  53. <view class="nav acea-row row-between-wrapper">
  54. <view class="data">日期</view>
  55. <view class="browse">订单数</view>
  56. <view class="turnover">成交额</view>
  57. <view class="visit">浏览量</view>
  58. </view>
  59. <view class="conter">
  60. <view class="item acea-row row-between-wrapper" v-for="(item, index) in list" :key="index">
  61. <view class="data">{{ item.time }}</view>
  62. <view class="browse">{{ item.count }}</view>
  63. <view class="turnover">¥ {{ item.price }}</view>
  64. <view class="visit">{{ item.visit }}</view>
  65. </view>
  66. </view>
  67. </view>
  68. <Loading :loaded="loaded" :loading="loading"></Loading>
  69. </view>
  70. <view class="safe-area-inset-bottom"></view>
  71. </view>
  72. </template>
  73. <script>
  74. let _self;
  75. let canvaMix = null;
  76. import {
  77. getStatisticsInfo,
  78. getStatisticsMonth,
  79. getOrderTime,
  80. getOrderChart,
  81. } from "@/api/admin";
  82. import Loading from '@/components/Loading/index.vue'
  83. import uCharts from '../components/ucharts/ucharts'
  84. // #ifdef MP || APP-PLUS
  85. import NavBar from '@/components/NavBar.vue';
  86. // #endif
  87. export default {
  88. name: 'adminOrder',
  89. components: {
  90. Loading,
  91. // #ifdef MP ||APP-PLUS
  92. NavBar,
  93. // #endif
  94. },
  95. data() {
  96. return {
  97. iconColor: '#FFFFFF',
  98. isScrolling: false,
  99. getHeight: this.$util.getWXStatusHeight(),
  100. census: {},
  101. list: [],
  102. where: {
  103. page: 1,
  104. limit: 15
  105. },
  106. loaded: false,
  107. loading: false,
  108. after_price: 0, // 销售额
  109. after_number: 0, // 订单数
  110. after_pay_number: 0, // 支付人数
  111. today_visits: 0, // 浏览量
  112. growth_rate: 0, // 增长率
  113. increase_time: 0, // 较昨日同比增长
  114. increase_time_status: 1, // 1 增长 2 减少
  115. cWidth: '',
  116. cHeight: '',
  117. pixelRatio: 1,
  118. textarea: '',
  119. index: 0,
  120. array: ['今天', '近7天', '近30天'],
  121. arrays: [1, 7, 30],
  122. }
  123. },
  124. onShow() {
  125. _self = this;
  126. this.cWidth = uni.upx2px(710);
  127. this.cHeight = uni.upx2px(500);
  128. this.getOrderTime();
  129. this.getOrderChart();
  130. this.getIndex();
  131. this.getList();
  132. // this.$scroll(this.$refs.container, () => {
  133. // !this.loading && this.getList();
  134. // });
  135. },
  136. onPageScroll(e) {
  137. // #ifdef MP
  138. if (e.scrollTop > 50) {
  139. this.isScrolling = true;
  140. this.iconColor = '#333333';
  141. } else if (e.scrollTop < 50) {
  142. this.isScrolling = false;
  143. this.iconColor = '#FFFFFF';
  144. }
  145. // #endif
  146. },
  147. beforeMount() {
  148. canvaMix = null
  149. },
  150. methods: {
  151. bindPickerChange: function(e) {
  152. console.log('picker发送选择改变,携带值为', e.detail.value)
  153. this.index = e.detail.value
  154. this.getOrderTime();
  155. this.getOrderChart();
  156. },
  157. getOrderTime() {
  158. getOrderTime({
  159. type: this.arrays[this.index],
  160. }).then(res => {
  161. const {
  162. after_number,
  163. after_pay_number,
  164. after_price,
  165. today_visits,
  166. growth_rate,
  167. increase_time,
  168. increase_time_status,
  169. } = res.data;
  170. this.after_number = after_number;
  171. this.after_pay_number = after_pay_number;
  172. this.after_price = after_price;
  173. this.today_visits = today_visits;
  174. this.growth_rate = growth_rate;
  175. this.increase_time = increase_time;
  176. this.increase_time_status = increase_time_status;
  177. });
  178. },
  179. getOrderChart() {
  180. getOrderChart({
  181. type: this.arrays[this.index],
  182. }).then(res => {
  183. const data = res.data;
  184. let Mix = {
  185. categories: [],
  186. series: []
  187. };
  188. let series = [{
  189. "name": '销售额',
  190. "type": "line",
  191. "data": [],
  192. }];
  193. data.forEach(({
  194. num,
  195. price,
  196. time
  197. }) => {
  198. series[0].data.push(price);
  199. Mix.categories.push(time);
  200. });
  201. Mix.series = series;
  202. this.chartData = data;
  203. if (canvaMix) {
  204. canvaMix.updateData(Mix);
  205. } else {
  206. this.showLineA("canvasMix", Mix);
  207. }
  208. });
  209. },
  210. // 创建charts
  211. showLineA(canvasId, chartData) {
  212. let _self = this
  213. canvaMix = new uCharts({
  214. $this: _self,
  215. canvasId: canvasId,
  216. type: 'line',
  217. fontSize: 11,
  218. padding: [5, 5, 0, 5],
  219. legend: {
  220. show: true,
  221. position: 'bottom',
  222. float: 'center',
  223. padding: 5,
  224. lineHeight: 11,
  225. margin: 6,
  226. },
  227. background: '#FFFFFF',
  228. pixelRatio: _self.pixelRatio,
  229. categories: chartData.categories,
  230. series: chartData.series,
  231. animation: true,
  232. enableScroll: true, //开启图表拖拽功能
  233. xAxis: {
  234. disableGrid: false,
  235. type: 'grid',
  236. gridType: 'dash',
  237. itemCount: 6,
  238. scrollShow: true,
  239. scrollAlign: 'left',
  240. },
  241. yAxis: {
  242. data: [{
  243. calibration: true,
  244. position: 'left',
  245. title: '销售额(元)',
  246. titleFontSize: 12,
  247. format: (val) => {
  248. return val.toFixed(0)
  249. }
  250. }, ],
  251. showTitle: true,
  252. gridType: 'dash',
  253. dashLength: 4,
  254. splitNumber: 7,
  255. },
  256. width: _self.cWidth * _self.pixelRatio,
  257. height: _self.cHeight * _self.pixelRatio,
  258. dataLabel: true,
  259. dataPointShape: true,
  260. });
  261. },
  262. touchMix(e) {
  263. canvaMix.scrollStart(e);
  264. },
  265. moveMix(e) {
  266. canvaMix.scroll(e);
  267. },
  268. touchEndMix(e) {
  269. var index = canvaMix.getCurrentDataIndex(e);
  270. canvaMix.scrollEnd(e);
  271. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  272. canvaMix.touchLegend(e);
  273. canvaMix.showToolTip(e, {
  274. textList: [{
  275. text: this.chartData[index].time,
  276. color: null
  277. },
  278. {
  279. text: "销售额:" + this.chartData[index].price,
  280. color: "#1890FF"
  281. },
  282. {
  283. text: "订单量:" + this.chartData[index].num,
  284. color: "#91CB74"
  285. }
  286. ]
  287. });
  288. },
  289. getIndex: function() {
  290. var that = this;
  291. getStatisticsInfo().then(
  292. res => {
  293. that.census = res.data;
  294. },
  295. err => {
  296. that.$util.Tips({
  297. title: err
  298. })
  299. }
  300. );
  301. },
  302. getList: function() {
  303. var that = this;
  304. if (that.loading || that.loaded) return;
  305. that.loading = true;
  306. getStatisticsMonth(that.where).then(
  307. res => {
  308. that.loading = false;
  309. that.loaded = res.data.length < that.where.limit;
  310. that.list.push.apply(that.list, res.data);
  311. that.where.page = that.where.page + 1;
  312. },
  313. error => {
  314. that.$util.Tips({
  315. title: error
  316. })
  317. },
  318. 300
  319. );
  320. }
  321. },
  322. onReachBottom() {
  323. this.getList()
  324. }
  325. }
  326. </script>
  327. <style lang="scss" scoped>
  328. .pagebox {
  329. position: relative;
  330. overflow: hidden;
  331. }
  332. .safe-area-inset-bottom {
  333. height: 0;
  334. height: constant(safe-area-inset-bottom);
  335. height: env(safe-area-inset-bottom);
  336. }
  337. .headerBg {
  338. position: absolute;
  339. top: 0;
  340. left: -25%;
  341. width: 150%;
  342. border-bottom-right-radius: 100%;
  343. border-bottom-left-radius: 100%;
  344. background: linear-gradient(270deg, #01ABF8 0%, #2A7EFB 100%);
  345. .inner {
  346. height: 356rpx;
  347. }
  348. }
  349. /*订单首页*/
  350. .order-index {
  351. position: relative;
  352. padding: 0 20rpx;
  353. }
  354. .order-index .header {
  355. position: relative;
  356. padding: 24rpx 0 40rpx 20rpx;
  357. font-size: 28rpx;
  358. line-height: 40rpx;
  359. color: #FFFFFF;
  360. .picker {
  361. position: absolute;
  362. top: 24rpx;
  363. right: 0;
  364. height: 48rpx;
  365. padding: 0 20rpx;
  366. border-radius: 24rpx;
  367. background: rgba(255, 255, 255, 0.3);
  368. text-align: center;
  369. font-size: 24rpx;
  370. line-height: 48rpx;
  371. color: #FFFFFF;
  372. .iconfont {
  373. margin-left: 10rpx;
  374. font-size: 24rpx;
  375. }
  376. }
  377. }
  378. .order-index .header .money {
  379. margin-top: 26rpx;
  380. font-family: SemiBold;
  381. font-size: 80rpx;
  382. line-height: 80rpx;
  383. }
  384. .order-index .header .info {
  385. margin-top: 30rpx;
  386. .iconfont {
  387. margin-left: 6rpx;
  388. font-size: 28rpx;
  389. }
  390. }
  391. .order-index .wrapper {
  392. background-color: #fff;
  393. border-radius: 24rpx;
  394. }
  395. .order-index .wrapper .list .item {
  396. flex: 1;
  397. padding: 36rpx 0 26rpx;
  398. text-align: center;
  399. font-size: 24rpx;
  400. line-height: 34rpx;
  401. color: #999;
  402. }
  403. .order-index .wrapper .list .item .num {
  404. margin-bottom: 8rpx;
  405. font-family: SemiBold;
  406. font-size: 36rpx;
  407. color: #333;
  408. }
  409. .public-wrapper .title {
  410. font-weight: 500;
  411. font-size: 30rpx;
  412. line-height: 42rpx;
  413. color: #333333;
  414. padding: 32rpx 0 40rpx 24rpx;
  415. }
  416. .public-wrapper {
  417. background-color: #fff;
  418. border-radius: 24rpx;
  419. margin-top: 20rpx;
  420. margin-bottom: 20rpx;
  421. }
  422. .public-wrapper .nav {
  423. padding: 0 40rpx;
  424. line-height: 34rpx;
  425. font-size: 24rpx;
  426. color: #999;
  427. }
  428. .public-wrapper .data {
  429. flex: 1;
  430. text-align: left;
  431. }
  432. .public-wrapper .browse {
  433. flex: 1;
  434. // text-align: center;
  435. }
  436. .public-wrapper .turnover {
  437. flex: 1;
  438. // text-align: center;
  439. }
  440. .public-wrapper .visit {
  441. flex: 1;
  442. text-align: right;
  443. }
  444. .public-wrapper .conter {
  445. padding: 0 40rpx;
  446. }
  447. .public-wrapper .conter .item {
  448. border-bottom: 1px solid #F1F1F1;
  449. height: 74rpx;
  450. font-size: 24rpx;
  451. }
  452. .chart {
  453. border-radius: 24rpx;
  454. margin-top: 20rpx;
  455. background: #FFFFFF;
  456. .title {
  457. padding: 32rpx 0 16rpx 24rpx;
  458. font-weight: 500;
  459. font-size: 30rpx;
  460. line-height: 42rpx;
  461. color: #333333;
  462. }
  463. .chart-title {
  464. padding: 40rpx 0 6rpx 42rpx;
  465. font-size: 22rpx;
  466. line-height: 26rpx;
  467. color: #999999;
  468. }
  469. .charts {
  470. width: 100%;
  471. height: 514rpx;
  472. }
  473. }
  474. .cover-view {
  475. position: fixed;
  476. top: 0;
  477. right: 0;
  478. bottom: 0;
  479. left: 0;
  480. }
  481. </style>