profit-report.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. import * as echarts from '../../../pages/ec-canvas/echarts.min';
  2. import { getOpData } from '../echarts-data.js'
  3. const app = getApp()
  4. const Constants = require('../../../utils/Constants.js');
  5. const util = require('../../../utils/util.js')
  6. const mixins = require('@/mixins/index.js')
  7. Page({
  8. mixins: [mixins],
  9. /**
  10. * 页面的初始数据
  11. */
  12. data: {
  13. service: app.globalData['reportService'],
  14. // 查询条件
  15. searchContent: [{
  16. code: 'makeTime',
  17. title: mixins.$t('currentMonth'),
  18. defaultValue: 3,
  19. searchType: Constants.searchType.date
  20. }],
  21. loading: false,
  22. ec: {},
  23. },
  24. /**
  25. * 生命周期函数--监听页面加载
  26. */
  27. onLoad: function (options) {
  28. // 报表查询数据
  29. this.getSaleProfit()
  30. },
  31. /**
  32. * 页面相关事件处理函数--监听用户下拉动作
  33. */
  34. onPullDownRefresh: function () {
  35. //调用刷新时将执行的方法
  36. this.onRefresh();
  37. },
  38. onRefresh() {
  39. //在当前页面显示导航条加载动画
  40. wx.showNavigationBarLoading()
  41. //显示 loading 提示框。需主动调用 wx.hideLoading 才能关闭提示框
  42. //报表查询数据
  43. this.getSaleProfit()
  44. },
  45. /** 去详细 */
  46. toDetail(e) {
  47. console.log(e, '/package-business-analysis/pages/profit-report/' + e.currentTarget.dataset.url)
  48. wx.navigateTo({
  49. url: '/package-business-analysis/pages/profit-report/' + e.currentTarget.dataset.url
  50. })
  51. },
  52. onShow() {
  53. this.echartsProfitDate = this.selectComponent("#echartsProfitDate")
  54. this.echartsProfitStaff = this.selectComponent("#echartsProfitStaff")
  55. this.echartsProfitOrg = this.selectComponent("#echartsProfitOrg")
  56. this.echartsProfitSku = this.selectComponent("#echartsProfitSku")
  57. },
  58. /** 设置echarts */
  59. setEcharts(name, { data, labelKey, valueKey, type }) {
  60. this[name].init((canvas, width, height, dpr) => {
  61. const chart = echarts.init(canvas, null, {
  62. width: width,
  63. height: height,
  64. devicePixelRatio: dpr
  65. });
  66. canvas.setChart(chart);
  67. chart.setOption(getOpData(data, labelKey, valueKey, type));
  68. return chart;
  69. });
  70. },
  71. /**
  72. * 销售毛利点击按日或按月查询
  73. */
  74. clickProfitDate(e) {
  75. this.setData({
  76. byDate: e.currentTarget.dataset.value
  77. })
  78. this.getSaleProfit()
  79. },
  80. /** 查询所有报表信息 */
  81. /** 查询页面展示的所有 */
  82. getSaleProfit() {
  83. this.setData({
  84. loading: true
  85. })
  86. this.excute(this.data.service, this.data.service.getSaleProfit, Object.assign({
  87. byDate: this.data.byDate
  88. }, JSON.parse(this.data.searchForm))).then(res => {
  89. if (res.data.code == Constants.SUCESS_CODE) {
  90. this.setData({
  91. profit: res.data.data.profit,
  92. })
  93. /** 图形重新渲染 */
  94. setTimeout(() => {
  95. this.setEcharts('echartsProfitDate', { data: res.data.data.dateProfit, labelKey: 'accDate', valueKey: 'profit', type: 1 })
  96. this.setEcharts('echartsProfitOrg', { data: res.data.data.orgProfit, labelKey: 'orgName', valueKey: 'profit', type: 3 })
  97. this.setEcharts('echartsProfitStaff', { data: res.data.data.staffProfit, labelKey: 'staffName', valueKey: 'profit', type: 3 })
  98. this.setEcharts('echartsProfitSku', { data: res.data.data.skuProfit, labelKey: 'skuName', valueKey: 'profit', type: 3 })
  99. }, 1000)
  100. }
  101. this.setData({
  102. loading: false
  103. })
  104. })
  105. },
  106. /**
  107. * 显示tip
  108. */
  109. showTip(e) {
  110. let item = e.currentTarget.dataset.item
  111. if (item) {
  112. util.showToast(item);
  113. }
  114. },
  115. })