"use strict";
const common_vendor = require("../../../../common/vendor.js");
const common_js_net_projectApi = require("../../../../common/js/net/projectApi.js");
const common_js_conver = require("../../../../common/js/conver.js");
const ContainerLoading = () => "../../../../components/container-loading.js";
const _sfc_main = {
  components: {
    ContainerLoading
  },
  data() {
    return {
      currentStatus: 1,
      couponsList: [],
      //订单列表
      pageData: {
        page: 1,
        rows: 10,
        isEffective: "",
        isUsed: ""
      },
      //检索参数
      loadingState: "loading",
      //加载状态
      listRefreshTrig: false,
      //list刷新状态
      isLoadMore: false,
      //加载更多的状态
      hasMore: true,
      //是否有更多数据
      keywords: "",
      //搜索关键字
      loadMore: "more"
    };
  },
  onLoad() {
    common_vendor.index.setNavigationBarTitle({
      title: "我的优惠卷"
    });
    common_vendor.index.setNavigationBarColor({
      frontColor: "#000000",
      // 必写项，字体颜色仅支持#ffffff和#000000
      backgroundColor: "#F0F0F0",
      // 传递的颜色值，仅支持十六进制颜色
      animation: {
        // 可选项
        duration: 500,
        timingFunc: "easeIn"
      }
    });
    this.doRefreshList();
  },
  onPullDownRefresh() {
    this.doRefreshList();
    common_vendor.index.stopPullDownRefresh();
  },
  methods: {
    boderStyle: common_js_conver.boderStyle,
    fontColor: common_js_conver.fontColor,
    timeSplit: common_js_conver.timeSplit,
    //tab切换
    doChangeStatus(e) {
      const value = e.currentTarget.dataset.value;
      this.currentStatus = value;
      this.doRefreshList();
    },
    //获取我的优惠卷
    doGetMyCoupons(isRefresh) {
      const _self = this;
      _self.couponsList = isRefresh ? [] : _self.couponsList;
      _self.loadingState = isRefresh ? "loading" : "";
      common_js_net_projectApi.ProApi.doGetCouponseList(_self.pageData).then((res) => {
        var status = "success";
        status = res.rows && res.rows.length > 0 ? "success" : "empty";
        _self.loadingState = isRefresh ? status : "";
        _self.couponsList = _self.couponsList.concat(res.rows);
        _self.listRefreshTrig = false;
        _self.isLoadMore = false;
        _self.hasMore = _self.couponsList.length < res.total;
        _self.loadMore = _self.hasMore ? "more" : "noMore";
      }).catch((err) => {
        _self.loadingState = "error";
        _self.listRefreshTrig = false;
        _self.isLoadMore = false;
        _self.hasMore = true;
        _self.loadMore = "more";
      });
    },
    //下拉刷新
    doRefreshList() {
      const _self = this;
      var isEffective = "";
      var isUsed = "";
      if (_self.currentStatus == 1) {
        isEffective = 1;
        isUsed = 0;
      } else if (_self.currentStatus == 2) {
        isEffective = "";
        isUsed = 1;
      } else {
        isEffective = 0;
        isUsed = 0;
      }
      _self.listRefreshTrig = true;
      _self.loadingState = "loading";
      _self.hasMore = true;
      _self.pageData.page = 1;
      _self.pageData.isEffective = isEffective;
      _self.pageData.isUsed = isUsed;
      _self.isLoadMore = false;
      _self.loadMore = "more";
      _self.doGetMyCoupons(true);
    },
    //加载更多
    doLoadMore() {
      const _self = this;
      if (_self.isLoadMore || _self.hasMore == "noMore") {
        return;
      }
      var isEffective = "";
      var isUsed = "";
      if (_self.currentStatus == 1) {
        isEffective = 1;
        isUsed = 0;
      } else if (_self.currentStatus == 2) {
        isEffective = "";
        isUsed = 1;
      } else {
        isEffective = 0;
        isUsed = 0;
      }
      _self.isLoadMore = true;
      _self.hasMore = "loading";
      _self.pageData.page = ++_self.pageData.page;
      _self.pageData.isEffective = isEffective;
      _self.pageData.isUsed = isUsed;
      _self.doGetMyCoupons(false);
    },
    //显示使用规则
    showRule() {
      const id = "89c4ca41-a44e-4ae2-bad3-6fa6536dd453";
      wx.navigateTo({
        url: "/pages/common/rule/rule?id=" + id
      });
    }
  }
};
if (!Array) {
  const _easycom_uni_load_more2 = common_vendor.resolveComponent("uni-load-more");
  const _component_ContainerLoading = common_vendor.resolveComponent("ContainerLoading");
  (_easycom_uni_load_more2 + _component_ContainerLoading)();
}
const _easycom_uni_load_more = () => "../../../../uni_modules/uni-load-more/components/uni-load-more/uni-load-more.js";
if (!Math) {
  _easycom_uni_load_more();
}
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  return {
    a: common_vendor.n($data.currentStatus == 1 ? "border-select" : "border-normal"),
    b: common_vendor.o((...args) => $options.doChangeStatus && $options.doChangeStatus(...args)),
    c: common_vendor.n($data.currentStatus == 1 ? "btn-select" : "btn-normal"),
    d: common_vendor.n($data.currentStatus == 2 ? "border-select" : "border-normal"),
    e: common_vendor.o((...args) => $options.doChangeStatus && $options.doChangeStatus(...args)),
    f: common_vendor.n($data.currentStatus == 2 ? "btn-select" : "btn-normal"),
    g: common_vendor.n($data.currentStatus == 3 ? "border-select" : "border-normal"),
    h: common_vendor.o((...args) => $options.doChangeStatus && $options.doChangeStatus(...args)),
    i: common_vendor.n($data.currentStatus == 3 ? "btn-select" : "btn-normal"),
    j: common_vendor.f($data.couponsList, (item, index, i0) => {
      return {
        a: index,
        b: common_vendor.t(item.coupon.amount / 100),
        c: common_vendor.t(item.coupon.title),
        d: common_vendor.t($options.timeSplit(item.coupon.useGmtStart)),
        e: common_vendor.t($options.timeSplit(item.coupon.useGmtEnd))
      };
    }),
    k: common_vendor.n($options.fontColor($data.currentStatus)),
    l: common_vendor.o((...args) => $options.showRule && $options.showRule(...args)),
    m: common_vendor.n($options.boderStyle($data.currentStatus)),
    n: common_vendor.p({
      status: $data.loadMore
    }),
    o: common_vendor.o((...args) => $options.doLoadMore && $options.doLoadMore(...args)),
    p: common_vendor.p({
      loadingVisible: $data.loadingState
    })
  };
}
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
swan.createPage(MiniProgramPage);
//# sourceMappingURL=../../../../../.sourcemap/mp-baidu/pages/mine/mineAccount/mineCoupons/mineCoupons.js.map
