9.18王德鹏/1
This commit is contained in:
@@ -1,251 +0,0 @@
|
||||
"use strict";
|
||||
const common_vendor = require("../../common/vendor.js");
|
||||
const common_http = require("../../common/http.js");
|
||||
function parseSafeStock(text) {
|
||||
const m = String(text || "").match(/\s*(\d+(?:\.\d+)?)\s*(?:-|~|—|到|,)?\s*(\d+(?:\.\d+)?)?\s*/);
|
||||
if (!m)
|
||||
return { min: null, max: null };
|
||||
return { min: m[1] ? Number(m[1]) : null, max: m[2] ? Number(m[2]) : null };
|
||||
}
|
||||
const _sfc_main = {
|
||||
data() {
|
||||
return {
|
||||
id: null,
|
||||
units: [],
|
||||
categories: [],
|
||||
form: {
|
||||
name: "",
|
||||
categoryId: null,
|
||||
unitId: null,
|
||||
barcode: "",
|
||||
brand: "",
|
||||
model: "",
|
||||
spec: "",
|
||||
purchasePrice: 0,
|
||||
wholesalePrice: 0,
|
||||
bigClientPrice: 0,
|
||||
retailPrice: 0,
|
||||
stock: 0,
|
||||
safeMin: null,
|
||||
safeMax: null,
|
||||
images: []
|
||||
}
|
||||
};
|
||||
},
|
||||
onLoad(query) {
|
||||
this.id = query && query.id ? Number(query.id) : null;
|
||||
this.bootstrap();
|
||||
},
|
||||
computed: {
|
||||
categoryLabel() {
|
||||
const c = this.categories.find((x) => x.id === this.form.categoryId);
|
||||
return c ? c.name : "未选择";
|
||||
},
|
||||
unitLabel() {
|
||||
const u = this.units.find((x) => x.id === this.form.unitId);
|
||||
return u ? u.name : "未选择";
|
||||
},
|
||||
safeStockText: {
|
||||
get() {
|
||||
const a = this.form.safeMin != null ? String(this.form.safeMin) : "";
|
||||
const b = this.form.safeMax != null ? String(this.form.safeMax) : "";
|
||||
if (!a && !b)
|
||||
return "";
|
||||
if (a && b)
|
||||
return a + "-" + b;
|
||||
return a || b;
|
||||
},
|
||||
set(v) {
|
||||
const { min, max } = parseSafeStock(v);
|
||||
this.form.safeMin = min;
|
||||
this.form.safeMax = max;
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
async bootstrap() {
|
||||
try {
|
||||
const [units, cats] = await Promise.all([
|
||||
common_http.get("/api/product/units"),
|
||||
common_http.get("/api/product/categories")
|
||||
]);
|
||||
this.units = Array.isArray(units == null ? void 0 : units.list) ? units.list : Array.isArray(units) ? units : [];
|
||||
this.categories = Array.isArray(cats == null ? void 0 : cats.list) ? cats.list : Array.isArray(cats) ? cats : [];
|
||||
} catch (_) {
|
||||
}
|
||||
if (this.id) {
|
||||
try {
|
||||
const d = await common_http.get("/api/product/detail", { id: this.id });
|
||||
Object.assign(this.form, {
|
||||
name: d.name || "",
|
||||
categoryId: d.categoryId || null,
|
||||
unitId: d.unitId || null,
|
||||
barcode: d.barcode || "",
|
||||
brand: d.brand || "",
|
||||
model: d.model || "",
|
||||
spec: d.spec || "",
|
||||
purchasePrice: Number(d.purchasePrice || 0),
|
||||
wholesalePrice: Number(d.wholesalePrice || 0),
|
||||
bigClientPrice: Number(d.bigClientPrice || 0),
|
||||
retailPrice: Number(d.retailPrice || 0),
|
||||
stock: Number(d.stock || 0),
|
||||
safeMin: d.safeMin ?? null,
|
||||
safeMax: d.safeMax ?? null,
|
||||
images: Array.isArray(d.images) ? d.images : []
|
||||
});
|
||||
} catch (_) {
|
||||
}
|
||||
}
|
||||
},
|
||||
chooseCategory() {
|
||||
if (!this.categories.length)
|
||||
return;
|
||||
common_vendor.index.showActionSheet({ itemList: this.categories.map((c) => c.name), success: ({ tapIndex }) => {
|
||||
this.form.categoryId = this.categories[tapIndex].id;
|
||||
} });
|
||||
},
|
||||
chooseUnit() {
|
||||
if (!this.units.length)
|
||||
return;
|
||||
common_vendor.index.showActionSheet({ itemList: this.units.map((u) => u.name), success: ({ tapIndex }) => {
|
||||
this.form.unitId = this.units[tapIndex].id;
|
||||
} });
|
||||
},
|
||||
scanBarcode() {
|
||||
common_vendor.index.scanCode({ onlyFromCamera: false, success: (res) => {
|
||||
this.form.barcode = res.result;
|
||||
}, fail: () => {
|
||||
common_vendor.index.showToast({ title: "扫码失败,请手动录入", icon: "none" });
|
||||
} });
|
||||
},
|
||||
async chooseImages() {
|
||||
common_vendor.index.chooseImage({ count: 6, sizeType: ["compressed"], success: async (res) => {
|
||||
try {
|
||||
const uploaded = [];
|
||||
for (const path of res.tempFilePaths) {
|
||||
const ret = await common_http.upload("/api/upload", path, { biz: "product" });
|
||||
uploaded.push(ret.url || ret.path || path);
|
||||
}
|
||||
this.form.images = (this.form.images || []).concat(uploaded).slice(0, 9);
|
||||
} catch (e) {
|
||||
common_vendor.index.showToast({ title: "上传失败", icon: "none" });
|
||||
}
|
||||
} });
|
||||
},
|
||||
moveLeft(i) {
|
||||
if (i <= 0)
|
||||
return;
|
||||
const a = this.form.images;
|
||||
[a[i - 1], a[i]] = [a[i], a[i - 1]];
|
||||
},
|
||||
moveRight(i) {
|
||||
const a = this.form.images;
|
||||
if (i >= a.length - 1)
|
||||
return;
|
||||
[a[i + 1], a[i]] = [a[i], a[i + 1]];
|
||||
},
|
||||
removeImg(i) {
|
||||
this.form.images.splice(i, 1);
|
||||
},
|
||||
async submit() {
|
||||
if (!this.form.name) {
|
||||
common_vendor.index.showToast({ title: "请填写名称", icon: "none" });
|
||||
return;
|
||||
}
|
||||
const payload = {
|
||||
name: this.form.name,
|
||||
categoryId: this.form.categoryId,
|
||||
unitId: this.form.unitId,
|
||||
barcode: this.form.barcode,
|
||||
brand: this.form.brand,
|
||||
model: this.form.model,
|
||||
spec: this.form.spec,
|
||||
purchasePrice: Number(this.form.purchasePrice || 0),
|
||||
wholesalePrice: Number(this.form.wholesalePrice || 0),
|
||||
bigClientPrice: Number(this.form.bigClientPrice || 0),
|
||||
retailPrice: Number(this.form.retailPrice || 0),
|
||||
stock: Number(this.form.stock || 0),
|
||||
safeMin: this.form.safeMin,
|
||||
safeMax: this.form.safeMax,
|
||||
images: this.form.images
|
||||
};
|
||||
try {
|
||||
if (this.id)
|
||||
await common_http.put("/api/product", { id: this.id, ...payload });
|
||||
else
|
||||
await common_http.post("/api/product", payload);
|
||||
common_vendor.index.showToast({ title: "已保存", icon: "success" });
|
||||
setTimeout(() => {
|
||||
common_vendor.index.navigateBack();
|
||||
}, 600);
|
||||
} catch (e) {
|
||||
common_vendor.index.showToast({ title: e && e.message || "保存失败", icon: "none" });
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
||||
return {
|
||||
a: $data.form.name,
|
||||
b: common_vendor.o(common_vendor.m(($event) => $data.form.name = $event.detail.value, {
|
||||
trim: true
|
||||
})),
|
||||
c: common_vendor.t($options.categoryLabel),
|
||||
d: common_vendor.o((...args) => $options.chooseCategory && $options.chooseCategory(...args)),
|
||||
e: common_vendor.t($options.unitLabel),
|
||||
f: common_vendor.o((...args) => $options.chooseUnit && $options.chooseUnit(...args)),
|
||||
g: $data.form.barcode,
|
||||
h: common_vendor.o(common_vendor.m(($event) => $data.form.barcode = $event.detail.value, {
|
||||
trim: true
|
||||
})),
|
||||
i: common_vendor.o((...args) => $options.scanBarcode && $options.scanBarcode(...args)),
|
||||
j: $data.form.brand,
|
||||
k: common_vendor.o(common_vendor.m(($event) => $data.form.brand = $event.detail.value, {
|
||||
trim: true
|
||||
})),
|
||||
l: $data.form.model,
|
||||
m: common_vendor.o(common_vendor.m(($event) => $data.form.model = $event.detail.value, {
|
||||
trim: true
|
||||
})),
|
||||
n: $data.form.spec,
|
||||
o: common_vendor.o(common_vendor.m(($event) => $data.form.spec = $event.detail.value, {
|
||||
trim: true
|
||||
})),
|
||||
p: $data.form.purchasePrice,
|
||||
q: common_vendor.o(common_vendor.m(($event) => $data.form.purchasePrice = $event.detail.value, {
|
||||
number: true
|
||||
})),
|
||||
r: $data.form.wholesalePrice,
|
||||
s: common_vendor.o(common_vendor.m(($event) => $data.form.wholesalePrice = $event.detail.value, {
|
||||
number: true
|
||||
})),
|
||||
t: $data.form.bigClientPrice,
|
||||
v: common_vendor.o(common_vendor.m(($event) => $data.form.bigClientPrice = $event.detail.value, {
|
||||
number: true
|
||||
})),
|
||||
w: $data.form.retailPrice,
|
||||
x: common_vendor.o(common_vendor.m(($event) => $data.form.retailPrice = $event.detail.value, {
|
||||
number: true
|
||||
})),
|
||||
y: $data.form.stock,
|
||||
z: common_vendor.o(common_vendor.m(($event) => $data.form.stock = $event.detail.value, {
|
||||
number: true
|
||||
})),
|
||||
A: $options.safeStockText,
|
||||
B: common_vendor.o(($event) => $options.safeStockText = $event.detail.value),
|
||||
C: common_vendor.o((...args) => $options.chooseImages && $options.chooseImages(...args)),
|
||||
D: common_vendor.f($data.form.images, (url, idx, i0) => {
|
||||
return {
|
||||
a: url,
|
||||
b: common_vendor.o(($event) => $options.moveLeft(idx), idx),
|
||||
c: common_vendor.o(($event) => $options.moveRight(idx), idx),
|
||||
d: common_vendor.o(($event) => $options.removeImg(idx), idx),
|
||||
e: idx
|
||||
};
|
||||
}),
|
||||
E: common_vendor.o((...args) => $options.submit && $options.submit(...args))
|
||||
};
|
||||
}
|
||||
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
|
||||
wx.createPage(MiniProgramPage);
|
||||
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/product/edit.js.map
|
||||
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"navigationBarTitleText": "编辑货品",
|
||||
"usingComponents": {}
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
<view class="page"><view class="form"><view class="field"><text class="label">名称</text><input class="value" placeholder="必填" value="{{a}}" bindinput="{{b}}"/></view><view class="field" bindtap="{{d}}"><text class="label">类别</text><text class="value">{{c}}</text></view><view class="field" bindtap="{{f}}"><text class="label">主单位</text><text class="value">{{e}}</text></view><view class="field"><text class="label">条形码</text><input class="value" placeholder="手动录入或扫码" value="{{g}}" bindinput="{{h}}"/><button size="mini" class="scan" bindtap="{{i}}">扫码</button></view><view class="field"><text class="label">品牌</text><input class="value" placeholder="可选" value="{{j}}" bindinput="{{k}}"/></view><view class="field"><text class="label">型号</text><input class="value" placeholder="可选" value="{{l}}" bindinput="{{m}}"/></view><view class="field"><text class="label">规格</text><input class="value" placeholder="可选" value="{{n}}" bindinput="{{o}}"/></view><view class="grid2"><view class="field"><text class="label">进货价</text><input class="value" type="digit" value="{{p}}" bindinput="{{q}}"/></view><view class="field"><text class="label">批发价</text><input class="value" type="digit" value="{{r}}" bindinput="{{s}}"/></view><view class="field"><text class="label">大单报价</text><input class="value" type="digit" value="{{t}}" bindinput="{{v}}"/></view><view class="field"><text class="label">零售价</text><input class="value" type="digit" value="{{w}}" bindinput="{{x}}"/></view></view><view class="grid2"><view class="field"><text class="label">当前库存</text><input class="value" type="digit" value="{{y}}" bindinput="{{z}}"/></view><view class="field"><text class="label">安全库存</text><input class="value" type="text" placeholder="如 10-100" value="{{A}}" bindinput="{{B}}"/></view></view><view class="photos"><view class="photos-header"><text>商品图片</text><button size="mini" bindtap="{{C}}">选择图片</button></view><view class="photo-list"><view wx:for="{{D}}" wx:for-item="url" wx:key="e" class="photo"><image src="{{url.a}}" mode="aspectFill"/><view class="photo-actions"><text class="btn" bindtap="{{url.b}}">←</text><text class="btn" bindtap="{{url.c}}">→</text><text class="btn danger" bindtap="{{url.d}}">删</text></view></view></view></view></view><view class="bottom"><button class="primary" bindtap="{{E}}">保存</button></view></view>
|
||||
@@ -1,35 +0,0 @@
|
||||
|
||||
.page{ padding-bottom: 140rpx;
|
||||
}
|
||||
.form{ background:#fff;
|
||||
}
|
||||
.field{ display:flex; align-items:center; gap: 12rpx; padding: 22rpx 20rpx; border-bottom: 1rpx solid #f2f2f2;
|
||||
}
|
||||
.label{ color:#666; width: 160rpx;
|
||||
}
|
||||
.value{ flex:1; color:#333;
|
||||
}
|
||||
.scan{ flex: 0 0 auto;
|
||||
}
|
||||
.grid2{ display:grid; grid-template-columns: 1fr 1fr;
|
||||
}
|
||||
.photos{ padding: 16rpx 20rpx;
|
||||
}
|
||||
.photos-header{ display:flex; justify-content: space-between; align-items:center; margin-bottom: 12rpx;
|
||||
}
|
||||
.photo-list{ display:grid; grid-template-columns: repeat(3, 1fr); gap: 12rpx;
|
||||
}
|
||||
.photo{ position: relative;
|
||||
}
|
||||
.photo image{ width: 100%; height: 200rpx; border-radius: 12rpx; background:#f6f6f6; display:block;
|
||||
}
|
||||
.photo-actions{ position:absolute; right:6rpx; bottom:6rpx; display:flex; gap: 6rpx;
|
||||
}
|
||||
.btn{ font-size: 22rpx; padding: 4rpx 8rpx; background: rgba(0,0,0,0.45); color:#fff; border-radius: 8rpx;
|
||||
}
|
||||
.btn.danger{ background: rgba(221,82,77,0.85);
|
||||
}
|
||||
.bottom{ position: fixed; left:0; right:0; bottom:0; background:#fff; padding: 16rpx 24rpx calc(env(safe-area-inset-bottom) + 16rpx); box-shadow: 0 -4rpx 12rpx rgba(0,0,0,0.06);
|
||||
}
|
||||
.primary{ width: 100%; background: linear-gradient(135deg, #FFE69A 0%, #F4CF62 45%, #D7A72E 100%); color:#493c1b; border-radius: 999rpx; padding: 20rpx 0; font-weight:800;
|
||||
}
|
||||
@@ -16,6 +16,9 @@ const _sfc_main = {
|
||||
this.fetchCategories();
|
||||
this.reload();
|
||||
},
|
||||
onShow() {
|
||||
this.reload();
|
||||
},
|
||||
computed: {
|
||||
categoryNames() {
|
||||
return this.categories.map((c) => c.name);
|
||||
|
||||
@@ -35,8 +35,8 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
||||
e: common_vendor.f($data.products, (p, k0, i0) => {
|
||||
return {
|
||||
a: common_vendor.t(p.name),
|
||||
b: common_vendor.t(p.code),
|
||||
c: common_vendor.t(p.stock || 0),
|
||||
b: common_vendor.t((p.brand || "") + " " + (p.model || "") + " " + (p.spec || "")),
|
||||
c: common_vendor.t(p.stock ?? 0),
|
||||
d: p.id,
|
||||
e: common_vendor.o(($event) => $options.select(p), p.id)
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user