pan
2025-11-30 dcdb87f1cb6cfd66d3fc01bc2248e4876c37f223
ÏîÄ¿´úÂë/WIDESEA_WMSClient/src/extension/outbound/extend/NoStockOut.vue
@@ -5,29 +5,63 @@
      :lazy="true"
      width="65%"
      :padding="20"
      title="无库存出库"
      title="虚拟出入库"
      class="custom-vol-box"
    >
      <div>
        <!-- å•据输入区域(支持扫码) -->
        <el-form :inline="true" :model="orderForm" style="margin-bottom: 20px; align-items: flex-end;">
          <el-form-item label="出库单据:" name="outboundOrderNo">
            <el-input
              v-model="orderForm.outboundOrderNo"
              placeholder="请输入或扫描出库单据号"
              clearable
              style="width: 220px; margin-right: 10px;"
              @input="handleOutboundInput"
              @keyup.enter="focusPurchaseInput"
              ref="outboundInputRef"
            ></el-input>
          </el-form-item>
          <el-form-item label="采购单据:" name="purchaseOrderNo">
            <el-input
              v-model="orderForm.purchaseOrderNo"
              placeholder="请输入或扫描采购单据号"
              clearable
              style="width: 220px; margin-right: 10px;"
              @input="handlePurchaseInput"
              @keyup.enter="focusBarcodeInput"
              ref="purchaseInputRef"
            ></el-input>
          </el-form-item>
        </el-form>
        <!-- ä¸Šæ–¹è¾“入框 -->
        <el-form :inline="true" :model="formData" ref="formData" style="margin-bottom: 20px; align-items: flex-end;">
        <el-form :inline="true" :model="formData" ref="formRef" style="margin-bottom: 20px; align-items: flex-end;">
          <el-form-item
            label="扫描条码:"
            style="width: 80%"
            prop="barcode"
            name="barcode"
            :rules="[{ required: true, message: '请扫描或输入条码', trigger: 'blur' }]"
          >
            <el-input
              ref="barcodeInput"
              ref="barcodeInputRef"
              v-model="formData.barcode"
              placeholder="请使用扫码枪扫描条码,或手动输入"
              @keyup.enter="handleScan"
              autofocus
              class="custom-input"
              :disabled="!orderForm.outboundOrderNo || !orderForm.purchaseOrderNo"
            ></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" size="small" @click="handleScan" class="custom-button">
              <i class="el-icon-search"></i> ç¡®è®¤æ‰«æ
            <el-button
              type="primary"
              size="small"
              @click="handleScan"
              class="custom-button"
              :disabled="!orderForm.outboundOrderNo || !orderForm.purchaseOrderNo || loading"
            >
              <Search /> ç¡®è®¤æ‰«æ
            </el-button>
          </el-form-item>
        </el-form>
@@ -37,27 +71,23 @@
          <el-card shadow="hover" style="margin-bottom: 10px; border: none;" class="custom-card">
            <div class="card-header">
              <span class="header-title">已扫描条码列表(共{{ scannedBarcodes.length }}条)</span>
              <el-button
                class="clear-all-btn"
                @click="clearAll"
                :disabled="scannedBarcodes.length === 0"
              >清空所有</el-button>
            </div>
            <div class="card-body">
              <el-scrollbar height="400px" class="custom-scrollbar">
                <!-- ä½¿ç”¨ transition-group åŒ…裹以实现动画 -->
                <transition-group name="barcode-item-transition">
                  <div class="barcode-item" v-for="(barcode, index) in scannedBarcodes" :key="barcode" :data-index="index">
                    <span class="barcode-text">{{ index + 1 }}. {{ barcode }}</span>
                  <div class="barcode-item" v-for="(item, index) in scannedBarcodes" :key="item.barcode" :data-index="index">
                    <span class="barcode-text">{{ index + 1 }}. {{ item.barcode }}</span>
                    <el-button
                      class="delete-btn"
                      @click="removeItem(index)"
                    >删除</el-button>
                      @click="removeItem(index, item.barcode)"
                      icon="Delete"
                      circle
                      :disabled="loading"
                    ></el-button>
                  </div>
                </transition-group>
                <div class="empty-tip" v-if="scannedBarcodes.length === 0">
                  <i class="el-icon-information"></i>
                  <span>暂无扫描记录,请扫描条码</span>
                  <span>暂无扫描记录,请先输入单据后扫描条码</span>
                </div>
              </el-scrollbar>
            </div>
