// package5/pages/report/detail/detail.js

const app = getApp()
const Constants = require('../../../../utils/Constants.js');
const mixins = require('@/mixins/index.js')

Page({
  mixins: [mixins],
  /**
   * 页面的初始数据
   */
  data: {
    service: app.globalData['reportService'],
    // 查询条件
    searchContent: [{
      code: 'makeTime',
      title: mixins.$t('currentMonth'),
      defaultValue: 3,
      searchType: Constants.searchType.date
    },
    {
      code: 'orderBy',
      title: mixins.$t('sort'),
      searchType: Constants.searchType.radio,
      value: 1,
      options: [
        {
          "text": "利润升序",
          "value": "profitAsc"
        },
        {
          "text": "利润倒序",
          "value": "profitDesc"
        },
        {
          "text": "利率升序",
          "value": "rateAsc"
        },
        {
          "text": "利率倒序",
          "value": "rateDsc"
        },
      ],
    }
    ],
    tab1Columns: [
      {
        "name": "staffName",
        "title": "员工名称",
        "width": "50%"
      },
      {
        "name": "profit",
        "title": "销售利润",
        "type": "amount",
        "width": "30%"
      },
      {
        "after": "%",
        "name": "profitRate",
        "title": "利润率",
        "width": "20%"
      }
    ],
    tab1TableData: [],
    tab1TopData: [
      {
        "title": "销售利润（总额）",
        "type": "amount",
        "value": "0.00"
      },
      {
        "title": "利润率",
        "type": "amount",
        "value": "0.00"
      }
    ],
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getReportData()
  },
  /** 查询页面展示的所有 */
  getReportData() {
    this.excute(this.data.service, this.data.service.getSaleProfitGroupByStaff, JSON.parse(this.data.searchForm)).then(res => {
      if (res.data.code == Constants.SUCESS_CODE) {
        this.setData({
          tab1TopData: [{ title: '销售利润（总额）', type: 'amount', value: res.data.data.profit ? res.data.data.profit.profit : 0 },
          { title: '利润率', type: '', value: (res.data.data.profit ? res.data.data.profit.profitRate : 0) + '%' }
          ],
          tab1TableData: res.data.data.staffProfit
        })
      }
    })
  },
})