gongchunyi
8 小时以前 4c3dee416ab4940d10e43af0e0ec79433ddd012a
feat: 新增销售产品展示库存数量
已修改1个文件
59 ■■■■ 文件已修改
src/views/salesManagement/salesLedger/index.vue 59 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/salesManagement/salesLedger/index.vue
@@ -727,12 +727,33 @@
          <el-col :span="12">
            <el-form-item label="是否生产:"
                          prop="isProduction">
              <el-radio-group v-model="productForm.isProduction">
                <el-radio label="是"
                          :value="true" />
                <el-radio label="否"
                          :value="false" />
              </el-radio-group>
              <div style="display: flex; align-items: center; width: 100%;">
                <el-radio-group v-model="productForm.isProduction">
                  <el-radio label="是"
                            :value="true" />
                  <el-radio label="否"
                            :value="false" />
                </el-radio-group>
                <div
                  v-if="currentStock !== null"
                  :style="{
                    marginLeft: '20px',
                    padding: '0 12px',
                    height: '28px',
                    lineHeight: '28px',
                    borderRadius: '4px',
                    fontSize: '13px',
                    fontWeight: '500',
                    display: 'inline-block',
                    whiteSpace: 'nowrap',
                    backgroundColor: (productForm.quantity || 0) > currentStock ? '#fff0f0' : '#f0f9eb',
                    border: (productForm.quantity || 0) > currentStock ? '1px solid #ffcccc' : '1px solid #e1f3d8',
                    color: (productForm.quantity || 0) > currentStock ? '#f56c6c' : '#67c23a'
                  }"
                >
                  <span>当前库存:{{ currentStock }} {{ productForm.unit || '' }}</span>
                </div>
              </div>
            </el-form-item>
          </el-col>
        </el-row>
@@ -1198,6 +1219,27 @@
      item?.stockQuantity;
    return quantity ?? 0;
  };
  const currentStock = ref(null);
  const fetchCurrentStock = async (productModelId) => {
    if (!productModelId) {
      currentStock.value = null;
      return;
    }
    try {
      const res = await getStockInventoryByModelId(productModelId);
      const rawList = Array.isArray(res?.data)
        ? res.data
        : res?.data?.records || res?.data?.rows || [];
      let total = 0;
      rawList.forEach(item => {
        total += Number(getDeliveryBatchQuantity(item) || 0);
      });
      currentStock.value = total;
    } catch (e) {
      console.error(e);
      currentStock.value = 0;
    }
  };
  const getCurrentDeliveryRowQuantity = () => {
    return Number(currentDeliveryRow.value?.noQuantity || 0);
  };
@@ -1463,6 +1505,7 @@
  // 获取tree子数据
  const getModels = value => {
    productForm.value.productCategory = findNodeById(productOptions.value, value);
    currentStock.value = null;
    modelList({ id: value }).then(res => {
      modelOptions.value = res;
    });
@@ -1472,9 +1515,11 @@
    if (index !== -1) {
      productForm.value.specificationModel = modelOptions.value[index].model;
      productForm.value.unit = modelOptions.value[index].unit;
      fetchCurrentStock(value);
    } else {
      productForm.value.specificationModel = null;
      productForm.value.unit = null;
      currentStock.value = null;
    }
  };
  const findNodeById = (nodes, productId) => {
@@ -1798,6 +1843,7 @@
    productOperationType.value = type;
    productForm.value = {};
    currentStock.value = null;
    if (type === "add") {
      productForm.value.isProduction = false;
    }
@@ -1824,6 +1870,7 @@
          );
          if (currentModel) {
            productForm.value.productModelId = currentModel.id;
            fetchCurrentStock(currentModel.id);
          }
        }
      } catch (e) {