feat: 绿植租赁方案添加产品数量

This commit is contained in:
fyy
2025-07-07 14:38:01 +08:00
parent f5d7d70cc2
commit 9ab72435c7
5 changed files with 184 additions and 98 deletions

View File

@@ -1,5 +1,5 @@
<script setup lang="ts">
import { computed, ref } from 'vue';
import { computed, ref, watch } from 'vue';
import { useVbenModal } from '@vben/common-ui';
import { $t } from '@vben/locales';
import { cloneDeep } from '@vben/utils';
@@ -25,6 +25,10 @@ const title = computed(() => {
// 缓存清洁服务数据
let plantListData: any[] = [];
const detailIndex = ref<number>();//传index对应详情的某条数据,对该条数据进行编辑修改
// 添加数量最大值
const productNumMax = ref<any>(0);
const detailSchema = [
{
label: '产品名称',
@@ -33,7 +37,7 @@ const detailSchema = [
componentProps: {
disabled: isView,
api: async () => {
const res = await plantsProductList({inventory:0});
const res = await plantsProductList({state:1,inventory:0});
plantListData = res.rows || [];
return res;
},
@@ -47,6 +51,7 @@ const detailSchema = [
// 自动填充其他字段
await formApi.setValues({
plantCode: selectedService.plantCode,
inventory: selectedService.inventory,
plantType: selectedService.plantType,
imgPath: selectedService.imgPath,
specification: selectedService.specification,
@@ -54,11 +59,32 @@ const detailSchema = [
state: selectedService.state,
remark: selectedService.remark,
});
// 更新最大数量
productNumMax.value = selectedService.inventory || 0;
}
},
},
rules: 'required',
},
{
label: '产品库存',
fieldName: 'inventory',
component: 'Input',
componentProps: {
disabled: true,
},
rules: 'required',
},
{
label: '添加数量',
fieldName: 'productNum',
component: 'InputNumber',
componentProps: {
min: 1,
max: productNumMax,
},
rules: 'required',
},
{
label: '产品编号',
fieldName: 'plantCode',
@@ -138,6 +164,22 @@ const [BasicForm, formApi] = useVbenForm({
showDefaultActions: false,
});
// 监听inventory变化更新productNumMax
watch(async () => {
const values = await formApi.getValues();
return values.inventory;
}, async (newInventory) => {
if (newInventory) {
productNumMax.value = newInventory;
// 如果当前productNum大于新的库存则设置为库存值
const values = await formApi.getValues();
const currentProductNum = values.productNum;
if (currentProductNum && currentProductNum > newInventory) {
formApi.setFieldValue('productNum', newInventory);
}
}
}, { immediate: true });
const { onBeforeClose, markInitialized, resetInitialized } = useBeforeCloseDiff(
{
initializedGetter: defaultFormValueGetter(formApi),
@@ -185,7 +227,7 @@ async function handleConfirm() {
const selectedService = plantListData.find(item => item.id === data.plantName);
if (selectedService) {
data.plantName = selectedService.plantName;
data.id = selectedService.id
data.productId = selectedService.id
}
if (isUpdate.value) {
data.index = detailIndex.value;

View File

@@ -88,7 +88,8 @@ async function handleConfirm() {
}
// getValues获取为一个readonly的对象 需要修改必须先深拷贝一次
const data = cloneDeep(await formApi.getValues());
data.productIds = detailTable.value.map((item:any) => item.id);
// data.productIds = detailTable.value.map((item:any) => item.productId);
data.productList = detailTable.value;
await (isUpdate.value ? rentalPlanUpdate({...data,id:editId.value}) : rentalPlanAdd(data));
resetInitialized();
emit('reload');
@@ -114,6 +115,7 @@ const detailColumns = [
{ title: '产品编号', dataIndex: 'plantCode', key: 'plantCode' },
{ title: '产品名称', dataIndex: 'plantName', key: 'plantName' },
{ title: '产品分类', dataIndex: 'plantType', key: 'plantType' },
{ title: '产品数量', dataIndex: 'productNum', key: 'productNum' },
{
title: '图片',
dataIndex: 'imgPath',
@@ -131,7 +133,7 @@ const detailColumns = [
dataIndex: 'state',
key: 'state',
customRender: ({ value }: { value: number }) =>
value === 1 ? '上架' : '下架',
value == 1 ? '上架' : '下架',
},
{
title: '操作',