import {
  getUser
} from "@/api/archiveUtilize/compilationResearch/taskAllocation"
import {
  getData,
  getthemeClass,
  getTree2
} from "@/api/archiveUtilize/compilationResearch/editingTopics"
import {
  getButtonList
} from "@/api/user"
import {
  message
} from '@/utils/common'
const getDefaultState = () => {
  return {
    selectData: [],
    treeData: [],
    showButtons: {
      submit: false,
    },
  }
}
const state = getDefaultState()
const mutations = {
  GET_DATA(state, data) {
    state.selectData = data.list
  },
  GET_TREE(state, data) {
    state.treeData = data.list
  },
  GET_BUTTON_LIST(state, data) {
    data.forEach(item => {
      state.showButtons[item.key] = true
    })
  }

}
const actions = {
  async getData({
    commit,
    dispatch
  }, data) {
    await getData(data).then(res => {
      try {
        commit('GET_DATA', res.body)
      } catch (err) {
        throw new Error(err)
      }
    })
  },
  async getTree({
    commit,
    dispatch
  }, data) {
    await getTree2(data).then(res => {
      try {
        commit('GET_TREE', res.body)
      } catch (err) {
        throw new Error(err)
      }
    })
  },
  async getButtonList({
    commit
  }, params) {
    await getButtonList(params).then(res => {
      commit('GET_BUTTON_LIST', res.body.list)
    })
  }


}
export default {
  namespaced: true,
  state,
  mutations,
  actions
}
