import {
  getPointTree,
} from "@/api/intelligent-warehouse/warehouse-setting/collection-point.js"
import {
  getData,
} from "@/api/intelligent-warehouse/warehouse-management/th-registration.js"
import {
  message
} from '@/utils/common'
const getDefaultState = () => {
  return {
    treeLoading: false,
    treeData: [],
    tableData: [],
    tableLoading: false,
    pagination: {
      pageSize: 10,
      pageNum: 1,
      total: 0,
    },
  }
}
const state = getDefaultState()
const mutations = {
  GET_TREE(state, data) {
    state.treeData = data.tree
    state.treeLoading = false
  },
  GET_DATA(state, data) {
    state.tableData = data.list
    state.pagination.total = data.total
    state.tableLoading = false
  },
}
const actions = {
  async getPointTree({
    commit,
    dispatch
  }, data) {
    await getPointTree(data).then(res => {
      try {
        commit('GET_TREE', res.body)
      } catch (err) {
        throw new Error(err)
      }
    })
  },
  async getData({
    commit,
    dispatch
  }, data) {
    await getData(data).then(res => {
      try {
        commit('GET_DATA', res.body)
      } catch (err) {
        throw new Error(err)
      }
    })
  }
}
export default {
  namespaced: true,
  state,
  mutations,
  actions
}
