spring
2026-03-27 4e950b3724519ddf165f33be9988098daf979d33
src/pages/inventoryManagement/stockManagement/add.vue
@@ -19,44 +19,59 @@
        </view>
        <view class="form-row">
          <text class="form-label">单位</text>
          <up-input v-model="form.unit" disabled placeholder="请选择产品后自动带出" />
          <up-radio-group v-model="form.unit" class="unit-radio-group">
            <up-radio
              v-for="opt in unitOptions"
              :key="opt.value"
              :label="opt.label"
              :name="opt.value"
            ></up-radio>
          </up-radio-group>
        </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>
          <text class="form-label required">车牌号</text>
          <up-input v-model="form.licensePlateNo" placeholder="请输入车牌号" />
        </view>
        <view class="form-row">
          <text class="form-label">毛重(吨)</text>
          <text class="form-label required">毛重</text>
          <up-input
            v-model="form.grossWeight"
            type="number"
            type="digit"
            placeholder="请输入毛重"
          />
        </view>
        <view class="form-row">
          <text class="form-label">皮重(吨)</text>
          <text class="form-label required">皮重</text>
          <up-input
            v-model="form.tareWeight"
            type="number"
            type="digit"
            placeholder="请输入皮重"
          />
        </view>
        <view class="form-row">
          <text class="form-label">净重(吨)</text>
          <text class="form-label">净重</text>
          <up-input
            v-model="form.netWeight"
            type="number"
            type="digit"
            disabled
            placeholder="自动计算"
          />
        </view>
        <view class="form-row">
          <text class="form-label">过磅日期</text>
          <text class="form-label required">过磅日期</text>
          <view class="selector-trigger" @click="openWeighingDatePicker">
            <text class="selector-text" :class="{ placeholder: !form.weighingDate }">
              {{ form.weighingDate || '请选择过磅日期' }}
@@ -65,16 +80,12 @@
          </view>
        </view>
        <view class="form-row">
          <text class="form-label">过磅员</text>
          <text class="form-label required">过磅员</text>
          <up-input v-model="form.weighingOperator" placeholder="请输入过磅员" />
        </view>
      </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="选填" />
@@ -152,20 +163,42 @@
  productModelId: undefined,
  productName: '',
  productModelName: '',
  unit: '',
  unit: '吨',
  productType: undefined,
  parentName: '',
  licensePlateNo: '',
  grossWeight: '',
  tareWeight: '',
  netWeight: '',
  weighingDate: '',
  weighingDate: dayjs().format('YYYY-MM-DD HH:mm:ss'),
  weighingOperator: '',
  qualitity: '',
  remark: ''
})
const unitOptions = [
  { label: '吨', value: '吨' },
  { label: '公斤', value: '公斤' }
]
const normalizeUnit = (u) => {
  if (!u) return ''
  const s = String(u).trim()
  if (s === '吨' || s === 't' || s === 'ton' || s === 'tonne') return '吨'
  if (
    s === '公斤' ||
    s === 'kg' ||
    s === 'kilogram' ||
    s === '千克' ||
    s === 'kilograms'
  )
    return '公斤'
  return s
}
const type = ref('0') // 固定合格库存
const isQualified = computed(() => true)
const isFinishedProduct = computed(() => form.parentName === '成品')
const showProductPopup = ref(false)
const productQuery = reactive({
@@ -221,8 +254,22 @@
  form.productModelId = item.id
  form.productName = item.productName
  form.productModelName = item.model
  form.unit = item.unit
  const normalizedUnit = normalizeUnit(item.unit)
  form.unit = normalizedUnit === '吨' || normalizedUnit === '公斤' ? normalizedUnit : '吨'
  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 +311,54 @@
    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
    }
  } else {
    if (!form.licensePlateNo) {
      uni.showToast({ title: '请输入车牌号', icon: 'none' })
      return
    }
    if (!form.grossWeight || Number(form.grossWeight) <= 0) {
      uni.showToast({ title: '请输入毛重', icon: 'none' })
      return
    }
    if (!form.tareWeight || Number(form.tareWeight) <= 0) {
      uni.showToast({ title: '请输入皮重', icon: 'none' })
      return
    }
    if (!form.weighingDate) {
      uni.showToast({ title: '请选择过磅日期', icon: 'none' })
      return
    }
    if (!form.weighingOperator) {
      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' })
@@ -422,6 +498,12 @@
  font-size: 24rpx;
  color: #666;
}
.unit-radio-group {
  display: flex;
  gap: 24rpx;
  align-items: center;
  flex-wrap: wrap;
}
.no-data {
  text-align: center;
  padding: 40rpx 0;