spring
7 天以前 f24ec48c98a485af26321f7f4b74fe1611162f5a
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 v-if="isQualified" 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="选填" />
@@ -145,7 +156,6 @@
import dayjs from 'dayjs'
import PageHeader from '@/components/PageHeader.vue'
import { createStockInventory } from '@/api/inventoryManagement/stockInventory.js'
import { createStockUnInventory } from '@/api/inventoryManagement/stockUninventory.js'
import { productModelList } from '@/api/basicData/productModel.js'
const form = reactive({
@@ -153,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 type = ref('0') // 0 合格库存,1 不合格库存
const isQualified = computed(() => type.value === '0')
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({
@@ -180,9 +212,7 @@
const weighingDateValue = ref(Date.now())
onLoad((options) => {
  if (options && options.type != null) {
    type.value = options.type
  }
  type.value = '0'
})
const openProductSelector = () => {
@@ -202,7 +232,12 @@
  })
    .then(res => {
      const data = res?.records || res?.data?.records || []
      productList.value = Array.isArray(data) ? data : []
      const list = Array.isArray(data) ? data : []
      // 过滤耗材:耗材不允许在“产品库存”入库
      productList.value = list.filter(item => {
        const parentName = item?.parentName || item?.parent?.name || ''
        return parentName !== '耗材'
      })
    })
    .finally(() => {
      productLoading.value = false
@@ -210,12 +245,31 @@
}
const selectProduct = (item) => {
  const parentName = item?.parentName || item?.parent?.name || ''
  if (parentName === '耗材') {
    uni.showToast({ title: '耗材请到耗材库存入库', icon: 'none' })
    return
  }
  form.productId = item.productId || item.id
  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
}
@@ -257,27 +311,55 @@
    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 api = isQualified.value ? createStockInventory : createStockUnInventory
  api(payload)
  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' })
      setTimeout(() => {
@@ -416,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;