spring
7 天以前 f24ec48c98a485af26321f7f4b74fe1611162f5a
fix: 吨/公斤换算
已修改4个文件
212 ■■■■■ 文件已修改
src/pages/inventoryManagement/dispatchLog/index.vue 46 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/pages/inventoryManagement/receiptManagement/index.vue 47 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/pages/inventoryManagement/stockManagement/add.vue 46 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/pages/inventoryManagement/stockManagement/subtract.vue 73 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/pages/inventoryManagement/dispatchLog/index.vue
@@ -83,7 +83,19 @@
          </view>
          <view class="form-row">
            <text class="form-label required">毛重(吨)</text>
            <text class="form-label">单位</text>
            <up-radio-group v-model="editForm.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 class="form-row">
            <text class="form-label required">毛重</text>
            <up-input
              v-model="editForm.grossWeight"
              type="digit"
@@ -93,7 +105,7 @@
          </view>
          <view class="form-row">
            <text class="form-label required">皮重(吨)</text>
            <text class="form-label required">皮重</text>
            <up-input
              v-model="editForm.tareWeight"
              type="digit"
@@ -103,7 +115,7 @@
          </view>
          <view class="form-row">
            <text class="form-label required">净重(吨)</text>
            <text class="form-label required">净重</text>
            <up-input v-model="editForm.netWeight" type="digit" placeholder="自动计算" disabled />
          </view>
