import { ref,onMounted,nextTick } from 'vue'
import moment from "moment";

export function bussinessTripH() {
  //周数之差
  const weekDiff=ref(0)
  const tableTheadColumns=ref(['本周','下一周'])
  const BaseDate=ref('')
  const weekQuery=ref(0)

  const toogelDate=(type,callback)=>{
    weekQuery.value=type
    if(weekQuery.value==0){
      BaseDate.value=''
      tableTheadColumns.value=['本周','下一周']
      weekDiff.value=0
    }else{
      let prePeriodDate,nextPeriodDate;
      weekDiff.value=weekQuery.value==1?weekDiff.value-2:weekDiff.value+2
      if(weekDiff.value==0){
        // 为0代表本期
        prePeriodDate='本周'
        nextPeriodDate='下一周'
      }else if(weekQuery.value==1){
        // 往前推两周
        prePeriodDate = moment(BaseDate.value).subtract(14,'days').format('YYYY-MM-DD')+
        '——'+moment(BaseDate.value).subtract(8,'days').format('YYYY-MM-DD')
        nextPeriodDate = moment(BaseDate.value).subtract(7,'days').format('YYYY-MM-DD')+
        '——'+moment(BaseDate.value).subtract(1,'days').format('YYYY-MM-DD')
      }else{
        // 往后推两周
        prePeriodDate = moment(BaseDate.value).add(14,'days').format('YYYY-MM-DD')+
        '——'+moment(BaseDate.value).add(20,'days').format('YYYY-MM-DD')
        nextPeriodDate = moment(BaseDate.value).add(21,'days').format('YYYY-MM-DD')+
        '——'+moment(BaseDate.value).add(27,'days').format('YYYY-MM-DD')
      }
      tableTheadColumns.value=[prePeriodDate,nextPeriodDate]
    }
    callback()
  }
  return {
    tableTheadColumns,
    BaseDate,
    weekQuery,
    toogelDate
  }
}