import { activity, User } from "@/config/api.js";
export default {
  data() {
    return {
      specialIsHintShow: false, // 按钮的显示
      specialGoFollowShow: false, // 弹框的隐藏显示
      specialAccounts: `您已开启【专项调研】新活动通知<br/><br/>请关注【查研观向小助手】公众号,及时获取微信消息提醒`,
      specialIsFollow: false, // 是否关注
      specialPopupMsg: "", // 消息的文案
      show_cancel_button: false, // 取消按钮的隐藏显示
      show_confirm_button: false, // 确定按钮的隐藏显示
    };
  },
  computed: {},
  methods: {
    // 点击小icon
    reminderTextHandler(item) {
      this.specialPopupMsg = "";
      this.specialIsHintShow = true;
      this.specialGoFollowShow = true;
      this.specialAccounts = item.Explain;
    },
    // 报名或者取消报名
    async applyOfcancel(item, type = "") {
      this.show_confirm_button = true;
      if ((type != "back" && item.IsTrip == 1) || (type == "back" && item.IsSignup == 1)) {
        // 取消报名
        const str = item.ActivityTime.replace(/-/g, "/");
        const date = new Date(str);
        const times = date.getTime();
        const num = new Date().getTime();
        let twoDays = times - num <= 3600000 * 48;
        uni.showModal({
          content: twoDays ? "活动开始前48小时内,取消报名仍会维持扣点,确定要取消报名吗?" : "您要取消此次专项调研的预报名吗?",
          confirmColor: "#376cbb",
          cancelColor: "#606266",
          success: async (res) => {
            if (res.confirm) {
              const res = await activity.activityApecialCancel({
                ActivityId: item.ActivityId,
                PageRouter: this.$store.state.pageRouterActivity,
              });
              if (res.Ret === 200) {
                uni.showToast({
                  title: "已取消",
                  duration: 2000,
                });
                item.TripNum > 0 && (item.TripNum -= 1);
                type == "back" ? (item.IsSignup = 0) : (item.IsTrip = 0);
              }
            }
          },
        });
      } else {
        // 报名
        const res = await activity.activityApecialAdd({ ActivityId: item.ActivityId, PageRouter: this.$store.state.pageRouterActivity });
        if (res.Ret == 200) {
          this.modalShow(res);
          if (res.Data.SignupStatus == 1) {
            type == "back" ? (item.IsSignup = 1) : (item.IsTrip = 1);
          }
        }
      }
    },

    // 弹框的数据重置
    ininModalHandler() {
      this.show_cancel_button = false;
      this.show_confirm_button = false;
      this.specialIsHintShow = false;
      this.specialGoFollowShow = false;
      this.isCancelBtn = false;
    },

    // 显示弹框
    modalShow(res) {
      this.show_confirm_button = true;
      this.specialGoFollowShow = true;
      this.specialAccounts = res.Data.PopupMsg;
      this.specialPopupMsg = res.Data.PopupMsg2;
    },
  },
};