import { defineStore } from 'pinia'
import { queryHour } from '@/api/hour'
import { reactive, ref } from 'vue'

export const hourOperate = defineStore('time', () => {
  // 定义数据
  const timeList = reactive([])
  const timeTotal = ref(0)
  // 定义修改数据的方法
  const getTimeList = (data) => {
    queryHour(data).then(res => {
      if (res.code === 0) {
        timeList.length = 0
        const list = res.data.list === null ? [] : res.data.list
        timeTotal.value = res.data.total
        timeList.push(...list)
      }
    })
  }
  const changeTimeList = (list) => {
    timeList.length = 0
    timeList.push(...list)
  }
  const changeTimeTotal = (total) => {
    timeTotal.value = total
  }

  return {
    timeList,
    timeTotal,
    getTimeList,
    changeTimeList,
    changeTimeTotal
  }
})
