import { Local } from "@/utils/storage"
import { API } from "@/axios/api/index"

const user = {
  state: {
    dictData: {
      followUpTime: [], //随访时间
      articleTags: [], //文章标签
      articleType: [], //文章类型
      articleMode: [], //文章模式
    },
  },
  mutations: {
    SET_DICT: (state, list) => {
      Local.set("dictData", list)
      state.dictData = list
    },
    DEL_DICT: (state) => {
      Local.remove("dictData")
      for (let k in state.dictData) {
        state.dictData[k] = []
      }
    },
  },
  actions: {
    getDict: ({ state, commit }) => {
      const dictData = Object.assign(state.dictData, Local.get("dictData"))
      const codes = []
      for (let k in dictData) {
        if (dictData[k].length == 0) {
          codes.push(k)
        }
      }
      if (codes.length > 0) {
        // API.getEnumerateList(codes).then((res) => {
        //   if (res.code == 1) {
        //     const d = res.object
        //     d.map((item) => {
        //       dictData[item.code] = item.items.map((child) => {
        //         return {
        //           label: child.itemName,
        //           value: child.itemCode,
        //         }
        //       })
        //     })
        //     commit("SET_DICT", dictData)
        //   }
        // })
      } else {
        commit("SET_DICT", dictData)
      }
    },
  },
}

export default user
