const useOperateStore = defineStore("operate", {
  state: () => ({
    goodId: sessionStorage.getItem('operate_goodId') || "",
    status: Number(sessionStorage.getItem('operate_status')) || 1, // 1编辑商品 2查看商品
  }),
  actions: {
    // 获取商品信息
    getGoodSInfo() {
      return {
        goodId: this.goodId,
        status: this.status,
      };
    },
    // 设置商品信息
    setGoodInfo(info) {
      this.goodId = info?.goodId ? info?.goodId : "";
      this.status = info?.status ? info?.status : 1;
       // 手动保存到sessionStorage
      sessionStorage.setItem('operate_goodId', this.goodId);
      sessionStorage.setItem('operate_status', String(this.status));
    },
    // 初始化商品信息
    initGoodInfo() {
      this.goodId = "";
      this.status = 1;
      sessionStorage.removeItem('operate_goodId');
      sessionStorage.removeItem('operate_status');
    },
  },
});

export default useOperateStore;
