// pinia仓库
import { defineStore } from "pinia";

export const useMainStore = defineStore("counter", {
  state: () => {
    return {
      hasDraw: true, //是否有抽奖机会
      token: "",
      posterId: 1, //测试结果
      hasPrize: true, //是否有奖品
      prizeCode: "oggSVMbeLgSK", //兑换码
      prizeMoney: "8.88", //金额
      drawKey: "",
    };
  },
  // 相当于computed属性，对state进行二次加工
  getters: {},
  // 异步处理方法
  actions: {
    updateToken(data) {
      this.token = data.authorization;
      this.hasDraw = data.drawNumber == 0 ? false : true;
    },
    updatePrize(data) {
      this.prizeCode = data.prizeCode;
      this.prizeMoney = data.prizeAmount;
      this.hasPrize = true;
    },
    updatePosterId(id) {
      this.posterId = id;
    },
    updateDrawKey(data) {
      console.log("保存结果:", data);
      this.drawKey = data.subKey;
      this.hasDraw = data.drawFlag;
    },
    updateDraw(value) {
      this.hasDraw = false;
    },
  },
});
