WXL
2025-02-12 f6bc6ed2dec9cd60853db928fa6e56a92ab5de0d
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
<template>
  <div>
    <UploadExcel :deforeUpload="excelSuccess" :onSuccess="onSuccess" />
  </div>
</template>
 
<script>
//等待api接口
// import { importEmployee } from "@/api/index";
import employees from "@/constant/employees";
import formatTime from "@/filters/index";
const { importMapKeyPath } = employees;
export default {
  data() {
    return {};
  },
 
  created() {},
 
  methods: {
    // 上传前触发
    excelSuccess({ name }) {
      if (!name.endsWith(".xlsx")) {
        return this.$message("请选择xlsx文件");
      }
      return true;
    },
    // 解析成功后触发
    async onSuccess({ results, header }) {
      const neWArr = results.map((item) => {
        const obj = {};
        for (let key in importMapKeyPath) {
          if (key === "入职时间" || key === "转正时间") {
            // excel时间戳
            const timestamp = item[key];
            // 转格式,并对比效验差时间
            const date = new Date((timestamp - 1) * 24 * 3600000);
            date.setFullYear(data.setFullYear() - 70);
            obj[importMapKeyPath[key]] = formatTime(date);
          } else {
            obj[importMapKeyPath[key]] = item[key];
          }
        }
        return obj;
      });
      // await importEmployee(neWArr);
      this.$message.success("导入成功");
      this.$router.go(-1);
      console.log(neWArr);
    },
  },
};
</script>
 
<style lang="scss" scoped></style>