<template>
|
<view class="account-detail">
|
<PageHeader title="新增库存"
|
@back="goBack" />
|
<up-form ref="formRef"
|
:model="form"
|
label-width="110">
|
<up-form-item label="产品"
|
required>
|
<up-input v-model="form.productName"
|
placeholder="请选择"
|
readonly
|
@click="goSelectProduct" />
|
<template #right>
|
<up-icon name="arrow-right"
|
@click="goSelectProduct"></up-icon>
|
</template>
|
</up-form-item>
|
<up-form-item label="规格型号">
|
<up-input v-model="form.model"
|
disabled
|
placeholder="自动填充" />
|
</up-form-item>
|
<up-form-item label="单位">
|
<up-input v-model="form.unit"
|
disabled
|
placeholder="自动填充" />
|
</up-form-item>
|
<up-form-item label="库存类型"
|
required>
|
<up-input v-model="stockTypeText"
|
disabled />
|
</up-form-item>
|
<up-form-item label="数量"
|
required>
|
<up-number-box v-model="form.qualitity"
|
:min="1"
|
:step="1" />
|
</up-form-item>
|
<up-form-item label="批号">
|
<up-input v-model="form.batchNo"
|
placeholder="选填"
|
clearable />
|
</up-form-item>
|
<up-form-item v-if="form.type === 'qualified'"
|
label="预警数量">
|
<up-number-box v-model="form.warnNum"
|
:min="0"
|
:max="Number(form.qualitity || 0)"
|
:step="1" />
|
</up-form-item>
|
<up-form-item label="备注">
|
<up-textarea v-model="form.remark"
|
placeholder="选填"
|
auto-height />
|
</up-form-item>
|
</up-form>
|
<FooterButtons cancelText="取消"
|
confirmText="保存"
|
:loading="submitting"
|
@cancel="goBack"
|
@confirm="handleSubmit" />
|
</view>
|
</template>
|
|
<script setup>
|
import { onMounted, ref } from "vue";
|
import PageHeader from "@/components/PageHeader.vue";
|
import FooterButtons from "@/components/FooterButtons.vue";
|
import { addStockInRecordOnly } from "@/api/inventoryManagement/stockInventory.js";
|
|
const submitting = ref(false);
|
const formRef = ref(null);
|
const topParentProductId = ref(undefined);
|
|
const form = ref({
|
productId: undefined,
|
productModelId: undefined,
|
productName: "",
|
model: "",
|
unit: "",
|
type: "qualified",
|
qualitity: 1,
|
batchNo: null,
|
warnNum: 0,
|
remark: "",
|
});
|
|
const stockTypeText = ref("合格库存");
|
|
const getRequestErrorText = err => {
|
if (!err || typeof err !== "object") return "";
|
const msg = err?.msg || err?.message || err?.data?.msg || err?.data?.message;
|
return msg ? String(msg) : "";
|
};
|
|
const goBack = () => {
|
uni.navigateBack();
|
};
|
|
const goSelectProduct = () => {
|
const onSelected = row => {
|
form.value.productId = row.productId;
|
form.value.productModelId = row.id;
|
form.value.productName = row.productName || "";
|
form.value.model = row.model || "";
|
form.value.unit = row.unit || "";
|
};
|
uni.$once("stockManagement:selectedProductModel", onSelected);
|
uni.navigateTo({
|
url: `/pages/inventoryManagement/stockManagement/selectProductModel?topParentProductId=${topParentProductId.value || ""}`,
|
events: {
|
selected: onSelected,
|
},
|
});
|
};
|
|
const handleSubmit = () => {
|
if (!form.value.productModelId) {
|
uni.showToast({ title: "请选择产品", icon: "none" });
|
return;
|
}
|
const qty = Number(form.value.qualitity);
|
if (!qty || qty < 1) {
|
uni.showToast({ title: "数量必须大于0", icon: "none" });
|
return;
|
}
|
|
submitting.value = true;
|
const payload = { ...form.value };
|
if (payload.batchNo === "") payload.batchNo = null;
|
addStockInRecordOnly(payload)
|
.then(() => {
|
uni.showToast({ title: "提交成功", icon: "success" });
|
uni.$emit("stockManagement:refresh", { topParentProductId: topParentProductId.value });
|
goBack();
|
})
|
.catch(err => {
|
const title = getRequestErrorText(err);
|
if (title) uni.showToast({ title, icon: "none" });
|
})
|
.finally(() => {
|
submitting.value = false;
|
});
|
};
|
|
onMounted(() => {
|
const options = getCurrentPages()?.slice(-1)?.[0]?.options || {};
|
topParentProductId.value = options.topParentProductId ? Number(options.topParentProductId) : undefined;
|
});
|
</script>
|
|
<style scoped lang="scss">
|
@import "@/static/scss/form-common.scss";
|
</style>
|