@@ -285,6 +297,7 @@
const editForm = reactive({
  id: null,
  licensePlateNo: '',
  unit: '吨',
  grossWeight: '',
  tareWeight: '',
  netWeight: '',
@@ -292,6 +305,26 @@
  weighingOperator: '',
  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 '吨'
}
const computeNetWeightEdit = () => {
  const gross = Number(editForm.grossWeight)
@@ -324,6 +357,7 @@
const handleEdit = (row) => {
  Object.assign(editForm, row || {})
  editForm.unit = normalizeUnit(editForm.unit)
  // 以当前毛重/皮重为准计算净重
  computeNetWeightEdit()
  showEditModal.value = true
@@ -525,6 +559,12 @@
  color: #f56c6c;
  margin-right: 6rpx;
}
.unit-radio-group {
  display: flex;
  gap: 24rpx;
  align-items: center;
  flex-wrap: wrap;
}
.selector-trigger {
  display: flex;
  align-items: center;
src/pages/inventoryManagement/receiptManagement/index.vue
@@ -81,16 +81,29 @@
            <text class="form-label required">车牌号</text>
            <up-input v-model="editForm.licensePlateNo" placeholder="请输入车牌号" />
          </view>
          <view class="form-row">
            <text class="form-label required">毛重(吨)</text>
            <text class="form-label">单位</text>
            <up-radio-group v-model="editForm.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 class="form-row">
            <text class="form-label required">毛重</text>
            <up-input v-model="editForm.grossWeight" type="digit" placeholder="请输入毛重" @blur="computeNetWeightEdit" />
          </view>
          <view class="form-row">
            <text class="form-label required">皮重(吨)</text>
            <text class="form-label required">皮重</text>
            <up-input v-model="editForm.tareWeight" type="digit" placeholder="请输入皮重" @blur="computeNetWeightEdit" />
          </view>
          <view class="form-row">
            <text class="form-label required">净重(吨)</text>
            <text class="form-label required">净重</text>
            <up-input v-model="editForm.netWeight" type="digit" placeholder="自动计算" disabled />
          </view>
          <view class="form-row">
@@ -275,6 +288,7 @@
const editForm = reactive({
  id: null,
  licensePlateNo: '',
  unit: '吨',
  grossWeight: '',
  tareWeight: '',
  netWeight: '',
@@ -282,6 +296,26 @@
  weighingOperator: '',
  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 '吨'
}
const computeNetWeightEdit = () => {
  const gross = Number(editForm.grossWeight)
@@ -312,6 +346,7 @@
const handleEdit = (row) => {
  Object.assign(editForm, row || {})
  editForm.unit = normalizeUnit(editForm.unit)
  computeNetWeightEdit()
  showEditModal.value = true
}
@@ -534,6 +569,12 @@
  color: #f56c6c;
  margin-right: 6rpx;
}
.unit-radio-group {
  display: flex;
  gap: 24rpx;
  align-items: center;
  flex-wrap: wrap;
}
.selector-trigger {
  display: flex;
  align-items: center;
src/pages/inventoryManagement/stockManagement/add.vue
@@ -19,7 +19,14 @@
        </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>
@@ -39,7 +46,7 @@
          <up-input v-model="form.licensePlateNo" placeholder="请输入车牌号" />
        </view>
        <view class="form-row">
          <text class="form-label required">毛重(吨)</text>
          <text class="form-label required">毛重</text>
          <up-input
            v-model="form.grossWeight"
            type="digit"
@@ -47,7 +54,7 @@
          />
        </view>
        <view class="form-row">
          <text class="form-label required">皮重(吨)</text>
          <text class="form-label required">皮重</text>
          <up-input
            v-model="form.tareWeight"
            type="digit"
@@ -55,7 +62,7 @@
          />
        </view>
        <view class="form-row">
          <text class="form-label">净重(吨)</text>
          <text class="form-label">净重</text>
          <up-input
            v-model="form.netWeight"
            type="digit"
@@ -156,7 +163,7 @@
  productModelId: undefined,
  productName: '',
  productModelName: '',
  unit: '',
  unit: '吨',
  productType: undefined,
  parentName: '',
  licensePlateNo: '',
@@ -168,6 +175,26 @@
  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)
@@ -227,7 +254,8 @@
  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
@@ -470,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;
src/pages/inventoryManagement/stockManagement/subtract.vue
@@ -14,7 +14,14 @@
        </view>
        <view class="form-row">
          <text class="form-label">单位</text>
          <up-input v-model="form.unit" disabled />
          <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>
@@ -22,7 +29,11 @@
        <view class="section-title">出库信息</view>
        <view class="form-row">
          <text class="form-label">出库数量</text>
          <up-input v-model="form.stockOutNum" type="number" :placeholder="'最大' + (form.unLockedQuantity ?? 0)" />
          <up-input
            v-model="form.stockOutNum"
            type="number"
            :placeholder="'最大' + maxOutQuantity"
          />
        </view>
        <view class="form-row">
          <text class="form-label">备注</text>
@@ -52,7 +63,7 @@
  parentName: '',
  productName: '',
  model: '',
  unit: '',
  unit: '吨',
  qualitity: undefined,
  lockedQuantity: undefined,
  unLockedQuantity: undefined,
@@ -69,6 +80,45 @@
})
const type = ref('0') // 固定合格库存
const unitOptions = [
  { label: '吨', value: '吨' },
  { label: '公斤', value: '公斤' }
]
// 记录的原始单位,用于吨/公斤换算校验“最大可出库数量”
const recordUnit = ref('')
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 convertByUnit = (value, fromUnit, toUnit) => {
  if (value === '' || value === undefined || value === null) return 0
  const num = Number(value)
  if (Number.isNaN(num)) return 0
  if (fromUnit === toUnit) return num
  // 默认只处理吨<->公斤;其他单位直接原样返回
  if (fromUnit === '吨' && toUnit === '公斤') return num * 1000
  if (fromUnit === '公斤' && toUnit === '吨') return num / 1000
  return num
}
const maxOutQuantity = computed(() => {
  const baseMax = Number(form.unLockedQuantity ?? 0)
  if (!recordUnit.value || !form.unit) return baseMax
  return convertByUnit(baseMax, recordUnit.value, form.unit)
})
onLoad((options) => {
  type.value = '0'
@@ -79,6 +129,9 @@
      const item = payload && payload.item ? payload.item : payload
      // 将列表记录的完整字段拷贝到表单中,保持与 PC 端 Subtract.vue 一致
      Object.assign(form, item)
      const normalizedUnit = normalizeUnit(form.unit)
      form.unit = normalizedUnit === '吨' || normalizedUnit === '公斤' ? normalizedUnit : '吨'
      recordUnit.value = form.unit
      uni.removeStorageSync('stockSubtractRecord')
    } catch (e) {
      uni.removeStorageSync('stockSubtractRecord')
@@ -91,8 +144,11 @@
    uni.showToast({ title: '记录信息缺失,无法出库', icon: 'none' })
    return
  }
  const normalizedUnit = normalizeUnit(form.unit)
  form.unit = normalizedUnit === '吨' || normalizedUnit === '公斤' ? normalizedUnit : '吨'
  const outNum = Number(form.stockOutNum)
  const max = Number(form.unLockedQuantity ?? 0)
  const max = Number(maxOutQuantity.value ?? 0)
  if (!outNum || outNum <= 0 || outNum > max) {
    uni.showToast({ title: `请输入 1~${max} 之间的数量`, icon: 'none' })
    return
@@ -100,7 +156,8 @@
  const payload = {
    id: form.id,
    stockOutNum: outNum,
    remark: form.remark
    remark: form.remark,
    unit: form.unit
  }
  subtractStockInventory(payload)
    .then(() => {
@@ -181,5 +238,11 @@
  align-items: center;
  justify-content: center;
}
.unit-radio-group {
  display: flex;
  gap: 24rpx;
  align-items: center;
  flex-wrap: wrap;
}
</style>