"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 common_assets = require("../../../common/assets.js");
const containerLoading = () => "../../../components/container-loading.js";
const _sfc_main = {
  components: {
    containerLoading
  },
  setup() {
    const globalData = common_vendor.inject("globalData");
    return {
      globalData
    };
  },
  data() {
    return {
      pageData: {
        page: 1,
        rows: 10,
        keywords: "",
        keywords: "",
        goodsLeaderType: "",
        goodsGetTime: "",
        goodsDevelop: "",
        goodsType: ""
      },
      keywords: "",
      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: "1"
      }, {
        dataName: "法人",
        dataId: "2"
      }, {
        dataName: "非法人组织或其他",
        dataId: "3"
      }],
      selOwner: "",
      msgType: "info",
      msgHint: "",
      msgShow: false,
      isScrolling: false,
      scrollTimer: null,
      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();
    }
  },
  onPageScroll(e) {
    if (this.scrollTimer) {
      clearTimeout(this.scrollTimer);
    }
    if (!this.isScrolling) {
      this.isScrolling = true;
    }
    const timer = setTimeout(() => {
      this.isScrolling = false;
    }, 300);
    this.scrollTimer = timer;
  },
  onPullDownRefresh() {
    this.doRefreshList();
  },
  onReachBottom() {
    this.doLoadMore();
  },
  methods: {
    goodsStatus: common_js_conver.goodsStatus,
    includes: common_js_conver.includes,
    moneyTxt: common_js_conver.moneyTxt,
    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;
        common_vendor.index.__f__("log", "at pages/shop/sellGoods/sellGoods.vue:221", "选择分类:", this.data.selType);
        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.keywords = this.keywords;
      this.pageData.goodsLeaderType = this.selOwner;
      this.pageData.priceRangeStart = this.priceStart;
      this.pageData.priceRangeEnd = this.priceEnd;
      this.pageData.goodsType = this.selType;
      this.getIndexList(true);
    },
    //加载更多
    doLoadMore() {
      if (this.isLoadMore || this.hasMore == "noMore") {
        return;
      }
      this.hasMore = "loading";
      this.isLoadMore = true;
      this.pageData.page = ++this.pageData.page;
      this.getIndexList(false);
    },
    //获取列表
    getIndexList(isRefresh) {
      const _self = this;
      this.listLoading = isRefresh ? "loading" : "";
      common_js_net_shop.Shop.doGetMineSellGoods(_self.pageData).then((res) => {
        common_vendor.index.stopPullDownRefresh();
        common_vendor.index.__f__("log", "at pages/shop/sellGoods/sellGoods.vue:276", 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/sellGoods/sellGoods.vue:288", 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 goods = e.currentTarget.dataset.value;
      if (goods.goodsOrderStatus == "0") {
        common_vendor.index.navigateTo({
          url: "/pages/shop/manageGoods/manageGoods?id=" + goods.goodsId,
          animation: "fade"
        });
      } else {
        this.msgHint = goods.goodsOrderStatus != "4" ? "商品已被买家购买,无法操作" : "商品已经出售";
        this.msgType = "info";
        this.$refs.msg.open();
      }
    },
    //去创建软著商品
    doCreateGoods() {
      common_vendor.index.navigateTo({
        url: "/pages/shop/publishGoods/publishGoods"
      });
    }
  }
};
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 {
    a: common_vendor.o((...args) => $options.doSearch && $options.doSearch(...args)),
    b: common_vendor.o((...args) => $options.inputKeywords && $options.inputKeywords(...args)),
    c: $data.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: common_vendor.f($data.goodsList, (item, index, i0) => {
      return {
        a: index,
        b: item.preImg,
        c: common_vendor.t(item.goodsName),
        d: $options.moneyTxt(8, 14, item.goodsPrice + ""),
        e: common_vendor.t(item.goodsLastTime),
        f: common_vendor.t($options.goodsStatus(item.goodsCheckStatus, item.goodsStatus, item.goodsOrderStatus)),
        g: item
      };
    }),
    j: common_vendor.o((...args) => $options.doDetail && $options.doDetail(...args)),
    k: common_vendor.p({
      status: $data.hasMore
    }),
    l: common_vendor.j({
      "refresh": common_vendor.o($options.doRefreshList)
    }),
    m: common_vendor.p({
      loadingVisible: $data.listLoading
    }),
    n: common_assets._imports_0$4,
    o: common_vendor.n($data.isScrolling ? "create-box-hide" : "create-box-show"),
    p: common_vendor.o((...args) => $options.doCreateGoods && $options.doCreateGoods(...args)),
    q: common_vendor.p({
      type: $data.msgType,
      message: $data.msgHint,
      duration: 2e3
    }),
    r: common_vendor.sr("msg", "3cc64c8c-2"),
    s: common_vendor.p({
      type: "message"
    })
  };
}
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-3cc64c8c"]]);
_sfc_main.__runtimeHooks = 1;
swan.createPage(MiniProgramPage);
//# sourceMappingURL=../../../../.sourcemap/mp-baidu/pages/shop/sellGoods/sellGoods.js.map