@@ -67,10 +97,16 @@
      <template #footer>
        <div class="footer-actions">
          <el-button type="primary" size="small" @click="submit" :disabled="scannedBarcodes.length === 0" class="submit-btn">
            <i class="el-icon-check"></i> æäº¤å‡ºåº“
          <el-button
            type="primary"
            size="small"
            @click="submit"
            :disabled="scannedBarcodes.length === 0 || !orderForm.outboundOrderNo || !orderForm.purchaseOrderNo || loading"
            class="submit-btn"
          >
            <Check /> æäº¤å‡ºåº“
          </el-button>
          <el-button type="text" size="small" @click="showDetailBox = false" class="cancel-btn">
          <el-button type="text" size="small" @click="showDetailBox = false" class="cancel-btn" :disabled="loading">
            å–消
          </el-button>
        </div>
@@ -79,99 +115,180 @@
  </div>
</template>
<script>
<script setup>
import { ref, reactive, onMounted, nextTick } from 'vue';
import { ElMessage } from 'element-plus';
import { Search } from '@element-plus/icons-vue';
import VolBox from "@/components/basic/VolBox.vue";
import http from '@/api/http';
export default {
  components: { VolBox },
  data() {
    return {
      showDetailBox: false,
      formData: {
        barcode: "",
      },
      scannedBarcodes: [],
    };
  },
  methods: {
    open() {
      this.showDetailBox = true;
      this.scannedBarcodes = [];
      this.formData.barcode = "";
      this.$nextTick(() => {
        this.$refs.barcodeInput.focus();
      });
    },
// å“åº”式数据
const showDetailBox = ref(false);
const orderForm = reactive({
  outboundOrderNo: "",
  purchaseOrderNo: ""
});
const formData = reactive({
  barcode: "",
});
const scannedBarcodes = ref([]);
const loading = ref(false);
    handleScan() {
      const barcode = this.formData.barcode.trim();
      if (!barcode) {
        this.$refs.barcodeInput.focus();
        return;
      }
      if (this.scannedBarcodes.includes(barcode)) {
        this.$message.warning(`条码 ${barcode} å·²æ‰«æè¿‡ï¼Œè¯·å‹¿é‡å¤æ‰«æ`);
        this.formData.barcode = "";
        this.$refs.barcodeInput.focus();
        return;
      }
// æ¨¡æ¿å¼•用
const formRef = ref(null);
const barcodeInputRef = ref(null);
const outboundInputRef = ref(null);
const purchaseInputRef = ref(null);
      this.scannedBarcodes.push(barcode);
      this.formData.barcode = "";
// ç»„件挂载时聚焦到出库单输入框
onMounted(() => {
  nextTick(() => {
    outboundInputRef.value?.focus();
  });
});
      this.$nextTick(() => {
        this.$refs.barcodeInput.focus();
      });
    },
    removeItem(index) {
      this.scannedBarcodes.splice(index, 1);
    },
    clearAll() {
      this.$confirm("确定要清空所有扫描记录吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        this.scannedBarcodes = [];
      }).catch(() => {
        this.$refs.barcodeInput.focus();
      });
    },
    submit() {
      if (this.scannedBarcodes.length === 0) {
        this.$message.warning("请先扫描至少一条条码");
        this.$refs.barcodeInput.focus();
        return;
      }
      const params = {
        barcodes: this.scannedBarcodes,
      };
      this.http
        .post("/api/OutboundOrder/NoStockOut", params, "数据处理中...")
        .then((res) => {
          if (!res.status) {
            this.$message.error(res.message);
            this.$refs.barcodeInput.focus();
            return;
          }
          this.$message.success("出库成功");
          this.showDetailBox = false;
          this.$emit("parentCall", ($vue) => {
            $vue.refresh();
          });
        })
        .catch((err) => {
          this.$message.error(`请求失败:${err.message || "未知错误"}`);
          this.$refs.barcodeInput.focus();
        });
    },
  },
