"use strict";
const common_vendor = require("../../common/vendor.js");
const common_http = require("../../common/http.js");
const _sfc_main = {
  data() {
    return { kw: "", products: [] };
  },
  onLoad() {
    this.search();
  },
  methods: {
    async search() {
      try {
        const res = await common_http.get("/api/products", { kw: this.kw, page: 1, size: 50 });
        this.products = Array.isArray(res == null ? void 0 : res.list) ? res.list : Array.isArray(res) ? res : [];
      } catch (e) {
        common_vendor.index.showToast({ title: "加载失败", icon: "none" });
      }
    },
    select(p) {
      const opener = getCurrentPages()[getCurrentPages().length - 2];
      if (opener && opener.$vm && opener.$vm.items) {
        const initPrice = Number(p.retailPrice != null ? p.retailPrice : p.price || 0);
        opener.$vm.items.push({ productId: p.id, productName: p.name, quantity: 1, unitPrice: initPrice, _autoPrice: true });
      }
      common_vendor.index.navigateBack();
    }
  }
};
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  return {
    a: common_vendor.o((...args) => $options.search && $options.search(...args)),
    b: $data.kw,
    c: common_vendor.o(($event) => $data.kw = $event.detail.value),
    d: common_vendor.o((...args) => $options.search && $options.search(...args)),
    e: common_vendor.f($data.products, (p, k0, i0) => {
      return {
        a: common_vendor.t(p.name),
        b: common_vendor.t((p.brand || "") + " " + (p.model || "") + " " + (p.spec || "")),
        c: common_vendor.t(p.stock ?? 0),
        d: p.id,
        e: common_vendor.o(($event) => $options.select(p), p.id)
      };
    })
  };
}
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
wx.createPage(MiniProgramPage);
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/product/select.js.map
