import { defineStore } from 'pinia'
import { reactive, ref } from 'vue'
import { getNodeList, getApproverNode } from '@/api/node'
export const nodeData = defineStore('node', () => {
  const nodeList = reactive([])
  const nodeListTotal = ref(0)
  const queryNodeList = (condition) => {
    getNodeList(condition).then(res => {
      if (res.code === 0) {
        nodeList.length = 0
        nodeList.push(...res.data.list)
        nodeListTotal.value = res.data.total
      }
    })
  }
  const queryApproverNode = (condition) => {
    getApproverNode(condition).then(res => {
      if (res.code === 0) {
        nodeList.length = 0
        nodeList.push(...res.data)
      }
    })
  }
  return {
    nodeList,
    nodeListTotal,
    queryNodeList,
    queryApproverNode
  }
})