// æ‰“开弹窗
const open = () => {
  showDetailBox.value = true;
  scannedBarcodes.value = [];
  formData.barcode = "";
  orderForm.outboundOrderNo = "";
  orderForm.purchaseOrderNo = "";
  nextTick(() => {
    outboundInputRef.value?.focus();
  });
};
// å‡ºåº“单输入处理(扫码或手动输入)
const handleOutboundInput = (value) => {
  // æ‰«ç æžªè¾“入通常会自动触发enter事件,这里主要处理手动输入的情况
  if (value && value.trim()) {
    // å¯ä»¥åœ¨è¿™é‡Œæ·»åŠ å‡ºåº“å•å·çš„æ ¼å¼éªŒè¯é€»è¾‘
  }
};
// é‡‡è´­å•输入处理(扫码或手动输入)
const handlePurchaseInput = (value) => {
  if (value && value.trim()) {
    // å¯ä»¥åœ¨è¿™é‡Œæ·»åŠ é‡‡è´­å•å·çš„æ ¼å¼éªŒè¯é€»è¾‘
  }
};
// ç„¦ç‚¹è·³è½¬å‡½æ•°
const focusPurchaseInput = () => {
  if (orderForm.outboundOrderNo.trim()) {
    purchaseInputRef.value?.focus();
  } else {
    ElMessage.warning("请先输入有效的出库单据号");
  }
};
const focusBarcodeInput = () => {
  if (orderForm.purchaseOrderNo.trim()) {
    barcodeInputRef.value?.focus();
  } else {
    ElMessage.warning("请先输入有效的采购单据号");
  }
};
// æ‰«ææ¡ç å¤„理
const handleScan = async () => {
  if (!formRef.value) return;
  await formRef.value.validateField('barcode');
  const barcode = formData.barcode.trim();
  if (scannedBarcodes.value.some(item => item.barcode === barcode)) {
    ElMessage.warning(`条码 ${barcode} å·²æ‰«æè¿‡ï¼Œè¯·å‹¿é‡å¤æ‰«æ`);
    formData.barcode = "";
    nextTick(() => barcodeInputRef.value?.focus());
    return;
  }
  try {
    loading.value = true;
    // è¿™é‡Œä¿ç•™äº†åŽŸæœ‰çš„æ¡ç éªŒè¯æŽ¥å£ï¼Œä½ å¯ä»¥æ ¹æ®å®žé™…éœ€æ±‚ä¿®æ”¹æˆ–ä¿ç•™
    const res = await http.post("/api/OutboundPicking/BarcodeValidate", {
      outOder: orderForm.outboundOrderNo, // æ³¨æ„ï¼šè¿™é‡ŒçŽ°åœ¨ä¼ é€’çš„æ˜¯å•æ®å·å­—ç¬¦ä¸²ï¼Œè€Œä¸æ˜¯ID
      inOder: orderForm.purchaseOrderNo,  // æ³¨æ„ï¼šè¿™é‡ŒçŽ°åœ¨ä¼ é€’çš„æ˜¯å•æ®å·å­—ç¬¦ä¸²ï¼Œè€Œä¸æ˜¯ID
      barCode: barcode
    });
    if (res.status === true) {
      scannedBarcodes.value.push({ barcode });
      ElMessage.success("扫描成功");
      formData.barcode = "";
    } else {
      ElMessage.error("扫描失败:" + (res.message || '验证失败'));
    }
  } catch (error) {
    ElMessage.error("扫描验证异常:" + error.message);
  } finally {
    loading.value = false;
    nextTick(() => barcodeInputRef.value?.focus());
  }
};
// ç§»é™¤å•条扫描记录
const removeItem = async (index, barcode) => {
  try {
    loading.value = true;
    // è¿™é‡Œä¿ç•™äº†åŽŸæœ‰çš„åˆ é™¤æ¡ç æŽ¥å£ï¼Œä½ å¯ä»¥æ ¹æ®å®žé™…éœ€æ±‚ä¿®æ”¹æˆ–ä¿ç•™
    const res = await http.post("/api/OutboundPicking/DeleteBarcode", {
      outOder: orderForm.outboundOrderNo,
      inOder: orderForm.purchaseOrderNo,
      barCode: barcode
    });
    if (res.status === true) {
      scannedBarcodes.value.splice(index, 1);
      ElMessage.success("删除成功");
    } else {
      ElMessage.error("删除失败:" + (res.message || '删除失败'));
    }
  } catch (error) {
    ElMessage.error("删除条码异常:" + error.message);
  } finally {
    loading.value = false;
  }
};
// æäº¤å‡ºåº“
const submit = async () => {
  if (scannedBarcodes.value.length === 0) {
    ElMessage.warning("请先扫描至少一条条码");
    return;
  }
  const barcodes = scannedBarcodes.value.map(item => item.barcode);
  try {
    loading.value = true;
    // è¿™é‡Œä¿ç•™äº†åŽŸæœ‰çš„æäº¤æŽ¥å£ï¼Œæ³¨æ„å‚æ•°çŽ°åœ¨ä¼ é€’çš„æ˜¯å•æ®å·å­—ç¬¦ä¸²
    const res = await http.post("/api/OutboundPicking/NoStockOutSubmit", {
      OutOderSubmit: orderForm.outboundOrderNo,
      InOderSubmit: orderForm.purchaseOrderNo,
      BarCodeSubmit: barcodes
    });
    if (res.status === true) {
      ElMessage.success("出库提交成功");
      showDetailBox.value = false;
    } else {
      ElMessage.error("出库提交失败:" + (res.message || '提交失败'));
    }
  } catch (error) {
    ElMessage.error("出库提交异常:" + error.message);
  } finally {
    loading.value = false;
  }
};
// æš´éœ²ç»™çˆ¶ç»„件的方法
defineExpose({
  open
});
</script>
<style scoped>
@@ -219,31 +336,22 @@
  font-size: 15px;
  color: #333;
}
.clear-all-btn {
  color: #f56c6c;
  font-size: 13px;
  transition: color 0.2s;
}
.clear-all-btn:hover {
  color: #e53e3e;
  background: rgba(245, 108, 108, 0.1);
}
.card-body {
  padding: 0;
}
/* è‡ªå®šä¹‰æ»šåŠ¨æ¡ */
.custom-scrollbar ::v-deep .el-scrollbar__thumb {
.custom-scrollbar :deep(.el-scrollbar__thumb) {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 4px;
  width: 4px;
}
.custom-scrollbar ::v-deep .el-scrollbar__bar:hover .el-scrollbar__thumb {
.custom-scrollbar :deep(.el-scrollbar__bar:hover .el-scrollbar__thumb) {
  background: rgba(0, 0, 0, 0.3);
  width: 6px;
}
.custom-scrollbar ::v-deep .el-scrollbar__wrap {
.custom-scrollbar :deep(.el-scrollbar__wrap) {
  overflow-x: hidden;
}
@@ -260,7 +368,7 @@
}
/* ä¸ºå¥‡æ•°è¡Œæ·»åŠ è½»å¾®çš„èƒŒæ™¯è‰²ï¼Œå¢žå¼ºå¯è¯»æ€§ */
.barcode-item:nth-child(odd) {
  background-color: #e1e1e1;
  background-color: #f9f9f9;
}
.barcode-text {
  flex: 1;
@@ -274,16 +382,15 @@
.delete-btn {
  color: #ea1919;
  font-size: 20px;
  font-size: 16px;
  transition: all 0.2s;
  transform: scale(0.8);
  opacity: 0.7;
}
.barcode-item:hover .delete-btn {
  opacity: 1;
  transform: scale(1);
}
.delete-btn:hover {
  color: #f56c6c !important; /* ä½¿ç”¨ !important è¦†ç›– Element UI é»˜è®¤æ ·å¼ */
  color: #f56c6c !important;
  background: rgba(245, 108, 108, 0.1);
}
@@ -296,22 +403,22 @@
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 15px;
}
.empty-tip i {
  font-size: 40px;
  margin-bottom: 15px;
  color: #dcdfe6;
}
/* è‡ªå®šä¹‰è¾“入框 */
.custom-input ::v-deep .el-input__inner {
.custom-input :deep(.el-input__inner) {
  border-radius: 6px;
  border-color: #e4e7ed;
  transition: all 0.3s;
  height: 36px;
  line-height: 36px;
}
.custom-input ::v-deep .el-input__inner:focus {
.custom-input :deep(.el-input__inner:focus) {
  border-color: #409eff;
  box-shadow: 0 0 0 3px rgba(64, 158, 255, 0.1);
}
@@ -355,7 +462,7 @@
</style>
<style>
/* ... (全局样式部分保持不变) ... */
/* å…¨å±€æ ·å¼éƒ¨åˆ†ä¿æŒä¸å˜ */
.text-button:hover {
  background-color: #f0f9eb !important;
}