statics.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. <template>
  2. <app-layout>
  3. <view class='main-between total'>
  4. <view class='box-grow-1'>
  5. <view class='data-num'>{{all_data.day_data}}</view>
  6. <view>昨日{{setting.form && setting.form.statics_text ? setting.form.statics_text :'分红'}}</view>
  7. </view>
  8. <view class='box-grow-1'>
  9. <view class='data-num'>{{all_data.day_7_data}}</view>
  10. <view>7日{{setting.form && setting.form.statics_text ? setting.form.statics_text :'分红'}}总计</view>
  11. </view>
  12. <view class='box-grow-1'>
  13. <view class='data-num'>{{all_data.month_12_data}}</view>
  14. <view>月{{setting.form && setting.form.statics_text ? setting.form.statics_text :'分红'}}总计</view>
  15. </view>
  16. </view>
  17. <view class='canvas'>
  18. <view class="choose main-center">
  19. <view class="choose-list main-center">
  20. <view :class="[date == 0 ? 'active' : '','cross-center','main-center','choose-item','left-choose-item']">
  21. <view @click="tablist(0)">昨日{{setting.form && setting.form.statics_text ? setting.form.statics_text :'分红'}}</view>
  22. </view>
  23. <view :class="[date == 1 ? 'active' : '','cross-center','main-center','choose-item']">
  24. <view @click="tablist(1)">7日{{setting.form && setting.form.statics_text ? setting.form.statics_text :'分红'}}</view>
  25. </view>
  26. <view :class="[date == 2 ? 'active' : '','cross-center','main-center','choose-item','right-choose-item']">
  27. <view @click="tablist(2)">月{{setting.form && setting.form.statics_text ? setting.form.statics_text :'分红'}}</view>
  28. </view>
  29. </view>
  30. </view>
  31. <view class="box">
  32. <!--#ifdef MP-ALIPAY -->
  33. <canvas @touchstart="touchIt($event,'canvasColumn')" canvas-id="canvasColumn" id="canvasColumn" 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>
  34. <!--#endif-->
  35. <!--#ifndef MP-ALIPAY -->
  36. <canvas @touchstart="touchIt($event)" canvas-id="canvasColumn" id="canvasColumn" class="charts"></canvas>
  37. <!--#endif-->
  38. </view>
  39. </view>
  40. </app-layout>
  41. </template>
  42. <script>
  43. import uCharts from '../../../components/u-charts/u-charts.min.js';
  44. var _self;
  45. var canvaColumn=null;
  46. export default {
  47. data() {
  48. return {
  49. list: [],
  50. setting: {},
  51. cWidth:'',
  52. cHeight:'',
  53. pixelRatio:1,
  54. date: 0,
  55. show: true,
  56. all_data: []
  57. }
  58. },
  59. methods: {
  60. tablist(e) {
  61. let that = this;
  62. this.date = e;
  63. this.show = true;
  64. let Column = {categories:[],series:[{name: '分红金额',data: []}]};
  65. let date;
  66. let padding;
  67. if(e == 0) {
  68. that.list.day_list.forEach(function(row,index){
  69. date = that.list.day_list[index].created_at;
  70. Column.series[0].data.push(row.bonus_price);
  71. if(index % 6 == 0) {
  72. if(date < 10) {
  73. date = '0' + date + ':00'
  74. }else {
  75. date = date + ':00'
  76. }
  77. Column.categories.push(date);
  78. }else {
  79. Column.categories.push('')
  80. }
  81. })
  82. Column.categories.push('24:00')
  83. _self.showColumn("canvasColumn",Column,'line');
  84. }else if(e == 1) {
  85. that.list.day_7_list.forEach(function(row,index){
  86. date = that.list.day_7_list[index].created_at.slice(5);
  87. Column.series[0].data.push(row.bonus_price);
  88. Column.categories.push(date);
  89. })
  90. padding = [15,15,4,-30]
  91. _self.showColumn("canvasColumn",Column,'column',padding);
  92. }else if(e == 2) {
  93. that.list.month_12_list.forEach(function(row,index){
  94. date = that.list.month_12_list[index].created_at.slice(5) + '月';
  95. Column.series[0].data.push(row.bonus_price);
  96. Column.categories.push(date);
  97. })
  98. padding = [15,15,4,-30]
  99. _self.showColumn("canvasColumn",Column,'column',padding);
  100. }
  101. this.$forceUpdate();
  102. },
  103. touchIt(e) {
  104. canvaColumn.showToolTip(e, {
  105. format: function (item, category) {
  106. item.color = 'rgba(0,0,0,0)';
  107. if(typeof item.data === 'object'){
  108. return category + ' ' + item.name + ':' + item.data.value
  109. }else{
  110. return category + ' ' + item.name + ':' + item.data
  111. }
  112. }
  113. });
  114. },
  115. getSetting() {
  116. let that = this;
  117. that.$request({
  118. url: that.$api.bonus.setting,
  119. }).then(response=>{
  120. if(response.code === 0) {
  121. that.setting = response.data.list;
  122. if (that.setting.form && that.setting.form.orders) {
  123. uni.setNavigationBarTitle({
  124. title: that.setting.form.statistic_bonus,
  125. })
  126. } else {
  127. uni.setNavigationBarTitle({
  128. title: '分红统计',
  129. })
  130. }
  131. }else {
  132. uni.showToast({
  133. title: response.msg,
  134. icon: 'none',
  135. duration: 1000
  136. });
  137. }
  138. }).catch(() => {
  139. that.$hideLoading();
  140. });
  141. },
  142. getList() {
  143. let that = this;
  144. uni.showLoading({
  145. mask: true,
  146. title: '加载中...'
  147. });
  148. that.$request({
  149. url: that.$api.bonus.data,
  150. }).then(response=>{
  151. uni.hideLoading();
  152. if(response.code == 0) {
  153. that.list = response.data.list;
  154. that.all_data = response.data.all_data;
  155. let Column = {categories:[],series:[{name: '分红金额',data: []}]};
  156. let date;
  157. response.data.list.day_list.forEach(function(row,index){
  158. date = response.data.list.day_list[index].created_at;
  159. Column.series[0].data.push(row.bonus_price);
  160. if(index % 6 == 0) {
  161. if(date < 10) {
  162. date = '0' + date + ':00'
  163. }else {
  164. date = date + ':00'
  165. }
  166. Column.categories.push(date);
  167. }else {
  168. Column.categories.push('')
  169. }
  170. })
  171. Column.categories.push('24:00')
  172. _self.showColumn("canvasColumn",Column,'line');
  173. }else {
  174. uni.showToast({
  175. title: response.msg,
  176. icon: 'none',
  177. duration: 1000
  178. });
  179. }
  180. }).catch(response => {
  181. uni.hideLoading();
  182. });
  183. },
  184. showColumn(canvasId,chartData,type,padding){
  185. canvaColumn=new uCharts({
  186. $this:_self,
  187. canvasId: canvasId,
  188. type: type ? type : 'column',
  189. legend:{
  190. show: false
  191. },
  192. fontSize:9,
  193. background:'#FFFFFF',
  194. colors: ["#ff4544"],
  195. pixelRatio:_self.pixelRatio,
  196. padding: padding ? padding : [15,15,4,0],
  197. categories: chartData.categories,
  198. series: chartData.series,
  199. xAxis: {
  200. disableGrid:true,
  201. },
  202. yAxis: {
  203. gridType: 'dash',
  204. data: {
  205. disabled: true
  206. }
  207. },
  208. dataLabel: false,
  209. dataPointShape: false,
  210. width: _self.cWidth*_self.pixelRatio,
  211. height: _self.cHeight*_self.pixelRatio,
  212. extra: {
  213. tooltip:{
  214. bgColor:'#000000',
  215. bgOpacity:0.7,
  216. }
  217. }
  218. });
  219. },
  220. changeData(){
  221. canvaColumn.updateData({
  222. series: _self.serverData.ColumnB.series,
  223. categories: _self.serverData.ColumnB.categories
  224. });
  225. }
  226. },
  227. onLoad() { this.$commonLoad.onload();
  228. _self = this;
  229. //#ifdef MP-ALIPAY
  230. uni.getSystemInfo({
  231. success: function (res) {
  232. if(res.pixelRatio>1){
  233. //正常这里给2就行,如果pixelRatio=3性能会降低一点
  234. //_self.pixelRatio =res.pixelRatio;
  235. _self.pixelRatio = 2;
  236. }
  237. }
  238. });
  239. //#endif
  240. this.cWidth=uni.upx2px(650);
  241. this.cHeight=uni.upx2px(440);
  242. this.getList();
  243. this.getSetting();
  244. }
  245. }
  246. </script>
  247. <style scoped lang="scss">
  248. .total {
  249. height: #{150rpx};
  250. background-color: #fff;
  251. text-align: center;
  252. font-size: #{24rpx};
  253. color: #999;
  254. }
  255. .data-num {
  256. font-size: #{36rpx};
  257. font-family: DIN;
  258. color: #353535;
  259. margin-top: #{36rpx};
  260. margin-bottom: #{6rpx};
  261. }
  262. .canvas {
  263. width: #{702rpx};
  264. margin: #{24rpx};
  265. background-color: #fff;
  266. border-radius: #{16rpx};
  267. padding: #{40rpx} #{24rpx} #{24rpx};
  268. }
  269. .choose {
  270. width: 100%;
  271. height: #{56rpx};
  272. line-height: #{56rpx};
  273. font-size: #{24rpx};
  274. color: #666;
  275. margin: 0 auto #{40rpx};
  276. }
  277. .choose-list {
  278. border-radius: #{28rpx};
  279. }
  280. .choose .choose-item {
  281. padding: 0 #{24rpx};
  282. background-color: #fff;
  283. border-bottom: #{1rpx} solid #ff4544;
  284. border-top: #{1rpx} solid #ff4544;
  285. }
  286. .choose .choose-item.active {
  287. background-color: #ff4544;
  288. color: #fff;
  289. }
  290. .left-choose-item {
  291. border-top-left-radius: #{28rpx};
  292. border-left: #{1rpx} solid #ff4544;
  293. border-bottom-left-radius: #{28rpx};
  294. }
  295. .right-choose-item {
  296. border-top-right-radius: #{28rpx};
  297. border-right: #{1rpx} solid #ff4544;
  298. border-bottom-right-radius: #{28rpx};
  299. }
  300. .box {
  301. width: 100%;
  302. height: #{440rpx};
  303. }
  304. .charts{
  305. width: #{650rpx};
  306. height:#{440rpx};
  307. background-color: #FFFFFF;
  308. }
  309. </style>