zhangwencui
18 小时以前 b7ddb64be82d402dca628e92fa432558fd712289
src/views/safeProduction/hazardousMaterialsControl/index.vue
@@ -244,9 +244,9 @@
      </el-form>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="dialogVisible = false">取消</el-button>
          <el-button type="primary"
                     @click="submitForm">确定</el-button>
          <el-button @click="dialogVisible = false">取消</el-button>
        </span>
      </template>
    </el-dialog>
@@ -258,9 +258,14 @@
      <div>
        <el-table :data="safeHazardList"
                  border
                  ref="safeHazardTableRef"
                  v-loading="safeHazardLoading"
                  style="width: 100%"
                  @row-click="handleSafeHazardSelect">
                  :selection="selectedSafeHazardIds"
                  @selection-change="handleSafeHazardSelectionChange"
                  style="width: 100%">
          <el-table-column type="selection"
                           width="55"
                           :selectable="isSelectable" />
          <el-table-column prop="code"
                           label="危险源编码"
                           width="180"
@@ -302,6 +307,8 @@
      </div>
      <template #footer>
        <span class="dialog-footer">
          <el-button type="primary"
                     @click="handleSafeHazardSelect">确定</el-button>
          <el-button @click="safeHazardSelectVisible = false">取消</el-button>
        </span>
      </template>
@@ -541,11 +548,17 @@
    }
  };
  const handleApplyQtyChange = () => {
    if (Number(form.value.applyQty) < 0) {
      ElMessage.error("领用数量不能小于0");
      form.value.applyQty = 0;
      return;
    }
    if (form.value.applyQty > valueItem.value.stockQty) {
      ElMessage.error("领用数量不能大于库存数量");
      form.value.applyQty = "";
    }
  };
  const selectedSafeHazardIds = ref([]);
  // 开始自动刷新
  const startAutoRefresh = () => {
@@ -580,7 +593,7 @@
  const fetchSafeHazardList = () => {
    safeHazardLoading.value = true;
    return safeHazardListPage({
      page: safeHazardPage.value.current,
      current: safeHazardPage.value.current,
      size: safeHazardPage.value.size,
    })
      .then(res => {
@@ -592,12 +605,36 @@
      });
  };
  const handleSafeHazardSelect = item => {
  const isSelectable = row => {
    // 只有库存数量大于0的行才能被选择
    return Number(row.stockQty) > 0;
  };
  const handleSafeHazardSelectionChange = selection => {
    // 只保留最后一个选中的项
    if (selection.length > 1) {
      const lastSelected = selection[selection.length - 1];
      selectedSafeHazardIds.value = [lastSelected];
      proxy.$refs.safeHazardTableRef.clearSelection();
      proxy.$refs.safeHazardTableRef.toggleRowSelection(lastSelected, true);
    } else if (selection.length === 1) {
      selectedSafeHazardIds.value = [selection[0]];
    } else {
      selectedSafeHazardIds.value = [];
    }
  };
  const handleSafeHazardSelect = () => {
    if (!selectedSafeHazardIds.value.length) {
      ElMessage.error("请选择一个危险源");
      return;
    }
    valueItem.value = {
      ...item,
      ...selectedSafeHazardIds.value[0],
    };
    valueItem.value.type = getTypeLabel(valueItem.value.type);
    form.value.safeHazardId = item.id;
    form.value.safeHazardId = selectedSafeHazardIds.value[0].id;
    safeHazardSelectVisible.value = false;
  };
@@ -616,7 +653,15 @@
  // 选择变化处理
  const handleSelectionChange = selection => {
    selectedIds.value = selection.map(item => item.id);
    // 主表格也只保留最后一个选中的项
    if (selection.length > 1) {
      const lastSelected = selection[selection.length - 1];
      selectedIds.value = [lastSelected.id];
    } else if (selection.length === 1) {
      selectedIds.value = [selection[0].id];
    } else {
      selectedIds.value = [];
    }
  };
  // 打开表单
@@ -741,7 +786,7 @@
          .catch(err => {
            ElMessage.error(err.msg);
          });
      } else {
      } else if (dialogType.value === "edit") {
        await formRef1.value.validate();
        safeHazardRecordUpdate({ ...form.value })
          .then(res => {
@@ -754,6 +799,9 @@
          .catch(err => {
            ElMessage.error(err.msg);
          });
      } else if (dialogType.value === "view") {
        // 查看模式下不提交表单
        dialogVisible.value = false;
      }
    } catch (error) {
      console.error("表单验证失败:", error);