9.18/3
This commit is contained in:
@@ -22,6 +22,9 @@ const _sfc_main = {
|
||||
remark: ""
|
||||
},
|
||||
customerName: "",
|
||||
customerPriceLevel: "零售价",
|
||||
_lastCustomerId: null,
|
||||
_priceCache: {},
|
||||
supplierName: "",
|
||||
items: [],
|
||||
activeCategory: "sale_income",
|
||||
@@ -64,7 +67,70 @@ const _sfc_main = {
|
||||
return Number(p.cash || 0) + Number(p.bank || 0) + Number(p.wechat || 0);
|
||||
}
|
||||
},
|
||||
onShow() {
|
||||
if (this.biz === "sale") {
|
||||
if (this.order.customerId && this.order.customerId !== this._lastCustomerId) {
|
||||
this.loadCustomerLevel(this.order.customerId).then(() => {
|
||||
this._lastCustomerId = this.order.customerId;
|
||||
for (const it of this.items) {
|
||||
if (it && (it._autoPrice || !it.unitPrice))
|
||||
this.autoPriceItem(it);
|
||||
}
|
||||
});
|
||||
}
|
||||
for (const it of this.items) {
|
||||
if (it && !it.unitPrice)
|
||||
this.autoPriceItem(it);
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
async loadCustomerLevel(customerId) {
|
||||
try {
|
||||
const d = await common_http.get(`/api/customers/${customerId}`);
|
||||
this.customerPriceLevel = d && d.priceLevel ? d.priceLevel : "零售价";
|
||||
} catch (e) {
|
||||
this.customerPriceLevel = "零售价";
|
||||
}
|
||||
},
|
||||
priceFieldForLevel() {
|
||||
const lvl = this.customerPriceLevel || "零售价";
|
||||
if (lvl === "批发价")
|
||||
return "wholesalePrice";
|
||||
if (lvl === "大单报价")
|
||||
return "bigClientPrice";
|
||||
return "retailPrice";
|
||||
},
|
||||
async autoPriceItem(it) {
|
||||
if (this.biz !== "sale")
|
||||
return;
|
||||
if (!it || !it.productId)
|
||||
return;
|
||||
const pid = it.productId;
|
||||
let detail = this._priceCache[pid];
|
||||
if (!detail) {
|
||||
try {
|
||||
detail = await common_http.get(`/api/products/${pid}`);
|
||||
this._priceCache[pid] = detail;
|
||||
} catch (e) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
const field = this.priceFieldForLevel();
|
||||
let price = Number(detail && detail[field] != null ? detail[field] : 0);
|
||||
if (!price && field !== "retailPrice") {
|
||||
price = Number(detail && detail.retailPrice != null ? detail.retailPrice : 0);
|
||||
}
|
||||
it.unitPrice = price;
|
||||
it._autoPrice = true;
|
||||
this.recalc();
|
||||
},
|
||||
onPriceInput(it) {
|
||||
if (it) {
|
||||
it._autoPrice = false;
|
||||
this.recalc();
|
||||
}
|
||||
},
|
||||
switchBiz(type) {
|
||||
this.biz = type;
|
||||
},
|
||||
@@ -98,6 +164,17 @@ const _sfc_main = {
|
||||
const isSaleOrPurchase = this.biz === "sale" || this.biz === "purchase";
|
||||
const isCollectOrPay = this.biz === "sale" && this.saleType === "collect" || this.biz === "purchase" && this.purchaseType === "pay";
|
||||
const saleTypeValue = this.biz === "sale" ? "sale." + this.saleType : "purchase." + this.purchaseType;
|
||||
if (isSaleOrPurchase && !isCollectOrPay) {
|
||||
if (!this.items.length) {
|
||||
common_vendor.index.showToast({ title: "请先选择商品", icon: "none" });
|
||||
return;
|
||||
}
|
||||
const invalid = this.items.find((it) => !it.productId || Number(it.quantity || 0) <= 0);
|
||||
if (invalid) {
|
||||
common_vendor.index.showToast({ title: "数量需大于0", icon: "none" });
|
||||
return;
|
||||
}
|
||||
}
|
||||
const payload = isSaleOrPurchase ? isCollectOrPay ? [
|
||||
{ method: "cash", amount: Number(this.payments.cash || 0) },
|
||||
{ method: "bank", amount: Number(this.payments.bank || 0) },
|
||||
@@ -244,7 +321,7 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
||||
c: it.quantity,
|
||||
d: common_vendor.o([common_vendor.m(($event) => it.unitPrice = $event.detail.value, {
|
||||
number: true
|
||||
}), ($event) => $options.recalc()], idx),
|
||||
}), ($event) => $options.onPriceInput(it)], idx),
|
||||
e: it.unitPrice,
|
||||
f: common_vendor.t((Number(it.quantity) * Number(it.unitPrice)).toFixed(2)),
|
||||
g: idx
|
||||
|
||||
Reference in New Issue
Block a user