"use strict";
const common_vendor = require("../../../common/vendor.js");
const common_js_net_shop = require("../../../common/js/net/shop.js");
const common_js_net_mainUrl = require("../../../common/js/net/mainUrl.js");
const common_js_conver = require("../../../common/js/conver.js");
const ContainerLoading = () => "../../../components/container-loading.js";
const _sfc_main = {
  components: {
    ContainerLoading
  },
  setup() {
  },
  data() {
    return {
      pageData: {
        page: 1,
        rows: 10,
        keywords: "",
        startTime: "",
        endTime: "",
        orderStatus: ""
      },
      msgShow: false,
      msgHint: "",
      msgType: "error",
      loadingState: "loading",
      listRefreshTrig: false,
      isLoadMore: false,
      hasMore: "more",
      goodsList: [],
      needRefresh: false
    };
  },
  onLoad(options) {
    common_vendor.index.setNavigationBarTitle({
      title: "已购买"
    });
    common_vendor.index.setNavigationBarColor({
      frontColor: "#000000",
      backgroundColor: "#FFFFFF",
      animation: {
        duration: 500,
        timingFunc: "easeIn"
      }
    });
    this.doRefreshList();
  },
  onShow() {
    if (this.needRefresh) {
      this.needRefresh = false;
      this.doRefreshList();
    }
  },
  onPullDownRefresh() {
    this.doRefreshList();
  },
  onReachBottom() {
    this.doLoadMore();
  },
  methods: {
    goodsOrderColor: common_js_conver.goodsOrderColor,
    goodsOrderStatus: common_js_conver.goodsOrderStatus,
    moneyTxt: common_js_conver.moneyTxt,
    inputKeywords(e) {
      this.pageData.keywords = e.detail.value;
    },
    doSearch() {
      common_vendor.index.pageScrollTo({
        scrollTop: 0
      });
      setTimeout(() => {
        this.doRefreshList();
      }, 300);
    },
    doRefreshList() {
      this.listRefreshTrig = true;
      this.loadingState = "loading";
      this.hasMore = "more";
      this.isLoadMore = false;
      this.pageData.page = 1;
      this.doGetMineOrders(true);
    },
    doLoadMore() {
      if (this.isLoadMore || this.hasMore == "noMore") {
        return;
      }
      this.isLoadMore = true;
      this.pageData.page = ++this.pageData.page;
      this.doGetMineOrders(false);
    },
    //获取列表
    doGetMineOrders(isRefresh) {
      const _self = this;
      this.goodsList = isRefresh ? [] : this.goodsList;
      this.loadingState = isRefresh ? "loading" : "";
      common_js_net_shop.Shop.doGetMineOrders(_self.pageData).then((res) => {
        common_vendor.index.__f__("log", "at pages/shop/purchasedGoods/purchasedGoods.vue:161", res);
        common_vendor.index.stopPullDownRefresh();
        var status = res.rows && res.rows.length > 0 ? "success" : "empty";
        const list = _self.addPrefixToPreviewImgs(res.rows);
        _self.loadingState = isRefresh ? status : "";
        _self.goodsList = _self.goodsList.concat(list);
        _self.listRefreshTrig = false;
        _self.isLoadMore = false;
        _self.hasMore = _self.goodsList.length < res.total ? "more" : "noMore";
      }).catch((err) => {
        common_vendor.index.__f__("log", "at pages/shop/purchasedGoods/purchasedGoods.vue:172", "错误", err);
        common_vendor.index.stopPullDownRefresh();
        this.loadingState = "error";
        this.listRefreshTrig = false;
        this.isLoadMore = false;
        this.hasMore = "more";
      });
    },
    //为数据中图片添加前缀
    addPrefixToPreviewImgs(data) {
      const prefix = common_js_net_mainUrl.sImgPrefix;
      return data.map((item) => {
        if (item.goodsDTO && item.goodsDTO != null && item.goodsDTO.goodsPhoto != "") {
          item.goodsDTO.preImg = prefix + item.goodsDTO.goodsPhoto;
        }
        return item;
      });
    },
    //跳转详情
    goDetail(e) {
      const goods = e.currentTarget.dataset.value;
      common_vendor.index.navigateTo({
        url: "/pages/shop/orderDetail/orderDetail?orderId=" + goods.orderId + "&kind=buy"
      });
    }
  }
};
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 common_vendor.e({
    a: common_vendor.o((...args) => $options.doSearch && $options.doSearch(...args)),
    b: common_vendor.o((...args) => $options.inputKeywords && $options.inputKeywords(...args)),
    c: $data.pageData.keywords,
    d: common_vendor.o((...args) => $options.doSearch && $options.doSearch(...args)),
    e: $data.goodsList.length > 0
  }, $data.goodsList.length > 0 ? {
    f: common_vendor.f($data.goodsList, (item, index, i0) => {
      return common_vendor.e({
        a: index,
        b: item.goodsDTO && item.goodsDTO != null
      }, item.goodsDTO && item.goodsDTO != null ? common_vendor.e({
        c: item.goodsDTO.preImg,
        d: item.waitCorrectionCount > 0
      }, item.waitCorrectionCount > 0 ? {
        e: common_vendor.t(item.waitCorrectionCount)
      } : {}, {
        f: common_vendor.t($options.goodsOrderStatus(item.orderStatus)),
        g: common_vendor.n($options.goodsOrderColor(item.orderStatus)),
        h: common_vendor.t(item.goodsDTO.goodsName),
        i: $options.moneyTxt(12, 16, item.payMoney),
        j: common_vendor.t(item.createTime),
        k: common_vendor.t(item.payTime == "" ? "未付款" : item.payTime),
        l: common_vendor.o((...args) => $options.goDetail && $options.goDetail(...args)),
        m: item
      }) : {});
    }),
    g: common_vendor.p({
      status: $data.hasMore
    })
  } : {}, {
    h: common_vendor.j({
      "refresh": common_vendor.o($options.doRefreshList)
    }),
    i: common_vendor.p({
      loadingVisible: $data.loadingState
    })
  });
}
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-15f896aa"]]);
swan.createPage(MiniProgramPage);
//# sourceMappingURL=../../../../.sourcemap/mp-baidu/pages/shop/purchasedGoods/purchasedGoods.js.map
