Przeglądaj źródła

feat(product): 添加库存修改功能并优化商品状态管理

- 在商品基础页面添加库存修改弹框,支持总库存、可用库存、虚拟库存的编辑
- 新增库存修改相关的表单验证和提交逻辑
- 修改商品上下架操作中的状态值类型从字符串改为数字
- 更新商品状态字段类型定义从string改为number
- 优化审核流程中的标签颜色和审核选项显示逻辑
- 修复审核表单中缺少产品审核状态字段的问题
肖路 4 tygodni temu
rodzic
commit
bd484af58e

+ 1 - 1
src/api/product/base/types.ts

@@ -96,7 +96,7 @@ export interface BaseVO {
   /**
    * 商品状态:1=已上架,0=下架,2=上架中
    */
-  productStatus: string;
+  productStatus: number;
 
   /**
    * 数据来源

+ 106 - 9
src/views/product/base/index.vue

@@ -250,11 +250,54 @@
         @pagination="getList"
       />
     </el-card>
-  </div>
+    <!-- 库存修改弹框 -->
+  <el-dialog v-model="inventoryDialog.visible" title="修改库存" width="500px" :close-on-click-modal="false">
+    <div v-loading="inventoryDialog.loading">
+      <el-form ref="inventoryFormRef" :model="inventoryForm" :rules="inventoryRules" label-width="110px">
+        <el-form-item label="总库存" prop="totalInventory">
+          <el-input-number
+            v-model="inventoryForm.totalInventory"
+            :min="0"
+            :precision="0"
+            controls-position="right"
+            style="width: 100%"
+            placeholder="请输入总库存"
+          />
+        </el-form-item>
+        <el-form-item label="当前可用库存" prop="nowInventory">
+          <el-input-number
+            v-model="inventoryForm.nowInventory"
+            :min="0"
+            :precision="0"
+            controls-position="right"
+            style="width: 100%"
+            placeholder="请输入当前可用库存"
+          />
+        </el-form-item>
+        <el-form-item label="虚拟库存" prop="virtualInventory">
+          <el-input-number
+            v-model="inventoryForm.virtualInventory"
+            :min="0"
+            :precision="0"
+            controls-position="right"
+            style="width: 100%"
+            placeholder="请输入虚拟库存"
+          />
+        </el-form-item>
+      </el-form>
+    </div>
+    <template #footer>
+      <el-button @click="inventoryDialog.visible = false">取消</el-button>
+      <el-button type="primary" :loading="inventoryDialog.submitLoading" @click="submitInventory">确定</el-button>
+    </template>
+  </el-dialog>
+</div>
 </template>
 
 <script setup name="Base" lang="ts">
-import { listBase, getBase, delBase, brandList, categoryTree, shelfReview, changeProductType, getProductStatusCount } from '@/api/product/base';
+import { listBase, getBase, delBase, brandList ,updateBase, categoryTree, shelfReview, changeProductType, getProductStatusCount } from '@/api/product/base';
+import { getPriceInventory, updatePriceInventory } from '@/api/product/priceInventory';
+import { PriceInventoryForm } from '@/api/product/priceInventory/types';
 import { BaseVO, BaseQuery, BaseForm, StatusCountVo } from '@/api/product/base/types';
 import { BrandVO } from '@/api/product/brand/types';
 import { listBrand } from '@/api/product/brand';
@@ -529,14 +572,13 @@ const handleView = (row: BaseVO) => {
 
 /** 上下架操作 */
 const handleShelf = async (row: BaseVO) => {
-  // productStatus字段定义为string类型:1=已上架,0=下架,2=上架中
-  const isOnShelf = row.productStatus === '1';
+  const isOnShelf = row.productStatus === 1;
   const action = isOnShelf ? '下架' : '上架';
   await proxy?.$modal.confirm(`确认${action}该商品吗?`);
 
   try {
     // 上架:状态改为2(上架中),下架:状态改为0(下架)
-    const productStatus = isOnShelf ? '0' : '2';
+    const productStatus = isOnShelf ? 0 : 2;
     await shelfReview({
       id: row.id,
       productStatus: productStatus,
@@ -556,10 +598,65 @@ const handlePrice = (row: BaseVO) => {
   // TODO: 打开价格设置对话框
 };
 
-/** 供货存管理 */
-const handleSupply = (row: BaseVO) => {
-  console.log('供货存管理', row);
-  // TODO: 打开供货存管理对话框
+/** 库存修改弹框 */
+const inventoryDialog = reactive({
+  visible: false,
+  loading: false,
+  submitLoading: false
+});
+
+const inventoryFormRef = ref<ElFormInstance>();
+
+const inventoryForm = reactive<PriceInventoryForm>({
+  productId: undefined,
+  totalInventory: undefined,
+  nowInventory: undefined,
+  virtualInventory: undefined
+});
+
+const inventoryRules = {
+  totalInventory: [{ required: true, message: '总库存不能为空', trigger: 'blur' }],
+  nowInventory: [{ required: true, message: '当前可用库存不能为空', trigger: 'blur' }],
+  virtualInventory: [{ required: true, message: '虚拟库存不能为空', trigger: 'blur' }]
+};
+
+/** 打开库存修改弹框 */
+const handleSupply = async (row: BaseVO) => {
+  inventoryForm.id = row.id;
+  inventoryForm.totalInventory = undefined;
+  inventoryForm.nowInventory = undefined;
+  inventoryForm.virtualInventory = undefined;
+  inventoryDialog.loading = true;
+  inventoryDialog.visible = true;
+  try {
+    const res = await getBase(row.id);
+    if (res.data) {
+      inventoryForm.totalInventory = res.data.totalInventory;
+      inventoryForm.nowInventory = res.data.nowInventory;
+      inventoryForm.virtualInventory = res.data.virtualInventory;
+    }
+  } catch (error) {
+    console.error('获取库存信息失败:', error);
+  } finally {
+    inventoryDialog.loading = false;
+  }
+};
+
+/** 提交库存修改 */
+const submitInventory = async () => {
+  await inventoryFormRef.value?.validate();
+  inventoryDialog.submitLoading = true;
+  try {
+    await updateBase({ ...inventoryForm });
+    proxy?.$modal.msgSuccess('库存修改成功');
+    inventoryDialog.visible = false;
+    await getList();
+  } catch (error) {
+    console.error('库存修改失败:', error);
+    proxy?.$modal.msgError('库存修改失败');
+  } finally {
+    inventoryDialog.submitLoading = false;
+  }
 };
 
 /** 停售操作 */

+ 11 - 8
src/views/product/base/review.vue

@@ -117,7 +117,7 @@
         </el-table-column>
         <el-table-column label="SKU价格" align="center" width="180">
           <template #default="scope">
-            <div class="text-left" style="font-size: 12px;">
+            <div class="text-left" style="font-size: 12px">
               <div>
                 <span class="text-gray-500">市场价:</span>
                 <span class="text-red-500">¥{{ scope.row.marketPrice || '0.00' }}</span>
@@ -155,9 +155,9 @@
         <el-table-column label="商品状态" align="center" width="100">
           <template #default="scope">
             <el-tag v-if="scope.row.productReviewStatus === 0" type="info">待采购审核</el-tag>
-            <el-tag v-else-if="scope.row.productReviewStatus === 1" type="warning">审核通过</el-tag>
-            <el-tag v-else-if="scope.row.productReviewStatus === 2" type="success">驳回</el-tag>
-            <el-tag v-else-if="scope.row.productReviewStatus === 3" type="danger">待营销审核</el-tag>
+            <el-tag v-else-if="scope.row.productReviewStatus === 1" type="success">审核通过</el-tag>
+            <el-tag v-else-if="scope.row.productReviewStatus === 2" type="danger">驳回</el-tag>
+            <el-tag v-else-if="scope.row.productReviewStatus === 3" type="warning">待营销审核</el-tag>
             <span v-else>-</span>
           </template>
         </el-table-column>
@@ -222,8 +222,9 @@
         </el-form-item>
         <el-form-item label="审核结果" prop="reviewStatus">
           <el-radio-group v-model="reviewForm.reviewStatus">
-            <el-radio :label="2">审核通过</el-radio>
-            <el-radio :label="3">审核驳回</el-radio>
+            <el-radio v-if="reviewForm.productReviewStatus === 0" :label="3">采购审核通过</el-radio>
+            <el-radio v-if="reviewForm.productReviewStatus === 3" :label="1">营销审核通过</el-radio>
+            <el-radio :label="2">审核驳回</el-radio>
           </el-radio-group>
         </el-form-item>
         <el-form-item label="审核意见" prop="reviewComments">
@@ -444,7 +445,8 @@ const handlePurchaseReview = (row: BaseVO) => {
     productNo: row.productNo,
     itemName: row.itemName,
     reviewStatus: 3,
-    reviewComments: ''
+    reviewComments: '',
+    productReviewStatus: row.productReviewStatus
   };
 }
 
@@ -457,7 +459,8 @@ const handleMarketingReview = (row: BaseVO) => {
     productNo: row.productNo,
     itemName: row.itemName,
     reviewStatus: 1,
-    reviewComments: ''
+    reviewComments: '',
+    productReviewStatus: row.productReviewStatus
   };
 };