doum
8 天以前 e46bfa3ff94a8a1b4daf37c7fcb79c2fab22a72c
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
      class="center-title"
      :title="title"
      width="500px"
      top="30vh"
      :visible.sync="visible"
      :confirm-working="isWorking"
      @confirm="confirm"
  >
    <p class="tip-warn"><i class="el-icon-warning"></i>导入说明:<br>
      1.请先下载文件模板,并按照模板要求填写表格内容;<br>
      2.带*为必填项,关联房源格式为:楼宇/楼层/房源;<br>
      3.设备分类格式为:一级分类/二级分类;<br>
    </p>
    <el-form class="demo-form-inline">
      <el-form-item label="设备名单" required>
        <div style="width: 100%;display: flex;align-items: center;">
          <el-button type="primary" @click="clickRef">点击上传</el-button>
          <el-button type="text" @click="exportTemplate">点击下载模版.EXCEL</el-button>
        </div>
        <div style="font-size: 14px; color: black;" v-if="fileName">{{ fileName }}</div>
      </el-form-item>
    </el-form>
    <input type="file" style="position: fixed; left: 0; top: -50px;" accept=".xlsx" ref="fileExcel" @change="result" />
    <template v-slot:footer>
      <el-button @click="visible=false">返回</el-button>
    </template>
  </el-dialog>
</template>
 
<script>
import BaseOpera from '@/components/base/BaseOpera'
import GlobalWindow from '@/components/common/GlobalWindow'
import { importExcel } from '@/api/Inspection/device'
export default {
  name: 'OperaDeviceImportWindow',
  extends: BaseOpera,
  // eslint-disable-next-line vue/no-unused-components
  components: { GlobalWindow },
  data () {
    return {
      importing: false,
      fileName: ''
    }
  },
  methods: {
    open (title) {
      this.title = title
      this.fileName = ''
      this.visible = true
    },
    exportTemplate () {
      window.open('/template/yw_device.xlsx')
    },
    clickRef () {
      this.$refs.fileExcel.click()
    },
    result (e) {
      const file = e.target.files[0]
      if (!file) {
        return
      }
      this.fileName = file.name
      const data = new FormData()
      data.append('file', file)
      importExcel(data)
        .then(res => {
          this.$message.success(res || '操作成功')
          this.$emit('success')
          this.visible = false
        })
        .catch(() => {
          this.fileName = ''
        })
        .finally(() => {
          this.$refs.fileExcel.value = null
        })
    }
  }
}
</script>
 
<style lang="scss" scoped>
 
</style>