import { defineStore } from 'pinia'
import { reactive, ref } from 'vue'
import { queryProjectCost } from '@/api/cost'
export const payData = defineStore('expenses', () => {
  const projectCostList = reactive([])
  const costListTotal = ref(0)
  const getCostList = (data) => {
    queryProjectCost(data).then(res => {
      if (res.code === 0) {
        console.log('查看费用列表', res)
        projectCostList.length = 0
        const list = res.data.list === null ? [] : res.data.list
        projectCostList.push(...list)
        costListTotal.value = res.data.total
      }
    })
  }
  const changeCostList = (list) => {
    costListTotal.value = list.length
    if (list.length > 8) {
      list = list.slice(0, 8)
    }
    projectCostList.length = 0
    projectCostList.push(...list)
  }
  const changeCostTotal = (total) => {
    costListTotal.value = total
  }
  return {
    projectCostList,
    changeCostList,
    costListTotal,
    changeCostTotal,
    getCostList
  }
})
