spring
17 小时以前 5a6097ab668b63dc332bac14c700dcd79abb826e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<template>
  <el-dialog  v-model="isShow" title="导入库存" @close="closeModal">
    <FileUpload
      ref="fileUploadRef"
      accept=".xlsx, .xls"
      :headers="upload.headers"
      :action="upload.url"
      :disabled="upload.isUploading"
      :showTip="true"
      @success="handleFileSuccess"
    />
    <template #footer>
      <div class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="closeModal">取 消</el-button>
      </div>
    </template>
  </el-dialog>
</template>
 
<script setup>
import {computed, reactive} from "vue";
import { getToken } from "@/utils/auth.js";
import { FileUpload } from "@/components/Upload";
import { ElMessage } from "element-plus";
 
defineOptions({
  name: "导入库存",
});
 
const props = defineProps({
  visible: {
    type: Boolean,
    required: true,
  },
 
  type: {
    type: String,
    required: true,
    default: 'qualified',
  },
});
 
const emit = defineEmits(['update:visible', 'uploadSuccess']);
 
 
const isShow = computed({
  get() {
    return props.visible;
  },
  set(val) {
    emit('update:visible', val);
  },
});
 
const fileUploadRef = ref();
const upload = reactive({
  // 是否显示弹出层(库存导入)
  open: false,
  // 是否禁用上传
  isUploading: false,
  // 设置上传的请求头部
  headers: { Authorization: "Bearer " + getToken() },
  // 上传的地址
  url: import.meta.env.VITE_APP_BASE_API + "/stockInventory/importStockInventory",
});
 
const submitFileForm = () => {
  fileUploadRef.value.uploadApi();
};
 
const handleFileSuccess = (response) => {
  const { code, msg } = response;
  if (code == 200) {
    ElMessage({ message: "导入成功", type: "success" });
    emit('uploadSuccess');
    closeModal();
  } else {
    ElMessage({ message: msg, type: "error" });
  }
};
 
const closeModal = () => {
  isShow.value = false;
};
</script>