spring
2026-05-20 7465eb431e134576b4c9c43103c9fc6f918d1696
src/views/productionManagement/workOrder/components/GranulationForm.vue
@@ -1,5 +1,5 @@
<script setup lang="ts">
import {computed, onMounted, reactive, ref} from "vue";
import {computed, onMounted, reactive, ref, watch} from "vue";
import {userListNoPageByTenantId} from "@/api/system/user.js";
import {ElMessage} from "element-plus";
import {addProductMain} from "@/api/productionManagement/workOrder.js";
@@ -20,7 +20,12 @@
  row: {
    type: Object,
    default: () => ({}),
  }
  },
  /** 工单 BOM 投入重量,回显到「投入重量」 */
  bomInputQty: {
    type: Number,
    default: null,
  },
});
const emits = defineEmits(["update:isShow", "refreshData"]);
@@ -121,6 +126,7 @@
      confirmName: undefined,
    },
    remark: undefined, // 备注
    inputWeight: undefined, // 投入重量(KG)
  }
})
@@ -228,10 +234,29 @@
  });
};
const resolveBomInputQty = () => {
  const bom = props.bomInputQty ?? props.row?.bomInputQty;
  if (bom === null || bom === undefined || bom === "") {
    return null;
  }
  const n = Number(bom);
  return Number.isFinite(n) ? n : null;
};
const applyBomInputWeight = () => {
  const n = resolveBomInputQty();
  if (n !== null) {
    formData.otherData.inputWeight = n;
  }
};
const initData = () => {
  if (!props.isEdit) {
    formData.otherData = JSON.parse(props.row.otherData || '{}');
    formData.quantity = props.row.quantity;
    if (formData.otherData.inputWeight === undefined || formData.otherData.inputWeight === null || formData.otherData.inputWeight === "") {
      applyBomInputWeight();
    }
  } else {
    const row = props.row;
    formData.planQuantity = row.planQuantity
@@ -239,8 +264,32 @@
    formData.workOrderId = row.id
    formData.reportWork = row.reportWork
    formData.productMainId = row.productMainId
    applyBomInputWeight();
  }
}
watch(
  () => props.isShow,
  (show) => {
    if (show) {
      initData();
    }
  }
);
watch(
  () => [props.bomInputQty, props.row?.bomInputQty],
  () => {
    if (!props.isShow) return;
    if (props.isEdit) {
      applyBomInputWeight();
      return;
    }
    if (formData.otherData.inputWeight === undefined || formData.otherData.inputWeight === null || formData.otherData.inputWeight === "") {
      applyBomInputWeight();
    }
  }
);
const displayValue = (value: any) => {
  return value === undefined || value === null || value === "" ? "-" : value;
@@ -771,7 +820,7 @@
          </td>
        </tr>
        <tr>
          <td class="label"  colspan="2" rowspan="4">造粒</td>
          <td class="label"  colspan="2" rowspan="5">造粒</td>
          <td class="label"  colspan="6">
            <span>开始时间:</span>
            <el-date-picker
@@ -836,6 +885,19 @@
          </td>
        </tr>
        <tr>
          <td colspan="12">
            <span>投入重量(KG):</span>
            <el-input-number
                v-if="props.isEdit"
                v-model="formData.otherData.inputWeight"
                :controls="false"
                style="width: 100%"
                placeholder="请输入"
            />
            <span v-else class="view-value">{{ displayValue(formData.otherData.inputWeight) }}</span>
          </td>
        </tr>
        <tr>
          <td class="label" colspan="6">
            <span>产出总数 :</span>
            <el-input  v-if="props.isEdit" v-model="formData.quantity" placeholder="请输入">