tuqin
2026-09-24 dc3fc550fe292043cc452dc9aeb0c8a1eeab3b30
src/views/inventoryManagement/receiptManagement/Record.vue
@@ -84,6 +84,10 @@
                 @click="handleBatchApprove">审批</el-button>
      <el-button :disabled="!canReverseApprove"
                 @click="handleReverseApprove">反审</el-button> -->
      <el-button type="info"
                 plain
                 icon="Upload"
                 @click="handleImport">导入</el-button>
      <el-button @click="handleOut">导出</el-button>
      <el-button type="danger"
                 plain
@@ -173,6 +177,42 @@
                  :limit="page.size"
                  @pagination="pageProductChange"/>
    </div>
    <!-- 入库导入对话框 -->
    <el-dialog :title="upload.title"
               v-model="upload.open"
               width="400px"
               append-to-body>
      <el-upload ref="uploadRef"
                 :limit="1"
                 accept=".xlsx, .xls"
                 :headers="upload.headers"
                 :action="upload.url"
                 :disabled="upload.isUploading"
                 :on-progress="handleFileUploadProgress"
                 :on-success="handleFileSuccess"
                 :on-error="handleFileError"
                 :auto-upload="false"
                 drag>
        <el-icon class="el-icon--upload"><upload-filled /></el-icon>
        <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
        <template #tip>
          <div class="el-upload__tip text-center">
            <span>仅允许导入 xls、xlsx 格式文件。</span>
            <el-link type="primary"
                     :underline="false"
                     style="font-size: 12px; vertical-align: baseline"
                     @click="importTemplate">下载模板</el-link>
          </div>
        </template>
      </el-upload>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary"
                     @click="submitFileForm">确 定</el-button>
          <el-button @click="upload.open = false">取 消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>
@@ -198,6 +238,7 @@
  // findAllUnQualifiedStockInRecordTypeOptions,
} from "@/api/basicData/enum.js";
import { parseTime } from "@/utils/ruoyi";
import { getToken } from "@/utils/auth.js";
const {proxy} = getCurrentInstance();
@@ -454,6 +495,55 @@
      });
};
// 导入
const uploadRef = ref();
const upload = reactive({
  open: false,
  title: "",
  isUploading: false,
  headers: { Authorization: "Bearer " + getToken() },
  url: import.meta.env.VITE_APP_BASE_API + "/stockInRecord/import?type=" + props.type,
});
const handleImport = () => {
  upload.title = "入库导入";
  upload.open = true;
};
const importTemplate = () => {
  proxy.download("/stockInRecord/importTemplate", {}, "入库导入模板.xlsx");
};
const submitFileForm = () => {
  upload.isUploading = true;
  uploadRef.value.submit();
};
const handleFileUploadProgress = () => {
  upload.isUploading = true;
};
const handleFileSuccess = (response) => {
  upload.isUploading = false;
  upload.open = false;
  uploadRef.value.clearFiles();
  if (response.code === 200) {
    const failCount = response.failCount || 0;
    if (failCount > 0) {
      const errors = Array.isArray(response.errors) ? response.errors : [];
      proxy.$modal.alert(`${response.msg}\n\n${errors.join("\n")}`, "导入结果", {
        confirmButtonText: "知道了",
      }).then(() => {
        getList();
      });
    } else {
      proxy.$modal.msgSuccess(response.msg || "导入成功");
      getList();
    }
  } else {
    proxy.$modal.msgError(response.msg || "导入失败");
  }
};
const handleFileError = () => {
  upload.isUploading = false;
  proxy.$modal.msgError("文件上传失败");
};
onMounted(() => {
  getList();
  fetchStockRecordTypeOptions();