statics.vue 12 KB

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