"use strict";
const common_vendor = require("../../common/vendor.js");
const common_http = require("../../common/http.js");
const _sfc_main = {
  data() {
    return { name: "", list: [] };
  },
  onLoad() {
    this.reload();
  },
  methods: {
    async reload() {
      try {
        const res = await common_http.get("/api/product-categories");
        this.list = Array.isArray(res == null ? void 0 : res.list) ? res.list : Array.isArray(res) ? res : [];
      } catch (_) {
      }
    },
    async create() {
      if (!this.name)
        return;
      await common_http.post("/api/product-categories", { name: this.name });
      this.name = "";
      this.reload();
    },
    async update(c) {
      await common_http.put("/api/product-categories/" + c.id, { name: c.name });
      common_vendor.index.showToast({ title: "已保存", icon: "success" });
    },
    async remove(c) {
      common_vendor.index.showModal({ content: "确定删除该类别？", success: async (r) => {
        if (!r.confirm)
          return;
        await common_http.del("/api/product-categories/" + c.id);
        this.reload();
      } });
    }
  }
};
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  return {
    a: $data.name,
    b: common_vendor.o(common_vendor.m(($event) => $data.name = $event.detail.value, {
      trim: true
    })),
    c: common_vendor.o((...args) => $options.create && $options.create(...args)),
    d: common_vendor.f($data.list, (c, k0, i0) => {
      return {
        a: c.name,
        b: common_vendor.o(common_vendor.m(($event) => c.name = $event.detail.value, {
          trim: true
        }), c.id),
        c: common_vendor.o(($event) => $options.update(c), c.id),
        d: common_vendor.o(($event) => $options.remove(c), c.id),
        e: c.id
      };
    })
  };
}
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
wx.createPage(MiniProgramPage);
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/product/categories.js.map
