"use strict";
const common_vendor = require("../../common/vendor.js");
const common_http = require("../../common/http.js");
const TYPE_MAP = { cash: "现金", bank: "银行", alipay: "支付宝", wechat: "微信", other: "其他" };
const _sfc_main = {
  data() {
    return { accounts: [], mode: "view" };
  },
  async onLoad(q) {
    this.mode = q && q.mode || "view";
    try {
      const res = await common_http.get("/api/accounts");
      this.accounts = Array.isArray(res) ? res : (res == null ? void 0 : res.list) || [];
    } catch (e) {
      common_vendor.index.showToast({ title: "加载失败", icon: "none" });
    }
  },
  methods: {
    select(a) {
      if (this.mode === "pick") {
        const opener = getCurrentPages()[getCurrentPages().length - 2];
        if (opener && opener.$vm) {
          opener.$vm.selectedAccountId = a.id;
          opener.$vm.selectedAccountName = a.name;
        }
        common_vendor.index.navigateBack();
      } else {
        common_vendor.index.navigateTo({ url: `/pages/account/ledger?id=${a.id}` });
      }
    },
    create() {
      common_vendor.index.navigateTo({ url: "/pages/account/form" });
    },
    typeLabel(t) {
      return TYPE_MAP[t] || t;
    }
  }
};
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  return {
    a: common_vendor.f($data.accounts, (a, k0, i0) => {
      var _a;
      return {
        a: common_vendor.t(a.name),
        b: common_vendor.t($options.typeLabel(a.type)),
        c: common_vendor.t(((_a = a.balance) == null ? void 0 : _a.toFixed) ? a.balance.toFixed(2) : a.balance),
        d: a.id,
        e: common_vendor.o(($event) => $options.select(a), a.id)
      };
    }),
    b: common_vendor.o((...args) => $options.create && $options.create(...args))
  };
}
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
wx.createPage(MiniProgramPage);
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/account/select.js.map
