"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 common_assets = require("../../../common/assets.js");
const containerLoadingVue = () => "../../../components/container-loading.js";
const _sfc_main = {
  components: {
    containerLoadingVue
  },
  setup() {
    const globalData = common_vendor.inject("globalData");
    return {
      globalData
    };
  },
  data() {
    return {
      pageData: {
        page: 1,
        rows: 10,
        keywords: "",
        priceRangeStart: "",
        priceRangeEnd: "",
        priceOrder: "",
        goodsGetTime: "",
        goodsDevelop: "",
        goodsType: "",
        //软著类型
        goodsFlag: ""
      },
      keywords: "",
      priceStart: "",
      priceEnd: "",
      isLoadMore: false,
      hasMore: "more",
      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: "",
      isSticky: false,
      msgType: "info",
      msgHint: "",
      msgShow: false,
      needRefresh: 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();
  },
  onShow() {
    if (this.needRefresh) {
      this.needRefresh = false;
      this.doRefreshList();
    }
  },
  onReachBottom() {
    common_vendor.index.__f__("log", "at pages/shop/index/index.vue:197", "触底了");
    this.doLoadMore();
  },
  onPageScroll(e) {
    this.isSticky = e.scrollTop > 155;
  },
  onPullDownRefresh() {
    this.doRefreshList();
  },
  methods: {
    moneyTxt: common_js_conver.moneyTxt,
    includes: common_js_conver.includes,
    inputKeywords(e) {
      this.keywords = e.detail.value;
    },
    doSearch() {
      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.pageData.page = 1;
      this.pageData.keywords = this.keywords;
      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;
      _self.listLoading = isRefresh ? "loading" : "";
      common_js_net_shop.Shop.doGetIndexList(_self.pageData).then((res) => {
        common_vendor.index.stopPullDownRefresh();
        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();
        _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;
      });
    },
    //我要买
    doBuy() {
      common_vendor.index.navigateTo({
        url: "/pages/shop/buyGoods/buyGoods"
      });
    },
    //已购买
    doPurchase() {
      common_vendor.index.navigateTo({
        url: "/pages/shop/purchasedGoods/purchasedGoods"
      });
    },
    //我要卖
    doSell() {
      common_vendor.index.navigateTo({
        url: "/pages/shop/sellGoods/sellGoods"
      });
    },
    //已销售
    doBetray() {
      common_vendor.index.navigateTo({
        url: "/pages/shop/soldGoods/soldGoods"
      });
    },
    //详情
    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_containerLoadingVue = common_vendor.resolveComponent("containerLoadingVue");
  (_easycom_uni_load_more2 + _component_containerLoadingVue)();
}
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: $data.keywords,
    b: common_vendor.o((...args) => $options.doSearch && $options.doSearch(...args)),
    c: common_vendor.o((...args) => $options.inputKeywords && $options.inputKeywords(...args)),
    d: common_vendor.o((...args) => $options.doSearch && $options.doSearch(...args)),
    e: "url(" + $data.imgAssets + "/bg_shop_title.png)",
    f: common_assets._imports_0$3,
    g: common_vendor.o((...args) => $options.doBuy && $options.doBuy(...args)),
    h: common_assets._imports_1$1,
    i: common_vendor.o((...args) => $options.doPurchase && $options.doPurchase(...args)),
    j: common_assets._imports_2,
    k: common_vendor.o((...args) => $options.doSell && $options.doSell(...args)),
    l: common_assets._imports_3,
    m: common_vendor.o((...args) => $options.doBetray && $options.doBetray(...args)),
    n: 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
      };
    }),
    o: common_vendor.o((...args) => $options.bindChooseType && $options.bindChooseType(...args)),
    p: 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
      };
    }),
    q: common_vendor.o((...args) => $options.bindChooseOwner && $options.bindChooseOwner(...args)),
    r: common_vendor.n($data.isSticky ? "sticky" : ""),
    s: $data.goodsList.length > 0
  }, $data.goodsList.length > 0 ? {
    t: 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
      });
    }),
    v: common_vendor.o((...args) => $options.doDetail && $options.doDetail(...args))
  } : {}, {
    w: common_vendor.p({
      status: $data.hasMore
    }),
    x: common_vendor.p({
      loadingVisible: $data.listLoading
    })
  });
}
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-f89a6c3d"]]);
_sfc_main.__runtimeHooks = 1;
swan.createPage(MiniProgramPage);
//# sourceMappingURL=../../../../.sourcemap/mp-baidu/pages/shop/index/index.js.map
