"use strict";
const common_vendor = require("../../../common/vendor.js");
const common_js_net_mainUrl = require("../../../common/js/net/mainUrl.js");
const common_js_conver = require("../../../common/js/conver.js");
const common_js_net_shop = require("../../../common/js/net/shop.js");
const ContainerLoading = () => "../../../components/container-loading.js";
const _sfc_main = {
  components: {
    ContainerLoading
  },
  setup() {
    const globalData = common_vendor.inject("globalData");
    return {
      globalData
    };
  },
  data() {
    return {
      msgType: "info",
      msgHint: "",
      pageData: {
        page: 1,
        rows: 12,
        keywords: "",
        priceRangeStart: "",
        priceRangeEnd: "",
        priceOrder: "",
        goodsGetTime: "",
        goodsDevelop: "",
        goodsType: "",
        //软著类型
        goodsFlag: ""
      },
      priceStart: "",
      priceEnd: "",
      isLoadMore: false,
      hasMore: true,
      listLoading: "loading",
      listRefreshTrig: false,
      goodsList: [],
      imgPrefix: common_js_net_mainUrl.sImgPrefix,
      localAssets: this.globalData.localAssets,
      imgAssets: this.globalData.imgAssetsUrl,
      typeList: [],
      selType: "",
      ownerList: [{
        dataName: "从高到低",
        dataId: "DESC"
      }, {
        dataName: "从低到高",
        dataId: "ASC"
      }],
      selOwner: "",
      msgType: "info",
      msgHint: "",
      msgShow: false
    };
  },
  onLoad(options) {
    common_vendor.index.setNavigationBarTitle({
      title: "我要买"
    });
    common_vendor.index.setNavigationBarColor({
      frontColor: "#000000",
      backgroundColor: "#FFFFFF",
      animation: {
        duration: 500,
        timingFunc: "easeIn"
      }
    });
    this.doGetDic();
    this.doRefreshList();
  },
  onPullDownRefresh() {
    this.doRefreshList();
  },
  onReachBottom() {
    this.doLoadMore();
  },
  methods: {
    moneyTxt: common_js_conver.moneyTxt,
    includes: common_js_conver.includes,
    inputKeywords(e) {
      this.pageData.keywords = e.detail.value;
    },
    doSearch() {
      this.goodsList = [];
      this.doRefreshList();
    },
    bindChooseType(e) {
      common_vendor.index.pageScrollTo({
        scrollTop: 0
      });
      setTimeout(() => {
        const item = e.currentTarget.dataset.item;
        let newSelType = this.selType;
        const typeArr = newSelType ? newSelType.split(",") : [];
        if (typeArr.includes(item.dataId)) {
          const index = typeArr.indexOf(item.dataId);
          typeArr.splice(index, 1);
        } else {
          typeArr.push(item.dataId);
        }
        newSelType = typeArr.join(",");
        this.selType = newSelType;
        this.doRefreshList();
      }, 500);
    },
    bindChooseOwner(e) {
      const item = e.currentTarget.dataset.item;
      this.selOwner = this.selOwner == item.dataId ? "" : item.dataId;
      this.doRefreshList();
    },
    doGetDic() {
      common_vendor.index.showLoading({
        title: "加载中..."
      });
      const that = this;
      common_js_net_shop.Shop.doGetGoodsDic("0b00884a-f7a2-425f-93e5-599fbaad4bde").then((res) => {
        common_vendor.index.hideLoading();
        that.typeList = res;
      }).catch((err) => {
        common_vendor.index.hideLoading();
      });
    },
    //刷新
    doRefreshList() {
      this.goodsList = [];
      this.isLoadMore = false;
      this.hasMore = "more";
      this.listRefreshTrig = true;
      this.pageData.page = 1;
      this.pageData.priceOrder = this.selOwner;
      this.pageData.priceRangeStart = this.priceStart;
      this.pageData.priceRangeEnd = this.priceEnd;
      this.pageData.goodsType = this.selType;
      this.getIndexList(true);
    },
    //加载更多
    doLoadMore() {
      const _self = this;
      if (_self.isLoadMore || _self.hasMore == "noMore") {
        return;
      }
      this.hasMore = "loading";
      this.isLoadMore = true;
      this.pageData.page = ++this.pageData.page;
      _self.getIndexList(false);
    },
    //获取列表
    getIndexList(isRefresh) {
      const _self = this;
      this.listLoading = isRefresh ? "loading" : "";
      common_js_net_shop.Shop.doGetIndexList(_self.pageData).then((res) => {
        common_vendor.index.stopPullDownRefresh();
        common_vendor.index.__f__("log", "at pages/shop/buyGoods/buyGoods.vue:237", res);
        var status = "success";
        status = res.rows && res.rows.length > 0 ? "success" : "empty";
        const list = _self.addPrefixToPreviewImgs(res.rows);
        _self.listLoading = 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.stopPullDownRefresh();
        common_vendor.index.__f__("log", "at pages/shop/buyGoods/buyGoods.vue:249", err);
        _self.listLoading = "error";
        _self.listRefreshTrig = false;
        _self.isLoadMore = false;
        _self.hasMore = "more";
      });
    },
    //为数据中图片添加前缀
    addPrefixToPreviewImgs(data) {
      const prefix = this.imgPrefix;
      return data.map((item) => {
        if (item.goodsPhoto && item.goodsPhoto != "") {
          item.preImg = prefix + item.goodsPhoto;
        }
        return item;
      });
    },
    //详情
    doDetail(e) {
      const id = e.currentTarget.dataset.value;
      common_vendor.index.navigateTo({
        url: "/pages/shop/goodsDetail/goodsDetail?id=" + id,
        animation: "fade"
      });
    }
  }
};
if (!Array) {
  const _easycom_uni_load_more2 = common_vendor.resolveComponent("uni-load-more");
  const _component_ContainerLoading = common_vendor.resolveComponent("ContainerLoading");
  const _easycom_uni_popup_message2 = common_vendor.resolveComponent("uni-popup-message");
  const _easycom_uni_popup2 = common_vendor.resolveComponent("uni-popup");
  (_easycom_uni_load_more2 + _component_ContainerLoading + _easycom_uni_popup_message2 + _easycom_uni_popup2)();
}
const _easycom_uni_load_more = () => "../../../uni_modules/uni-load-more/components/uni-load-more/uni-load-more.js";
const _easycom_uni_popup_message = () => "../../../uni_modules/uni-popup/components/uni-popup-message/uni-popup-message.js";
const _easycom_uni_popup = () => "../../../uni_modules/uni-popup/components/uni-popup/uni-popup.js";
if (!Math) {
  (_easycom_uni_load_more + _easycom_uni_popup_message + _easycom_uni_popup)();
}
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: common_vendor.f($data.typeList, (item, index, i0) => {
      return {
        a: index,
        b: common_vendor.t(item.dataName),
        c: common_vendor.n($options.includes($data.selType, item.dataId) ? "tab-select" : "tab-normal"),
        d: item
      };
    }),
    f: common_vendor.o((...args) => $options.bindChooseType && $options.bindChooseType(...args)),
    g: common_vendor.f($data.ownerList, (item, index, i0) => {
      return {
        a: index,
        b: common_vendor.t(item.dataName),
        c: common_vendor.n($data.selOwner == item.dataId ? "tab-select" : "tab-normal"),
        d: item
      };
    }),
    h: common_vendor.o((...args) => $options.bindChooseOwner && $options.bindChooseOwner(...args)),
    i: $data.goodsList.length > 0
  }, $data.goodsList.length > 0 ? {
    j: common_vendor.f($data.goodsList, (item, index, i0) => {
      return common_vendor.e({
        a: index,
        b: item.preImg,
        c: common_vendor.t(item.goodsName),
        d: $options.moneyTxt(8, 14, item.goodsOpenPrice),
        e: common_vendor.t(item.goodsLastTime),
        f: $options.includes(item.goodsFlag, "特价")
      }, $options.includes(item.goodsFlag, "特价") ? {} : {}, {
        g: item.goodsId
      });
    }),
    k: common_vendor.o((...args) => $options.doDetail && $options.doDetail(...args)),
    l: common_vendor.p({
      status: $data.hasMore
    })
  } : {}, {
    m: common_vendor.j({
      "refresh": common_vendor.o($options.doRefreshList)
    }),
    n: common_vendor.p({
      loadingVisible: $data.listLoading
    }),
    o: common_vendor.p({
      type: $data.msgType,
      message: $data.msgHint,
      duration: 2e3
    }),
    p: common_vendor.sr("msg", "5615517f-2"),
    q: common_vendor.p({
      type: "message"
    })
  });
}
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-5615517f"]]);
swan.createPage(MiniProgramPage);
//# sourceMappingURL=../../../../.sourcemap/mp-baidu/pages/shop/buyGoods/buyGoods.js.map
