"use strict";
const common_vendor = require("../../common/vendor.js");
const sheep_index = require("../../sheep/index.js");
const sheep_api_member_signin = require("../../sheep/api/member/signin.js");
require("../../sheep/api/index.js");
require("../../sheep/api/distri/score.js");
require("../../sheep/request/index.js");
require("../../sheep/config/index.js");
require("../../sheep/store/index.js");
require("../../sheep/store/app.js");
require("../../sheep/api/promotion/diy.js");
require("../../sheep/platform/index.js");
require("../../sheep/platform/provider/wechat/index.js");
require("../../sheep/platform/provider/wechat/miniProgram.js");
require("../../sheep/api/member/auth.js");
require("../../sheep/api/member/social.js");
require("../../sheep/api/member/user.js");
require("../../sheep/platform/provider/apple/index.js");
require("../../sheep/platform/share.js");
require("../../sheep/router/index.js");
require("../../sheep/hooks/useModal.js");
require("../../sheep/helper/index.js");
require("../../sheep/helper/test.js");
require("../../sheep/helper/digit.js");
require("../../sheep/helper/throttle.js");
require("../../sheep/url/index.js");
require("../../sheep/platform/pay.js");
require("../../sheep/api/pay/order.js");
require("../../sheep/store/user.js");
require("../../sheep/store/cart.js");
require("../../sheep/api/trade/cart.js");
require("../../sheep/api/pay/wallet.js");
require("../../sheep/api/trade/order.js");
require("../../sheep/api/promotion/coupon.js");
require("../../sheep/store/sys.js");
require("../../sheep/store/modal.js");
require("../../sheep/api/distri/share.js");
require("../../sheep/api/distri/team.js");
require("../../sheep/api/infra/file.js");
require("../../sheep/api/member/address.js");
require("../../sheep/api/member/point.js");
require("../../sheep/api/migration/app.js");
require("../../sheep/api/migration/chat.js");
require("../../sheep/api/migration/index.js");
require("../../sheep/api/migration/third.js");
require("../../sheep/api/pay/channel.js");
require("../../sheep/api/product/category.js");
require("../../sheep/api/product/comment.js");
require("../../sheep/api/product/favorite.js");
require("../../sheep/api/product/history.js");
require("../../sheep/api/product/spu.js");
require("../../sheep/api/promotion/activity.js");
require("../../sheep/api/promotion/article.js");
require("../../sheep/api/promotion/bargain.js");
require("../../sheep/api/promotion/combination.js");
require("../../sheep/api/promotion/rewardActivity.js");
require("../../sheep/api/promotion/seckill.js");
require("../../sheep/api/system/area.js");
require("../../sheep/api/system/voice.js");
require("../../sheep/api/trade/afterSale.js");
require("../../sheep/api/trade/brokerage.js");
require("../../sheep/api/trade/config.js");
require("../../sheep/api/trade/delivery.js");
require("../../sheep/config/zIndex.js");
if (!Array) {
  const _easycom_s_empty2 = common_vendor.resolveComponent("s-empty");
  const _easycom_su_popup2 = common_vendor.resolveComponent("su-popup");
  const _easycom_s_layout2 = common_vendor.resolveComponent("s-layout");
  (_easycom_s_empty2 + _easycom_su_popup2 + _easycom_s_layout2)();
}
const _easycom_s_empty = () => "../../sheep/components/s-empty/s-empty.js";
const _easycom_su_popup = () => "../../sheep/ui/su-popup/su-popup.js";
const _easycom_s_layout = () => "../../sheep/components/s-layout/s-layout.js";
if (!Math) {
  (_easycom_s_empty + _easycom_su_popup + _easycom_s_layout)();
}
const _sfc_main = {
  __name: "sign",
  setup(__props) {
    common_vendor.useCssVars((_ctx) => ({
      "19707c8c": common_vendor.unref(headerBg)
    }));
    const headerBg = sheep_index.sheep.$url.css("/static/images/sign.png");
    const state = common_vendor.reactive({
      data: {
        days: [],
        //日历
        rules: {}
        //规则
      },
      cur_year: 0,
      //当前选的年
      cur_month: 0,
      //当前选的月
      cur_day: 0,
      //当前选择的天
      weeks_ch: [
        {
          title: "日",
          value: "0"
        },
        {
          title: "一",
          value: "1"
        },
        {
          title: "二",
          value: "2"
        },
        {
          title: "三",
          value: "3"
        },
        {
          title: "四",
          value: "4"
        },
        {
          title: "五",
          value: "5"
        },
        {
          title: "六",
          value: "6"
        }
      ],
      //星期
      showModel: false,
      //签到弹框
      continue_days: 0,
      //连续签到天数
      signin: {},
      // 签到
      showRetroactive: false,
      //补签弹框
      date: "",
      //补签选中日期
      isSign: 0,
      //今天是否签到
      loading: true
    });
    async function onSign() {
      const {
        code,
        data
      } = await sheep_api_member_signin.SignInApi.createSignInRecord();
      if (code === 0) {
        state.showModel = true;
        state.signin = data;
        state.isSign = 1;
        common_vendor.index.setStorageSync("isSign", true);
      }
    }
    common_vendor.watch(() => state.showModel, (newValue) => {
      if (newValue) {
        setTimeout(onConfirm, 3e3);
      }
    });
    function onConfirm() {
      state.showModel = false;
      getData({
        month: formatDate(/* @__PURE__ */ new Date()).substring(0, 7)
      });
    }
    function formatDate(t) {
      let date = new Date(t);
      let year = date.getFullYear();
      let month = String(date.getMonth() + 1).padStart(2, "0");
      let day = String(date.getDate()).padStart(2, "0");
      let dateString = `${year}-${month}-${day}`;
      return dateString;
    }
    async function getData(mouth) {
      const {
        code,
        data
      } = await sheep_api_member_signin.SignInApi.getOwnSignInMoon(mouth);
      if (code === 0) {
        data.days.forEach((i, index) => {
          if (i.week == "SUNDAY") {
            i.week = 0;
          } else if (i.week == "MONDAY") {
            i.week = 1;
          } else if (i.week == "TUESDAY") {
            i.week = 2;
          } else if (i.week == "WEDNESDAY") {
            i.week = 3;
          } else if (i.week == "THURSDAY") {
            i.week = 4;
          } else if (i.week == "FRIDAY") {
            i.week = 5;
          } else if (i.week == "SATURDAY") {
            i.week = 6;
          }
          i.date = formatDate(i.date);
        });
        state.data = data;
      } else {
        state.data = null;
      }
      state.loading = false;
      if (state.data) {
        state.data.days.forEach((i, index) => {
          if (index < i.week) {
            index++;
            var obj = {
              day: null,
              isSign: false
            };
            state.data.days.unshift(obj);
          }
          if (index == 1) {
            let arr = i.date.split("-");
            state.cur_year = arr[0];
            state.cur_month = arr[1];
          }
        });
        if (state.data.days[0].day == null) {
          state.data.days.forEach((i, index) => {
            if (i.current == "today") {
              state.isSign = i.isSign;
            }
          });
        }
        state.continue_days = data.continueDays;
      }
    }
    common_vendor.onReady(() => {
      getData({
        month: formatDate(/* @__PURE__ */ new Date()).substring(0, 7)
      });
    });
    const handleCalendar = (type) => {
      const cur_year = parseInt(state.cur_year);
      const cur_month = parseInt(state.cur_month);
      console.log(cur_year, cur_month);
      var newMonth;
      var newYear = cur_year;
      if (type === 0) {
        newMonth = cur_month - 1;
        if (newMonth < 1) {
          newYear = cur_year - 1;
          newMonth = 12;
        } else if (newMonth < 10) {
          newMonth = "0" + newMonth;
        }
      } else {
        newMonth = cur_month + 1;
        if (newMonth > 12) {
          newYear = cur_year + 1;
          newMonth = "01";
        } else if (newMonth < 10) {
          newMonth = "0" + newMonth;
        }
      }
      console.log(newYear + "-" + newMonth);
      getData({
        month: newYear + "-" + newMonth
      });
    };
    return (_ctx, _cache) => {
      var _a, _b, _c;
      return common_vendor.e({
        a: state.loading
      }, state.loading ? {} : state.data && !state.loading ? common_vendor.e({
        c: common_vendor.t(state.continue_days),
        d: common_vendor.o(($event) => handleCalendar(0)),
        e: common_vendor.t(state.cur_year || "--"),
        f: common_vendor.t(state.cur_month || "--"),
        g: common_vendor.o(($event) => handleCalendar(1)),
        h: common_vendor.f(state.weeks_ch, (item, index, i0) => {
          return {
            a: common_vendor.t(item.title),
            b: index
          };
        }),
        i: common_vendor.f(state.data.days, (item, j, i0) => {
          return common_vendor.e({
            a: item.isSign
          }, item.isSign ? {
            b: common_vendor.t(item.day < 10 ? "0" + item.day : item.day),
            c: common_vendor.unref(sheep_index.sheep).$url.static("/static/images/correct.png")
          } : {}, {
            d: item.isReplenish == 1
          }, item.isReplenish == 1 ? {
            e: common_vendor.t(item.day < 10 ? "0" + item.day : item.day)
          } : {}, {
            f: item.isReplenish == 0 && !item.isSign
          }, item.isReplenish == 0 && !item.isSign ? {
            g: common_vendor.t(item.day < 10 ? "0" + item.day : item.day)
          } : {}, {
            h: j
          });
        }),
        j: state.isSign === 0
      }, state.isSign === 0 ? {
        k: common_vendor.o(onSign)
      } : {}, {
        l: state.isSign === 1
      }, state.isSign === 1 ? {} : {}, {
        m: common_vendor.t(state.data.signInSocialStatus),
        n: ((_a = state.data.rules.discounts) == null ? void 0 : _a.length) > 0
      }, ((_b = state.data.rules.discounts) == null ? void 0 : _b.length) > 0 ? {
        o: common_vendor.f(state.data.rules.discounts, (i, k0, i0) => {
          return {
            a: common_vendor.t(i.full),
            b: common_vendor.t(i.value),
            c: i
          };
        })
      } : {}, {
        p: state.data.rules.is_replenish == "1"
      }, state.data.rules.is_replenish == "1" ? {
        q: common_vendor.t(((_c = state.data.rules.discounts) == null ? void 0 : _c.length) > 0 ? "3" : "2"),
        r: common_vendor.t(state.data.rules.replenish_limit),
        s: common_vendor.t(state.data.rules.replenish_days),
        t: common_vendor.t(state.data.rules.replenish_num)
      } : {}) : !state.data && !state.loading ? {
        w: common_vendor.p({
          icon: "/static/data-empty.png",
          text: "签到活动还未开始"
        })
      } : {}, {
        b: state.data && !state.loading,
        v: !state.data && !state.loading,
        x: common_vendor.t(state.signin.social),
        y: state == null ? void 0 : state.upgradeOrNot
      }, (state == null ? void 0 : state.upgradeOrNot) ? {
        z: common_vendor.t(state == null ? void 0 : state.socialStatusName)
      } : {}, {
        A: common_vendor.o(($event) => onConfirm()),
        B: common_vendor.p({
          show: state.showModel,
          type: "center",
          round: "10",
          isMaskClick: false
        }),
        C: common_vendor.s(_ctx.__cssVars()),
        D: common_vendor.p({
          title: "签到有礼"
        })
      });
    };
  }
};
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-964858d2"], ["__file", "D:/zx/mall-front-app/pages/app/sign.vue"]]);
wx.createPage(MiniProgramPage);
