"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-units");
        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-units", { name: this.name });
      this.name = "";
      this.reload();
    },
    async update(u) {
      await common_http.put("/api/product-units/" + u.id, { name: u.name });
      common_vendor.index.showToast({ title: "已保存", icon: "success" });
    },
    async remove(u) {
      common_vendor.index.showModal({ content: "确定删除该单位？", success: async (r) => {
        if (!r.confirm)
          return;
        await common_http.del("/api/product-units/" + u.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, (u, k0, i0) => {
      return {
        a: u.name,
        b: common_vendor.o(common_vendor.m(($event) => u.name = $event.detail.value, {
          trim: true
        }), u.id),
        c: common_vendor.o(($event) => $options.update(u), u.id),
        d: common_vendor.o(($event) => $options.remove(u), u.id),
        e: u.id
      };
    })
  };
}
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
wx.createPage(MiniProgramPage);
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/product/units.js.map
