haoxuan
2024-04-25 5aa07c5cfe96b928f1371d34d0af44890fbf7cd7
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<template>
  <el-dialog
    :close-on-click-modal="false"
    :visible.sync="isopen"
    width="28rem"
    class="add-event-dialog"
    @close="shutdown"
  >
    <div slot="title" class="tac drawerHeader">{{ title }}</div>
    <div class="dialog-content-box">
      <el-form ref="form" :rules="rules" :model="form" label-width="110px">
        <el-form-item label="上传考勤:" prop="doc" class="down-box">
          <uploadImportBtn
            ref="mychild"
            buttonText="上传"
            name="processModel"
            :isFileListShow="true"
            :continueImport="continueImport"
            :importObj="importObj"
            @fileSuccess="fileSuccess"
            @remove="remove"
          >
        </uploadImportBtn>
        <span class="margin_left_20px cursor_pinter down-btn color_blue" @click="downHttpClick"><i class="el-icon-download"></i>下载模板</span>
        </el-form-item>
      </el-form>
    </div>
    <div slot="footer" class="dialog-footer tac">
      <el-button @click="shutdown">取消</el-button>
 
      <el-button @click="onSubmit" type="primary">确定</el-button>
    </div>
  </el-dialog>
</template>
 
<script>
import { attendanceInput,getTemplate } from "@/api/employeeSalary/attendanceManage.js"
import uploadImportBtn from "@/components/common/uploadImportBtn";
export default {
  components: {
    uploadImportBtn,
  },
  props: ["title"],
  data() {
    return {
      form: {
        doc: null,
        doc2: null,
      },
      rules: {
        doc: [{ required: true, message: "请上传", trigger: "change" }],
      },
      isopen: false,
      // 上传
      continueImport: false, //是否继续上传
      continueImport2: false, //是否继续上传
 
      importObj: {
        suffix: "xlsx",
        size: 20,
        num: 1,
      },
    };
  },
  mounted() {},
  watch: {
    isopen(val) {
      if (val) {
        this.form.doc = null;
        this.form.doc2 = null;
        this.$nextTick(()=>{
          this.$refs.form.resetFields();
        })
      }
    },
  },
  methods: {
    //导入成功
    fileSuccess(fd, file) {
      this.continueImport = true;
      this.form.doc = file;
    },
    shutdown() {
      this.isopen = false;
      this.$refs.mychild.remove(0);
      this.$emit("fileSuccess", this.form);
    },
    remove(){
      this.continueImport = false;
      this.form.doc = null;
      this.$refs.mychild.remove(0);
    },
    downHttpClick(){
      getTemplate({category:13}).then(res=>{
        if (res.code === 200) {
          const fileUrl = res.data[0].fileUrl;
          const downloadLink = document.createElement("a");
          downloadLink.href = fileUrl;
          downloadLink.download = "模板.excel";
          document.body.appendChild(downloadLink);
          downloadLink.click();
          this.$message.success("模板下载成功!");
        }
      });
    },
    onSubmit() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          let fd = new FormData(); // 创建form对象
          fd.append("file", this.form.doc.raw); // file对象是 beforeUpload参数
          // fd.append('file2', this.form.doc2.raw)  // file对象是 beforeUpload参数
 
          attendanceInput(fd).then((res) => {
            if (res.code == 200) {
              this.$message.success("上传成功!");
              this.shutdown();
            }
          });
        } else {
          this.$message.error("请上传!");
        }
      });
    },
  },
};
</script>
 
<style lang="scss" scoped>
/* .title {
  font-size: 13px;
  line-height: 18px;
  color: #2a78fb;
} */
.dialog-content-box {
  height: 17rem;
  min-height: 110px;
  overflow: auto;
}
::v-deep .el-select-dropdown__wrap {
  overflow: auto !important;
}
 
::v-deep .el-select-dropdown {
  position: absolute !important;
  top: 36px !important;
  left: 0px !important;
}
.down-box{
  position:relative;
  .down-btn{
    position:absolute;
    left:90px;
    top:0;
  }
}
</style>