"use strict";
const common_vendor = require("../../common/vendor.js");
const sheep_index = require("../../sheep/index.js");
const sheep_util_index = require("../../sheep/util/index.js");
const sheep_api_promotion_coupon = require("../../sheep/api/promotion/coupon.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/api/member/signin.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/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_su_tabs2 = common_vendor.resolveComponent("su-tabs");
  const _easycom_su_sticky2 = common_vendor.resolveComponent("su-sticky");
  const _easycom_s_empty2 = common_vendor.resolveComponent("s-empty");
  const _easycom_s_coupon_list2 = common_vendor.resolveComponent("s-coupon-list");
  const _easycom_uni_load_more2 = common_vendor.resolveComponent("uni-load-more");
  const _easycom_s_layout2 = common_vendor.resolveComponent("s-layout");
  (_easycom_su_tabs2 + _easycom_su_sticky2 + _easycom_s_empty2 + _easycom_s_coupon_list2 + _easycom_uni_load_more2 + _easycom_s_layout2)();
}
const _easycom_su_tabs = () => "../../sheep/ui/su-tabs/su-tabs.js";
const _easycom_su_sticky = () => "../../sheep/ui/su-sticky/su-sticky.js";
const _easycom_s_empty = () => "../../sheep/components/s-empty/s-empty.js";
const _easycom_s_coupon_list = () => "../../sheep/components/s-coupon-list/s-coupon-list.js";
const _easycom_uni_load_more = () => "../../uni_modules/uni-load-more/components/uni-load-more/uni-load-more.js";
const _easycom_s_layout = () => "../../sheep/components/s-layout/s-layout.js";
if (!Math) {
  (_easycom_su_tabs + _easycom_su_sticky + _easycom_s_empty + _easycom_s_coupon_list + _easycom_uni_load_more + _easycom_s_layout)();
}
const _sfc_main = {
  __name: "list",
  setup(__props) {
    const state = common_vendor.reactive({
      currentTab: 0,
      // 当前 tab
      type: "1",
      pagination: {
        list: [],
        total: 0,
        pageNo: 1,
        pageSize: 5
      },
      loadStatus: ""
    });
    const tabMaps = [
      {
        name: "领券中心",
        value: "all"
      },
      {
        name: "已领取",
        value: "1"
      },
      {
        name: "已使用",
        value: "2"
      },
      {
        name: "已失效",
        value: "3"
      }
    ];
    function onTabsChange(e) {
      state.currentTab = e.index;
      state.type = e.value;
      sheep_util_index.resetPagination(state.pagination);
      if (state.currentTab === 0) {
        getData();
      } else {
        getCoupon();
      }
    }
    async function getData() {
      state.loadStatus = "loading";
      const { data, code } = await sheep_api_promotion_coupon.CouponApi.getCouponTemplatePage({
        pageNo: state.pagination.pageNo,
        pageSize: state.pagination.pageSize
      });
      if (code !== 0) {
        return;
      }
      state.pagination.list = common_vendor._.concat(state.pagination.list, data.list);
      state.pagination.total = data.total;
      state.loadStatus = state.pagination.list.length < state.pagination.total ? "more" : "noMore";
    }
    async function getCoupon() {
      state.loadStatus = "loading";
      const { data, code } = await sheep_api_promotion_coupon.CouponApi.getCouponPage({
        pageNo: state.pagination.pageNo,
        pageSize: state.pagination.pageSize,
        status: state.type
      });
      if (code !== 0) {
        return;
      }
      state.pagination.list = common_vendor._.concat(state.pagination.list, data.list);
      state.pagination.total = data.total;
      state.loadStatus = state.pagination.list.length < state.pagination.total ? "more" : "noMore";
    }
    async function getBuy(id) {
      const { code } = await sheep_api_promotion_coupon.CouponApi.takeCoupon(id);
      if (code !== 0) {
        return;
      }
      common_vendor.index.showToast({
        title: "领取成功"
      });
      setTimeout(() => {
        sheep_util_index.resetPagination(state.pagination);
        getData();
      }, 1e3);
    }
    function loadMore() {
      if (state.loadStatus === "noMore") {
        return;
      }
      state.pagination.pageNo++;
      if (state.currentTab === 0) {
        getData();
      } else {
        getCoupon();
      }
    }
    common_vendor.onLoad((Option) => {
      if (Option.type === "all" || !Option.type) {
        getData();
      } else {
        Option.type === "geted" ? state.currentTab = 1 : Option.type === "used" ? state.currentTab = 2 : state.currentTab = 3;
        state.type = state.currentTab;
        getCoupon();
      }
    });
    common_vendor.onReachBottom(() => {
      loadMore();
    });
    return (_ctx, _cache) => {
      return common_vendor.e({
        a: common_vendor.o(onTabsChange),
        b: common_vendor.p({
          list: tabMaps,
          scrollable: false,
          current: state.currentTab
        }),
        c: common_vendor.p({
          bgColor: "#fff"
        }),
        d: state.pagination.total === 0
      }, state.pagination.total === 0 ? {
        e: common_vendor.p({
          icon: "/static/coupon-empty.png",
          text: "暂无优惠券"
        })
      } : {}, {
        f: state.currentTab === 0
      }, state.currentTab === 0 ? {
        g: common_vendor.f(state.pagination.list, (item, k0, i0) => {
          return {
            a: common_vendor.t(item.canTake ? "立即领取" : "已领取"),
            b: common_vendor.n(!item.canTake ? "border-btn" : ""),
            c: common_vendor.o(($event) => getBuy(item.id), item.id),
            d: !item.canTake,
            e: common_vendor.o(($event) => common_vendor.unref(sheep_index.sheep).$router.go("/pages/coupon/detail", {
              id: item.id
            }), item.id),
            f: "019d569f-4-" + i0 + ",019d569f-0",
            g: common_vendor.p({
              data: item
            }),
            h: item.id
          };
        })
      } : {
        h: common_vendor.f(state.pagination.list, (item, k0, i0) => {
          return {
            a: common_vendor.t(item.status === 1 ? "立即使用" : item.status === 2 ? "已使用" : "已过期"),
            b: common_vendor.n(item.status !== 1 ? "disabled-btn" : ""),
            c: item.status !== 1,
            d: common_vendor.o(($event) => common_vendor.unref(sheep_index.sheep).$router.go("/pages/coupon/detail", {
              couponId: item.id
            }), item.id),
            e: common_vendor.o(($event) => common_vendor.unref(sheep_index.sheep).$router.go("/pages/coupon/detail", {
              couponId: item.id
            }), item.id),
            f: "019d569f-5-" + i0 + ",019d569f-0",
            g: common_vendor.p({
              data: item,
              type: "user"
            }),
            h: item.id
          };
        })
      }, {
        i: state.pagination.total > 0
      }, state.pagination.total > 0 ? {
        j: common_vendor.o(loadMore),
        k: common_vendor.p({
          status: state.loadStatus,
          ["content-text"]: {
            contentdown: "上拉加载更多"
          }
        })
      } : {}, {
        l: common_vendor.p({
          title: "优惠券",
          bgStyle: {
            color: "#f2f2f2"
          }
        })
      });
    };
  }
};
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-019d569f"], ["__file", "D:/zx/mall-front-app/pages/coupon/list.vue"]]);
wx.createPage(MiniProgramPage);
