export default {
  namespaced: true,
  state: {
    drugsInfo: (() => {
      try {
        const raw = sessionStorage.getItem('drugsInfo');
        if (!raw || raw === 'undefined') return {};
        return JSON.parse(raw) || {};
      } catch (e) {
        return {};
      }
    })(), // 病人信息
    //  drugsInfo: sessionStorage.getItem('drugsInfo') ? JSON.parse(sessionStorage.getItem('drugsInfo')) : {}, // 病人信息
    recipeId: sessionStorage.getItem('recipeId'),
  },
  mutations: {
    setDrugsInfo(state, data) {
      const safe = data == null ? {} : data;
      sessionStorage.setItem('drugsInfo', JSON.stringify(safe))
      state.drugsInfo = safe


      //  sessionStorage.setItem('drugsInfo', JSON.stringify(data))
      // state.drugsInfo = data
    },
    setRecipeId(state, id) {
      sessionStorage.setItem('recipeId', id)
      state.recipeId = id
    }

  },
  getters: {
    drug(state) {
      return state
    }
  }
};