hutongqing
2024-11-20 0845150c79d1ebd664753931933e786ed8bd06c4
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
<template>
  <div>
    <vol-box
      v-model="showDetialBox"
      :lazy="true"
      :height="350"
      :width="600"
      :padding="15"
      title="设备协议信息-导入"
    >
      <upload-excel
        ref="upload_excel"
        :url="url"
        :template="template"
      ></upload-excel>
    </vol-box>
  </div>
</template>
    
    <script>
import VolBox from "@/components/basic/VolBox.vue";
import UploadExcel from "@/components/basic/UploadExcel.vue";
export default {
  components: { VolBox, UploadExcel },
  data() {
    return {
      showDetialBox: false,
      url: "",
      template: {
        url: "", //模板下载路径,如果没有模板路径,则不显示下载模板功能
        fileName: "设备协议信息导入模板", //下载模板的文件名
      },
    };
  },
  methods: {
    open() {
      this.template.url = `${this.http.ipAddress}api/DeviceProtocol/DownLoadTemplate`;
      this.url = `${this.http.ipAddress}api/DeviceProtocol/GetImportData`;
      this.showDetialBox = true;
      this.$nextTick(() => {
        this.$refs.upload_excel.upload = this.upload;
        console.log(this.$refs.upload_excel);
      });
    },
    upload() {
      console.log("upload");
      let _url = this.url;
      if (!_url) {
        return this.$Message.error("没有配置好Url");
      }
 
      if (!this.$refs.upload_excel.file) {
        return this.$Message.error("请选择文件");
      }
      var formData = new FormData();
      formData.append("fileInput", this.$refs.upload_excel.file);
      if (!this.$refs.upload_excel.importExcelBefore(formData)) {
        return;
      }
      this.$refs.upload_excel.loadingStatus = true;
      this.http.post(_url, formData).then(
        (x) => {
          // this.$refs.uploadFile.clearFiles();
          this.$refs.upload_excel.loadingStatus = false;
          this.$refs.upload_excel.file = null;
          if (x.status) {
            this.$emit("parentCall", ($vue) => {
              $vue.$refs.detail.rowData.push(...x.data);
            });
          }
 
          this.message = x.message;
          this.resultClass = x.status ? "v-r-success" : "v-r-error";
        },
        (error) => {
          this.$refs.upload_excel.loadingStatus = false;
        }
      );
    },
  },
  created() {},
};
</script>
    
    <style scoped>
.el-col {
  border-radius: 4px;
}
.grid-content {
  border-radius: 4px;
  min-height: 36px;
}
.content-text {
  display: flex;
  align-items: center;
  justify-content: center;
}
.left-text {
  display: flex;
  align-items: center;
  justify-content: flex-start;
}
</style>
    <style>
.el-table .warning-row {
  background: #fcf1e2;
}
 
.el-table .success-row {
  background: #f0f9eb;
}
 
.el-table .error-row {
  background: #fde2e2;
}
</style>