statistics.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  1. <template>
  2. <view class="container">
  3. <u-navbar leftIconColor="#fff" titleStyle="color:#fff;fontSize:36rpx;" :autoBack="true" bgColor="#2C6FF3"
  4. :placeholder="true" :title="navTitle"></u-navbar>
  5. <view class="content">
  6. <view class="card">
  7. <view class="select">
  8. <view class="time-tab flex justify-between">
  9. <block v-for="(item,index) in timeList" :key="item.id">
  10. <view class="time-tab-item" :class="[timeTabCurrent==item.id?'time-tab-show':'']"
  11. @click="timeTabClick(item.id)">
  12. {{item.name}}
  13. </view>
  14. </block>
  15. </view>
  16. <view class="time-select flex justify-around">
  17. <view class="flex align-center">
  18. <view @click="timePickerShow('start')">
  19. {{timeStart?timeStart:'开始时间'}}
  20. </view>
  21. <view>
  22. </view>
  23. <view @click="timePickerShow('end')">
  24. {{timeEnd?timeEnd:'结束时间'}}
  25. </view>
  26. </view>
  27. </view>
  28. </view>
  29. <view class="total flex justify-around">
  30. <view class="flex flex-direction align-center">
  31. <view class="total-name">
  32. 总销售额(元)
  33. </view>
  34. <view class="total-num" style="color: #2C6FF3;">
  35. {{$xy.delMoney(total.salesMoney)}}
  36. </view>
  37. </view>
  38. <view class="flex flex-direction align-center">
  39. <view class="total-name">
  40. 商品销售数量(个)
  41. </view>
  42. <view class="total-num" style="color: #F9B237;">
  43. {{total.salesCount||0}}
  44. </view>
  45. </view>
  46. <view class="flex flex-direction align-center">
  47. <view class="total-name">
  48. 平均商品价(元)
  49. </view>
  50. <view class="total-num" v-if="total.salesCount>0" style="color: #E94F4F;">
  51. {{($xy.delMoney(total.salesMoney)/total.salesCount).toFixed(2)||0}}
  52. </view>
  53. <view class="total-num" v-else style="color:#E94F4F;">
  54. 0
  55. </view>
  56. </view>
  57. </view>
  58. <view class="chart" style="height: 600rpx;">
  59. <qiun-data-charts type="qy-line-gradual" :opts="opts" :chartData="chartData"
  60. :errorMessage="errorMessage" />
  61. </view>
  62. </view>
  63. <view class="goods-table card">
  64. <view class="table">
  65. <view class="table-title flex justify-between align-center">
  66. <view class="title">
  67. 商品销售排行
  68. </view>
  69. <view class="sort-type flex">
  70. <view :class="[goodsSortType==0?'sort-type-item sort-type-show':'sort-type-item']"
  71. @click="goodsSort(0)">
  72. 销售额
  73. </view>
  74. <view :class="[goodsSortType==1?'sort-type-item sort-type-show':'sort-type-item']"
  75. @click="goodsSort(1)">
  76. 销量
  77. </view>
  78. </view>
  79. </view>
  80. <uni-table :border="false" :stripe="false" emptyText="暂无更多数据">
  81. <!-- 表头行 -->
  82. <uni-tr>
  83. <uni-th align="center" width="52">排名</uni-th>
  84. <uni-th align="center" width="110">上榜商品</uni-th>
  85. <uni-th align="center" width="92">销售额</uni-th>
  86. <uni-th align="center" width="92">销量</uni-th>
  87. </uni-tr>
  88. <!-- 表格数据行 -->
  89. <uni-tr v-for="(item,index) in list2" :key="item.goodsId">
  90. <uni-td v-if="index==0">
  91. <view class="table-td">
  92. <image class="table-img" src="../../static/images/global/first-class.png"
  93. mode="widthFix"></image>
  94. </view>
  95. </uni-td>
  96. <uni-td v-else-if="index==1">
  97. <view class="table-td">
  98. <image class="table-img" src="../../static/images/global/second-class.png"
  99. mode="widthFix"></image>
  100. </view>
  101. </uni-td>
  102. <uni-td v-else-if="index==2">
  103. <view class="table-td">
  104. <image class="table-img" src="../../static/images/global/third-class.png"
  105. mode="widthFix"></image>
  106. </view>
  107. </uni-td>
  108. <uni-td v-else>
  109. <view class="table-td">
  110. {{index+1}}
  111. </view>
  112. </uni-td>
  113. <uni-td>
  114. <view class="table-td table-td-name">{{item.goodsName}}</view>
  115. </uni-td>
  116. <uni-td>
  117. <view class="table-td">¥{{$xy.delMoney(item.salesMoney)}}</view>
  118. </uni-td>
  119. <uni-td>
  120. <view class="table-td">{{item.salesCount}}件</view>
  121. </uni-td>
  122. </uni-tr>
  123. </uni-table>
  124. </view>
  125. <view class="more" @click="more('goods')" v-if="list2.length==5">
  126. 查看更多<view><u-icon name="arrow-right" color="#2C6FF3"></u-icon></view>
  127. </view>
  128. </view>
  129. </view>
  130. <u-datetime-picker :show="timeShow" :mode="timeMode" v-model="time" @confirm="confirm"
  131. :closeOnClickOverlay="true" @close="close" @cancel="close"></u-datetime-picker>
  132. <u-picker :show="pickerShow" :columns="columns" @confirm="pickerComfirm" :closeOnClickOverlay="true"
  133. @close="pickerClose" @cancel="pickerClose"></u-picker>
  134. </view>
  135. </template>
  136. <script>
  137. import {
  138. salesData,
  139. goodSumCount,
  140. goodSumPage
  141. } from "@/api/device/device.js"
  142. export default {
  143. data() {
  144. return {
  145. timeType: ['日', '月', '年'],
  146. timeCurrent: 0,
  147. timeStart: '',
  148. timeEnd: '',
  149. deviceSortType: 0,
  150. goodsSortType: 0,
  151. timeShow: false,
  152. timeMode: 'date',
  153. startOrEnd: '',
  154. time: new Date(),
  155. pickerType: 'year',
  156. pickerShow: false,
  157. // typeColumns: [
  158. // ['销售额从高到低', '销售额从低到高', '销售数量从高到低', '销售数量从低到高']
  159. // ],
  160. typeColumns: [
  161. ['销售额', '订单笔数']
  162. ],
  163. page: 1, //商品分页
  164. size: 10,
  165. status: 'loadmore', //加载更多
  166. list1: [], //设备列表
  167. list2: [], //商品列表
  168. fullHeight: 0,
  169. total: {
  170. goodsCount: 0,
  171. salesMoney: 0
  172. },
  173. tabCurrent: 0,
  174. timeList: [{
  175. id: 0,
  176. name: '昨天'
  177. },
  178. {
  179. id: 1,
  180. name: '今天'
  181. },
  182. {
  183. id: 2,
  184. name: '近7日'
  185. },
  186. {
  187. id: 3,
  188. name: '近30日'
  189. },
  190. {
  191. id: 4,
  192. name: '本月'
  193. },
  194. ],
  195. timeTabCurrent: 1,
  196. title: '设备销售额排行',
  197. opts: {
  198. enableScroll: false,
  199. legend: {
  200. position: 'top',
  201. float: 'right',
  202. padding: 20,
  203. itemGap: 20
  204. },
  205. xAxis: {
  206. disableGrid: true,
  207. labelCount: 6,
  208. },
  209. yAxis: {
  210. gridType: "solid",
  211. dashLength: 2,
  212. showTitle: true,
  213. axisLineColor: '#fff',
  214. data: [{
  215. position: "left",
  216. title: "/元"
  217. },
  218. {
  219. position: "right",
  220. title: "/单",
  221. textAlign: "left"
  222. },
  223. ]
  224. },
  225. extra: {
  226. area: {
  227. type: "curve",
  228. opacity: 0.2,
  229. addLine: true,
  230. width: 2,
  231. gradient: true,
  232. activeType: "hollow"
  233. }
  234. }
  235. },
  236. errorMessage: '无数据',
  237. chartData: {
  238. categories: [],
  239. series: []
  240. },
  241. navTitle: ''
  242. }
  243. },
  244. onLoad(o) {
  245. this.navTitle = o.title;
  246. this.id = o.id
  247. },
  248. onShow() {
  249. let timeObj = this.setResetTime(this.timeTabCurrent)
  250. this.timeStart = timeObj.start
  251. this.timeEnd = timeObj.end
  252. this.getData()
  253. },
  254. methods: {
  255. getData() {
  256. this.getList2(this.goodsSortType)
  257. this.getDeviceTotal(this.deviceSortType)
  258. this.getCountData()
  259. },
  260. timeTabClick(e) {
  261. this.timeTabCurrent = e
  262. let timeObj = this.setResetTime(this.timeTabCurrent)
  263. this.timeStart = timeObj.start
  264. this.timeEnd = timeObj.end
  265. this.getData()
  266. },
  267. setResetTime(type) {
  268. let date = new Date()
  269. let time = {
  270. start: uni.$u.timeFormat(date, 'yyyy-mm-dd'),
  271. end: uni.$u.timeFormat(date, 'yyyy-mm-dd')
  272. }
  273. switch (type) {
  274. case 0: //昨天
  275. time = {
  276. start: uni.$u.timeFormat(date - 24 * 60 * 60 * 1000, 'yyyy-mm-dd'),
  277. end: uni.$u.timeFormat(date - 24 * 60 * 60 * 1000, 'yyyy-mm-dd')
  278. }
  279. break;
  280. case 1: //今天
  281. time = {
  282. start: uni.$u.timeFormat(date, 'yyyy-mm-dd'),
  283. end: uni.$u.timeFormat(date, 'yyyy-mm-dd')
  284. }
  285. break;
  286. case 2: //近7日
  287. time = {
  288. start: uni.$u.timeFormat(date - 7 * 24 * 60 * 60 * 1000, 'yyyy-mm-dd'),
  289. end: uni.$u.timeFormat(date, 'yyyy-mm-dd')
  290. }
  291. break;
  292. case 3: //近30日
  293. time = {
  294. start: uni.$u.timeFrom(date - 30 * 24 * 60 * 60 * 1000, 'yyyy-mm-dd'),
  295. end: uni.$u.timeFrom(date, 'yyyy-mm-dd')
  296. }
  297. break;
  298. case 4: //本月
  299. let start = uni.$u.timeFrom(date, 'yyyy-mm-dd')
  300. time = {
  301. start: start.substr(0, 8) + '01',
  302. end: uni.$u.timeFrom(date, 'yyyy-mm-dd')
  303. }
  304. break;
  305. default:
  306. break;
  307. }
  308. return time
  309. },
  310. timePickerShow(type) {
  311. this.pickerType = 'year';
  312. this.startOrEnd = type
  313. if (this.timeCurrent == 2) {
  314. this.columns = yearList
  315. this.pickerShow = true
  316. } else {
  317. this.timeShow = true;
  318. }
  319. },
  320. goodsSort(type) {
  321. this.goodsSortType = type
  322. this.getList2(type)
  323. },
  324. close() {
  325. this.timeShow = false
  326. },
  327. confirm(e) {
  328. let time = '';
  329. time = uni.$u.timeFormat(e.value, 'yyyy-mm-dd')
  330. if (this.startOrEnd == 'start') {
  331. this.timeStart = time
  332. }
  333. if (this.startOrEnd == 'end') {
  334. this.timeEnd = time
  335. }
  336. this.getData()
  337. this.timeShow = false;
  338. },
  339. pickerClose() {
  340. this.pickerShow = false
  341. },
  342. //获取统计数据
  343. getCountData(type) {
  344. salesData({
  345. type: "day",
  346. beginDate: this.timeStart,
  347. endDate: this.timeEnd,
  348. deviceId: this.id
  349. }).then(res => {
  350. let data = res.data;
  351. let tempChartData = {};
  352. this.delData(data);
  353. tempChartData.series = data.series ? data.series : [];
  354. tempChartData.categories = data.categories ? data.categories : [];
  355. this.chartData = JSON.parse(JSON.stringify(tempChartData));
  356. }).catch(err => {
  357. })
  358. },
  359. // 处理统计图表数据
  360. delData(data) {
  361. let arr = data.categories.map(item => {
  362. if (item.length < 3) {
  363. item = item + '点'
  364. } else {
  365. item = item.substr(4, 2) + '月' + item.substr(6, 2) + '日'
  366. }
  367. return item
  368. })
  369. data.categories = arr
  370. },
  371. getParams(type) {
  372. let orderByKey = "";
  373. let orderBy = "";
  374. switch (type) {
  375. case '销售额':
  376. orderBy = 'desc';
  377. orderByKey = 'sales_money';
  378. break;
  379. case '订单笔数':
  380. orderBy = 'desc';
  381. orderByKey = 'sales_count';
  382. break;
  383. case '销量':
  384. orderBy = 'desc';
  385. orderByKey = 'sales_count';
  386. break;
  387. default:
  388. break;
  389. }
  390. let params = {
  391. type: 'day',
  392. orderByKey: orderByKey,
  393. orderBy: orderBy,
  394. beginDate: this.timeStart,
  395. endDate: this.timeEnd,
  396. deviceId: this.id
  397. }
  398. return params
  399. },
  400. //设备统计总数居
  401. getDeviceTotal(type) {
  402. let params = this.getParams(type)
  403. goodSumCount(params).then(res => {
  404. this.total = res.data
  405. })
  406. },
  407. //获取商品排行
  408. getList2(e) {
  409. let type = e == 0 ? '销售额' : '销量';
  410. let dataParams = this.getParams(type)
  411. let pageParams = {
  412. page: {
  413. current: 1,
  414. size: 5
  415. }
  416. }
  417. let params = Object.assign(dataParams, pageParams)
  418. goodSumPage(params).then(res => {
  419. if (res.data) {
  420. this.list2 = res.data.records;
  421. } else {
  422. this.list2 = []
  423. }
  424. })
  425. },
  426. more(type) {
  427. let sortType = this.goodsSortType
  428. this.$tab.navigateTo(
  429. `/pages/equipment/statisticsMore?timeStart=${this.timeStart}&&timeEnd=${this.timeEnd}&&sortType=${sortType}&&id=${this.id}`
  430. )
  431. }
  432. }
  433. }
  434. </script>
  435. <style lang="scss" scoped>
  436. .container {
  437. .content {
  438. padding-bottom: 24rpx;
  439. .card {
  440. width: 724rpx;
  441. margin-left: 13rpx;
  442. background-color: #fff;
  443. margin-top: 20rpx;
  444. box-shadow: 0px 0px 10rpx 0px rgba(174, 201, 255, 0.2);
  445. border-radius: 14rpx;
  446. }
  447. .tab {
  448. padding: 24rpx;
  449. // background-color: #fff;
  450. }
  451. .select {
  452. padding-top: 34rpx;
  453. .time-tab {
  454. padding: 0 36rpx;
  455. .time-tab-item {
  456. width: 20%;
  457. border: 1rpx solid #CCCCCC;
  458. border-left: none;
  459. text-align: center;
  460. font-size: 26rpx;
  461. line-height: 58rpx;
  462. color: #777777;
  463. &:first-of-type {
  464. border-left: 1rpx solid #CCCCCC;
  465. border-radius: 6rpx 0px 0px 6rpx;
  466. }
  467. &:last-of-type {
  468. border-radius: 0px 6rpx 6rpx 0px;
  469. }
  470. &.time-tab-show {
  471. background: #F4F8FF;
  472. color: #2C6FF3;
  473. }
  474. }
  475. }
  476. .time-select {
  477. padding: 34rpx 36rpx;
  478. color: rgb(144, 144, 144);
  479. font-size: 28rpx;
  480. >view {
  481. >view:nth-child(1) {
  482. width: 160rpx;
  483. text-align: right;
  484. }
  485. >view:nth-child(2) {
  486. width: 80rpx;
  487. padding: 0 24rpx;
  488. }
  489. }
  490. }
  491. }
  492. .total {
  493. padding: 12rpx 0;
  494. background-color: #fff;
  495. .total-name {
  496. color: #333;
  497. font-size: 28rpx;
  498. line-height: 28rpx;
  499. margin-top: 48rpx;
  500. }
  501. .total-num {
  502. color: #eab09a;
  503. font-size: 42rpx;
  504. font-weight: bold;
  505. line-height: 41rpx;
  506. margin-top: 24rpx;
  507. }
  508. }
  509. .search {
  510. padding: 24rpx 24rpx;
  511. background-color: #fff;
  512. position: relative;
  513. font-size: 26rpx;
  514. .time-type {
  515. width: 180rpx;
  516. }
  517. .time-select {
  518. width: 340rpx;
  519. line-height: 64rpx;
  520. background-color: #eeeeef;
  521. border-radius: 6rpx;
  522. }
  523. }
  524. .chart {
  525. background-color: #fff;
  526. }
  527. .table {
  528. width: 724rpx;
  529. background-color: #fff;
  530. margin-top: 18rpx;
  531. color: #333;
  532. .table-title {
  533. font-size: 32rpx;
  534. line-height: 50rpx;
  535. padding: 24rpx;
  536. font-weight: 800;
  537. color: #333333;
  538. border-bottom: 1rpx solid #ebeef5;
  539. }
  540. .table-td {
  541. width: 100%;
  542. text-align: center;
  543. &.table-td-name {
  544. width: 230rpx;
  545. white-space: wrap;
  546. }
  547. }
  548. .table-img {
  549. width: 40rpx;
  550. height: 40rpx;
  551. position: relative;
  552. }
  553. .sort-type {
  554. width: 250rpx;
  555. height: 50rpx;
  556. line-height: 48rpx;
  557. text-align: center;
  558. font-weight: normal;
  559. .sort-type-item {
  560. width: 50%;
  561. font-size: 26rpx;
  562. color: #555555;
  563. background-color: #fff;
  564. &.sort-type-item:nth-child(1) {
  565. border-top-left-radius: 6rpx;
  566. border-bottom-left-radius: 6rpx;
  567. border-top: 1rpx solid #CCCCCC;
  568. border-left: 1rpx solid #CCCCCC;
  569. border-bottom: 1rpx solid #CCCCCC;
  570. &.sort-type-show {
  571. color: #fff;
  572. border-top: 1rpx solid #2C6FF3;
  573. border-left: 1rpx solid #2C6FF3;
  574. border-bottom: 1rpx solid #2C6FF3;
  575. background-color: #2C6FF3;
  576. }
  577. }
  578. &.sort-type-item:nth-child(2) {
  579. border-top-right-radius: 6rpx;
  580. border-bottom-right-radius: 6rpx;
  581. border-top: 1rpx solid #CCCCCC;
  582. border-right: 1rpx solid #CCCCCC;
  583. border-bottom: 1rpx solid #CCCCCC;
  584. &.sort-type-show {
  585. color: #fff;
  586. border-top: 1rpx solid #2C6FF3;
  587. border-right: 1rpx solid #2C6FF3;
  588. border-bottom: 1rpx solid #2C6FF3;
  589. background-color: #2C6FF3;
  590. }
  591. }
  592. }
  593. }
  594. /deep/.uni-table-th {
  595. color: #333;
  596. font-weight: normal;
  597. }
  598. /deep/.uni-table-td {
  599. vertical-align: middle;
  600. }
  601. }
  602. .more {
  603. text-align: right;
  604. padding-right: 40rpx;
  605. position: relative;
  606. color: #2C6FF3;
  607. line-height: 80rpx;
  608. background-color: #fff;
  609. >view {
  610. position: absolute;
  611. right: 12rpx;
  612. top: 50%;
  613. transform: translateY(-50%);
  614. }
  615. }
  616. }
  617. }
  618. </style>