spring
2 天以前 e65eba077662e270ba462304b15507d00ec2875a
src/pages/inventoryManagement/stockManagement/add.vue
@@ -23,8 +23,16 @@
        </view>
      </view>
      <!-- 过磅相关字段 -->
      <view class="form-section">
      <!-- 成品:只需要数量 -->
      <view v-if="isFinishedProduct" class="form-section">
        <view class="form-row">
          <text class="form-label required">数量</text>
          <up-input v-model="form.qualitity" type="number" placeholder="请输入数量" />
        </view>
      </view>
      <!-- 原材料:过磅相关字段 -->
      <view v-else class="form-section">
        <view class="section-title">过磅信息</view>
        <view class="form-row">
          <text class="form-label">车牌号</text>
@@ -34,7 +42,7 @@
          <text class="form-label">毛重(吨)</text>
          <up-input
            v-model="form.grossWeight"
            type="number"
            type="digit"
            placeholder="请输入毛重"
          />
        </view>
@@ -42,7 +50,7 @@
          <text class="form-label">皮重(吨)</text>
          <up-input
            v-model="form.tareWeight"
            type="number"
            type="digit"
            placeholder="请输入皮重"
          />
        </view>
@@ -50,7 +58,7 @@
          <text class="form-label">净重(吨)</text>
          <up-input
            v-model="form.netWeight"
            type="number"
            type="digit"
            disabled
            placeholder="自动计算"
          />
@@ -71,10 +79,6 @@
      </view>
      <view class="form-section">
        <!-- <view class="form-row">
          <text class="form-label required">数量</text>
          <up-input v-model="form.qualitity" type="number" placeholder="请输入数量" />
        </view> -->
        <view class="form-row">
          <text class="form-label">备注</text>
          <up-input v-model="form.remark" type="textarea" placeholder="选填" />
@@ -154,6 +158,7 @@
  productModelName: '',
  unit: '',
  productType: undefined,
  parentName: '',
  licensePlateNo: '',
  grossWeight: '',
  tareWeight: '',
@@ -166,6 +171,7 @@
const type = ref('0') // 固定合格库存
const isQualified = computed(() => true)
const isFinishedProduct = computed(() => form.parentName === '成品')
const showProductPopup = ref(false)
const productQuery = reactive({
@@ -223,6 +229,19 @@
  form.productModelName = item.model
  form.unit = item.unit
  form.productType = item.productType
  form.parentName = parentName
  // 切换产品后,按类型清理无关字段
  if (parentName === '成品') {
    form.licensePlateNo = ''
    form.grossWeight = ''
    form.tareWeight = ''
    form.netWeight = ''
    form.weighingDate = ''
    form.weighingOperator = ''
  } else {
    form.qualitity = ''
  }
  showProductPopup.value = false
}
@@ -264,25 +283,33 @@
    uni.showToast({ title: '请选择产品', icon: 'none' })
    return
  }
  // if (!form.qualitity || Number(form.qualitity) <= 0) {
  //   uni.showToast({ title: '请输入数量', icon: 'none' })
  //   return
  // }
  const payload = {
  if (isFinishedProduct.value) {
    if (!form.qualitity || Number(form.qualitity) <= 0) {
      uni.showToast({ title: '请输入数量', icon: 'none' })
      return
    }
  }
  const base = {
    productId: form.productId,
    productModelId: form.productModelId,
    productName: form.productName,
    productModelName: form.productModelName,
    unit: form.unit,
    productType: form.productType,
    licensePlateNo: form.licensePlateNo,
    grossWeight: form.grossWeight,
    tareWeight: form.tareWeight,
    netWeight: form.netWeight,
    weighingDate: form.weighingDate,
    weighingOperator: form.weighingOperator,
    remark: form.remark
  }
  const payload = isFinishedProduct.value
    ? { ...base, qualitity: Number(form.qualitity) }
    : {
        ...base,
        licensePlateNo: form.licensePlateNo,
        grossWeight: form.grossWeight,
        tareWeight: form.tareWeight,
        netWeight: form.netWeight,
        weighingDate: form.weighingDate,
        weighingOperator: form.weighingOperator
      }
  createStockInventory(payload)
    .then(() => {
      uni.showToast({ title: '新增成功', icon: 'success' })