Files
2025-09-27 22:57:59 +08:00

90 lines
3.6 KiB
JavaScript

"use strict";
const common_vendor = require("../../common/vendor.js");
const common_http = require("../../common/http.js");
const _sfc_main = {
data() {
return {
id: null,
form: { name: "", priceLevel: "retail", contactName: "", mobile: "", phone: "", address: "", arOpening: 0, remark: "" },
priceLevels: ["零售价", "批发价", "大单报价"],
priceLabels: ["零售价", "批发价", "大单报价"],
priceIdx: 0
};
},
onLoad(query) {
if (query && query.id) {
this.id = Number(query.id);
this.load();
}
},
methods: {
onPriceChange(e) {
this.priceIdx = Number(e.detail.value);
this.form.priceLevel = this.priceLevels[this.priceIdx];
},
async load() {
if (!this.id)
return;
try {
const d = await common_http.get(`/api/customers/${this.id}`);
this.form = {
name: (d == null ? void 0 : d.name) || "",
priceLevel: (d == null ? void 0 : d.priceLevel) || "零售价",
contactName: (d == null ? void 0 : d.contactName) || "",
mobile: (d == null ? void 0 : d.mobile) || "",
phone: (d == null ? void 0 : d.phone) || "",
address: (d == null ? void 0 : d.address) || "",
arOpening: Number((d == null ? void 0 : d.arOpening) || 0),
remark: (d == null ? void 0 : d.remark) || ""
};
const idx = this.priceLevels.indexOf(this.form.priceLevel || "零售价");
this.priceIdx = idx >= 0 ? idx : 0;
} catch (e) {
common_vendor.index.showToast({ title: (e == null ? void 0 : e.message) || "加载失败", icon: "none" });
}
},
async save() {
if (!this.form.name)
return common_vendor.index.showToast({ title: "请填写客户名称", icon: "none" });
try {
if (this.id)
await common_http.put(`/api/customers/${this.id}`, this.form);
else
await common_http.post("/api/customers", this.form);
common_vendor.index.showToast({ title: "保存成功", icon: "success" });
setTimeout(() => common_vendor.index.navigateBack(), 500);
} catch (e) {
common_vendor.index.showToast({ title: (e == null ? void 0 : e.message) || "保存失败", icon: "none" });
}
}
}
};
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
return {
a: $data.form.name,
b: common_vendor.o(($event) => $data.form.name = $event.detail.value),
c: common_vendor.t($data.priceLabels[$data.priceIdx]),
d: $data.priceLabels,
e: $data.priceIdx,
f: common_vendor.o((...args) => $options.onPriceChange && $options.onPriceChange(...args)),
g: $data.form.contactName,
h: common_vendor.o(($event) => $data.form.contactName = $event.detail.value),
i: $data.form.mobile,
j: common_vendor.o(($event) => $data.form.mobile = $event.detail.value),
k: $data.form.phone,
l: common_vendor.o(($event) => $data.form.phone = $event.detail.value),
m: $data.form.address,
n: common_vendor.o(($event) => $data.form.address = $event.detail.value),
o: $data.form.arOpening,
p: common_vendor.o(common_vendor.m(($event) => $data.form.arOpening = $event.detail.value, {
number: true
})),
q: $data.form.remark,
r: common_vendor.o(($event) => $data.form.remark = $event.detail.value),
s: common_vendor.o((...args) => $options.save && $options.save(...args))
};
}
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
wx.createPage(MiniProgramPage);
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/customer/form.js.map