export const mixin = {
  data() {
    let _self = this
    return {
      loading: false,
      date:new Date(),
      dateType:3,
      format:'本月',
      dateOption: {
        shortcuts: [
          {
            text: '本日',
            onClick(){
              _self.$refs['date-picker'].visible = false
              _self.format = '本日'
              _self.dateType = 1
              _self.getSaleProfit()
            }
          },
          {
            text: '本周',
            onClick(){
              _self.$refs['date-picker'].visible = false
              _self.format = '本周'
              _self.dateType = 2
              _self.getSaleProfit()
            }
          },
          {
            text: '本月',
            onClick(){
              _self.$refs['date-picker'].visible = false
              _self.format = '本月'
              _self.dateType = 3
              _self.getSaleProfit()

            }
          },
          {
            text: '本年',
            onClick(){
              _self.$refs['date-picker'].visible = false
              _self.format = '本年'
              _self.dateType = 5
              _self.getSaleProfit()
            }
          },
          {
            text: '区间',
            onClick(){
              _self.$refs['date-picker'].visible = false
              // _self.format = '区间'
              _self.dateType = 6
              _self.btDataShow = true
              // _self.getSaleProfit()
            }
          }
        ]
      },
      btDate:[],
      btDataShow:false,
      orderBy: null,
      orderByList:[
        {
          "text": "利润升序",
          "value": "profitAsc"
        },
        {
          "text": "利润倒序",
          "value": "profitDesc"
        },
        {
          "text": "利率升序",
          "value": "rateAsc"
        },
        {
          "text": "利率倒序",
          "value": "rateDsc"
        },
      ],
    }
  },
  methods: {
    /**
     * @desc   : 选择日期
     * @author : 洪旭东
     * @date   : 2024-06-18 13:49
     */
    onChangeDate(){
      this.format = 'yyyy年MM月'
      this.dateType = 0
      this.getSaleProfit()
    },
    /**
     * @desc   : 选择区间
     * @author : 洪旭东
     * @date   : 2024-06-18 14:54
     */
    btOk(){
      this.format = '区间：'+this.btDate[0].format('yyyy-MM-dd') + '-' + this.btDate[1].format('yyyy-MM-dd')
      this.btDataShow = false
      this.getSaleProfit()
    },
    /**
     * @desc   : 查询日期区间
     * @author : 洪旭东
     * @date   : 2024-06-18 14:49
     */
    getDateBetween(date){
      const now = new Date();
      if (this.dateType === 1){
        return {makeTimeStart: now.format('yyyy-MM-dd'),makeTimeEnd: now.format('yyyy-MM-dd')}
      } else if (this.dateType === 2){
        // 本周
        const startOfWeek = new Date(now.getFullYear(), now.getMonth(), now.getDate() - now.getDay() + 1)
        const endOfWeek = new Date(startOfWeek.getFullYear(), startOfWeek.getMonth(), startOfWeek.getDate() + 6)
        return {makeTimeStart: startOfWeek.format('yyyy-MM-dd'), makeTimeEnd: endOfWeek.format('yyyy-MM-dd')}
      } else if (this.dateType === 3){
        // 本月
        const startOfMonth = new Date(now.getFullYear(), now.getMonth(), 1)
        const endOfMonth = new Date(now.getFullYear(), now.getMonth() + 1, 0)
        return {makeTimeStart: startOfMonth.format('yyyy-MM-dd'), makeTimeEnd: endOfMonth.format('yyyy-MM-dd')}
      } else if (this.dateType === 5){
        // 本年
        const startOfYear = new Date(now.getFullYear(), 0, 1)
        const endOfYear = new Date(now.getFullYear() + 1, 0, 0)
        return {makeTimeStart: startOfYear.format('yyyy-MM-dd'), makeTimeEnd: endOfYear.format('yyyy-MM-dd')}
      } else if(this.dateType === 6){
        return {makeTimeStart: this.btDate[0].format('yyyy-MM-dd'),makeTimeEnd: this.btDate[1].format('yyyy-MM-dd')}
      } else {
        let year = date.getFullYear();
        let month = date.getMonth() + 1;
        let yearAndMonth = year + '-' + (month>=10?month:'0'+month);
        return { makeTimeStart:yearAndMonth+'-01',makeTimeEnd:yearAndMonth +'-'+ new Date(year,month,0).getDate()}
      }
    },
  }
}
