import * as dictApi from "../../dao/dict";
const dicts = {
  // state子属性 key值命名来自dao/dict.js 中的方法名 以便策略模式请求
  state: {
    CarType: [],
    CarColor: [],
    PlateColor: [],
    TrafficActor: [],
    CrowdDeep: [],
    Owner: [],
    Nature: [],
    IfLocal: [],
    EventType: [],
    CrossInfo: [],
    Direction: [],
    Visibility: [],
    CrossType: [],
    TrafficStatus:[]
  },
  actions: {
    // 查询字典是否存在 并 请求 存储 vuex
    async QUERY_DICT({ state }, typeParam) {
      if (!state[typeParam.type].length) {
        let res = await dictApi[`dict${typeParam.type}`]();
        if (typeParam.type === "CrossInfo") {
          for (let i = 0; i < res.content.length; i++) {
            res.content[i].code = res.content[i].crossId;
            res.content[i].name = res.content[i].crossName;
          }
        }
        state[typeParam.type] = res.content;
      }
      // return state[typeParam.type]
    },
  },
};
export default dicts;
