statics.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. <template>
  2. <app-layout>
  3. <app-tab-nav :shadow="noBorder" :tabList="tabList" background="#f7f7f7" padding="0" :border="noBorder" :activeItem="activeTab" @click="tabStatus"></app-tab-nav>
  4. <view class="total-item">
  5. <view class='total-num' style='color: #417afd'>{{total_order_num}}</view>
  6. <view class="total-title">核销订单数</view>
  7. <!--#ifdef MP-ALIPAY -->
  8. <canvas @touchstart="touchIt($event,'canvasFirst')" canvas-id="canvasFirst" id="canvasFirst" class="charts" :style="{'width':cWidth*pixelRatio+'px','height':cHeight*pixelRatio+'px', 'transform': 'scale('+(1/pixelRatio)+')','margin-left':-cWidth*(pixelRatio-1)/2+'px','margin-top':-cHeight*(pixelRatio-1)/2+'px'}"></canvas>
  9. <!--#endif-->
  10. <!--#ifndef MP-ALIPAY -->
  11. <canvas @touchstart="touchIt($event,'canvasFirst')" canvas-id="canvasFirst" id="canvasFirst" class="charts"></canvas>
  12. <!--#endif-->
  13. </view>
  14. <view class="total-item">
  15. <view class='total-num' style='color: #ff9000'>{{total_order_price}}</view>
  16. <view class="total-title">核销订单金额</view>
  17. <!--#ifdef MP-ALIPAY -->
  18. <canvas @touchstart="touchIt($event,'canvasSec')" canvas-id="canvasSec" id="canvasSec" class="charts" :style="{'width':cWidth*pixelRatio+'px','height':cHeight*pixelRatio+'px', 'transform': 'scale('+(1/pixelRatio)+')','margin-left':-cWidth*(pixelRatio-1)/2+'px','margin-top':-cHeight*(pixelRatio-1)/2+'px'}"></canvas>
  19. <!--#endif-->
  20. <!--#ifndef MP-ALIPAY -->
  21. <canvas @touchstart="touchIt($event,'canvasSec')" canvas-id="canvasSec" id="canvasSec" class="charts"></canvas>
  22. <!--#endif-->
  23. </view>
  24. <view class="total-item">
  25. <view class='total-num' style='color: #41c6fe'>{{total_card}}</view>
  26. <view class="total-title">核销卡券次数</view>
  27. <!--#ifdef MP-ALIPAY -->
  28. <canvas @touchstart="touchIt($event,'canvasThird')" canvas-id="canvasThird" id="canvasThird" class="charts" :style="{'width':cWidth*pixelRatio+'px','height':cHeight*pixelRatio+'px', 'transform': 'scale('+(1/pixelRatio)+')','margin-left':-cWidth*(pixelRatio-1)/2+'px','margin-top':-cHeight*(pixelRatio-1)/2+'px'}"></canvas>
  29. <!--#endif-->
  30. <!--#ifndef MP-ALIPAY -->
  31. <canvas @touchstart="touchIt($event,'canvasThird')" canvas-id="canvasThird" id="canvasThird" class="charts"></canvas>
  32. <!--#endif-->
  33. </view>
  34. </app-layout>
  35. </template>
  36. <script>
  37. import appTabNav from "../../../components/basic-component/app-tab-nav/app-tab-nav.vue";
  38. import uCharts from '../../../components/u-charts/u-charts.min.js';
  39. import { mapState } from "vuex";
  40. var _self;
  41. var canvasObj = {};
  42. export default {
  43. name: "about",
  44. components: {
  45. "app-tab-nav": appTabNav,
  46. },
  47. data() {
  48. return {
  49. noBorder: false,
  50. tabList: [
  51. {id:0, name: '累计'},
  52. {id:1, name: '今日'},
  53. {id:-1, name: '昨日'},
  54. {id:7, name: '7日'},
  55. {id:30, name: '30日'},
  56. ],
  57. cWidth:'',
  58. cHeight:'',
  59. pixelRatio:1,
  60. card_list: [],
  61. order_num_list: [],
  62. order_price_list: [],
  63. activeTab: 0,
  64. total_card: 0,
  65. total_order_num: 0,
  66. total_order_price: 0,
  67. };
  68. },
  69. computed: {
  70. ...mapState({
  71. mall: state => state.mallConfig.mall
  72. }),
  73. },
  74. onLoad() {
  75. _self = this;
  76. //#ifdef MP-ALIPAY
  77. uni.getSystemInfo({
  78. success: function (res) {
  79. if(res.pixelRatio>1){
  80. //正常这里给2就行,如果pixelRatio=3性能会降低一点
  81. //_self.pixelRatio =res.pixelRatio;
  82. _self.pixelRatio =2;
  83. }
  84. }
  85. });
  86. //#endif
  87. this.cWidth=uni.upx2px(702);
  88. this.cHeight=uni.upx2px(340);
  89. this.activeTab = 0;
  90. this.getList();
  91. },
  92. methods: {
  93. showColumn(canvasId, chartData,color,padding) {
  94. canvasObj[canvasId] = new uCharts({
  95. $this: _self,
  96. canvasId: canvasId,
  97. type: 'area',
  98. legend:{
  99. show: false
  100. },
  101. fontSize:9,
  102. background:'#FFFFFF',
  103. colors: color,
  104. padding: padding?padding:[15,15,4,0],
  105. pixelRatio: _self.pixelRatio,
  106. animation: false,
  107. categories: chartData.categories,
  108. series: chartData.series,
  109. xAxis: {
  110. disableGrid:true,
  111. },
  112. yAxis: {
  113. gridType: 'dash',
  114. data: {
  115. disabled: true
  116. }
  117. },
  118. dataLabel: false,
  119. dataPointShape: false,
  120. width: _self.cWidth*_self.pixelRatio,
  121. height: _self.cHeight*_self.pixelRatio,
  122. extra: {
  123. area: {
  124. type: 'curve',
  125. addLine: true
  126. },
  127. tooltip:{
  128. bgColor:'#000000',
  129. bgOpacity:0.7,
  130. }
  131. }
  132. });
  133. },
  134. tabStatus(e) {
  135. this.activeTab = e.currentTarget.dataset.id;
  136. this.getList();
  137. },
  138. touchIt(e,id) {
  139. canvasObj[id].showToolTip(e, {
  140. format: function (item, category) {
  141. item.color = 'rgba(0,0,0,0)';
  142. if(typeof item.data === 'object'){
  143. return category + ' ' + item.name + ':' + item.data.value
  144. }else{
  145. return category + ' ' + item.name + ':' + item.data
  146. }
  147. }
  148. });
  149. },
  150. getList() {
  151. let that = this;
  152. that.$request({
  153. url: that.$api.clerk.statistics,
  154. data: {
  155. key: that.activeTab
  156. }
  157. }).then(response=>{
  158. that.$hideLoading();
  159. if(response.code == 0) {
  160. that.card_list = response.data.card_list;
  161. that.order_num_list = response.data.order_num_list;
  162. that.order_price_list = response.data.order_price_list;
  163. that.total_card = 0;
  164. that.total_order_num = 0;
  165. that.total_order_price = 0;
  166. that.card_list.forEach(function(row){
  167. that.total_card = (+that.total_card + +row.num).toFixed(2);
  168. })
  169. that.order_num_list.forEach(function (row) {
  170. that.total_order_num = (+that.total_order_num + +row.num).toFixed(2);
  171. })
  172. that.order_price_list.forEach(function (row) {
  173. that.total_order_price = (+that.total_order_price + +row.num).toFixed(2);
  174. })
  175. let Column_1 = {categories:[],series:[{name: '核销订单数',data: []}]};
  176. let Column_2 = {categories:[],series:[{name: '核销订单金额',data: []}]};
  177. let Column_3 = {categories:[],series:[{name: '核销卡券次数',data: []}]};
  178. let padding = [15,15,4,-20];
  179. if(that.activeTab == 1 || that.activeTab == -1 || that.activeTab == 7) {
  180. padding = [15,15,4,0];
  181. }
  182. // 图表一
  183. Column_1 = that.create(response.data.order_num_list,Column_1);
  184. _self.showColumn("canvasFirst",Column_1,["#417afd"],padding);
  185. // 图表二
  186. Column_2 = that.create(response.data.order_price_list,Column_2);
  187. _self.showColumn("canvasSec",Column_2,["#ff9000"]);
  188. // 图表三
  189. Column_3 = that.create(response.data.card_list,Column_3);
  190. _self.showColumn("canvasThird",Column_3,["#41c6fe"]);
  191. }else {
  192. uni.showToast({
  193. title: response.msg,
  194. icon: 'none',
  195. duration: 1000
  196. });
  197. }
  198. }).catch(response => {
  199. that.$hideLoading();
  200. });
  201. },
  202. create(list,Column) {
  203. let date;
  204. let that = this;
  205. list.forEach(function(row,index){
  206. date = list[index].time;
  207. if(that.activeTab == 1 || that.activeTab == -1) {
  208. if(index % 6 == 0) {
  209. if(date < 10) {
  210. date = '0' + date + ':00'
  211. }else {
  212. date = date + ':00'
  213. }
  214. Column.categories.push(date);
  215. }else {
  216. Column.categories.push('')
  217. }
  218. }else if(that.activeTab == 30) {
  219. if(index % 5 == 0 || index == list.length - 1) {
  220. Column.categories.push(date);
  221. }else {
  222. Column.categories.push('')
  223. }
  224. }else {
  225. Column.categories.push(date);
  226. }
  227. Column.series[0].data.push(row.num);
  228. })
  229. if(that.activeTab == 1 || that.activeTab == -1) {
  230. Column.categories.push('24:00')
  231. }
  232. return Column
  233. }
  234. }
  235. }
  236. </script>
  237. <style scoped lang="scss">
  238. .total-item {
  239. width: #{702rpx};
  240. margin: #{24rpx} #{24rpx} 0;
  241. border-radius: #{16rpx};
  242. background-color: #fff;
  243. padding-top: #{54rpx};
  244. text-align: center;
  245. }
  246. .total-title {
  247. color: #999999;
  248. font-size: #{24rpx};
  249. }
  250. .total-num {
  251. font-size: #{46rpx};
  252. }
  253. .charts{
  254. width: 100%;
  255. height:#{340rpx};
  256. margin: #{85rpx} auto 0;
  257. }
  258. </style>