Blame view

src/components/car/importOwnerCar.vue 2.98 KB
6ec243d6   wuxw   v1.9 点击提交后,成功提示没有...
1
  <template>
eafabeed   wuxw   开发完成业主车辆
2
    <el-dialog :title="$t('listOwnerCar.importCarTitle')" :visible.sync="visible" width="600px" @close="resetForm">
963f5a4f   wuxw   车辆功能测试完成
3
      <el-form :model="form" label-width="120px" class="text-left">
eafabeed   wuxw   开发完成业主车辆
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
        <el-form-item :label="$t('listOwnerCar.selectFile')">
          <el-upload class="upload-demo" action="" :on-change="handleFileChange" :auto-upload="false"
            :show-file-list="false">
            <el-button size="small" type="primary">{{ $t('listOwnerCar.selectFile') }}</el-button>
            <div slot="tip" class="el-upload__tip">
              {{ fileName || $t('listOwnerCar.fileRequired') }}
            </div>
          </el-upload>
        </el-form-item>
  
        <el-form-item :label="$t('listOwnerCar.downloadTemplate')">
          <div>
            {{ $t('listOwnerCar.downloadFirst') }}
            <el-link type="primary" href="/import/importCar.xlsx" target="_blank">
              {{ $t('listOwnerCar.importTemplate') }}
            </el-link>
            <span>{{ $t('listOwnerCar.prepareData') }}</span>
          </div>
        </el-form-item>
      </el-form>
  
      <div slot="footer" class="dialog-footer">
        <el-button @click="visible = false">{{ $t('common.cancel') }}</el-button>
        <el-button type="primary" @click="importData" :loading="loading">
          {{ $t('listOwnerCar.import') }}
        </el-button>
      </div>
    </el-dialog>
  </template>
  
  <script>
  import { importData } from '@/api/car/listOwnerCarApi'
  
  export default {
    name: 'ImportOwnerCar',
    data() {
      return {
        visible: false,
        loading: false,
        file: null,
        fileName: ''
      }
    },
    methods: {
      open() {
        this.visible = true
      },
  
      handleFileChange(file) {
        this.file = file.raw
        this.fileName = file.name
      },
  
      async importData() {
        if (!this.file) {
          this.$message.warning(this.$t('listOwnerCar.fileRequired'))
          return
        }
  
        if (!this.checkFileType(this.fileName)) {
          this.$message.warning(this.$t('listOwnerCar.invalidExcel'))
          return
        }
  
        if (!this.checkFileSize(this.file.size)) {
          this.$message.warning(this.$t('listOwnerCar.fileSizeExceed'))
          return
        }
  
        this.loading = true
        try {
          const response = await importData({
            file: this.file,
            importAdapt: 'importOwnerCar'
          })
  
6ec243d6   wuxw   v1.9 点击提交后,成功提示没有...
80
          this.$message.success(this.$t('common.operationSuccess'))
eafabeed   wuxw   开发完成业主车辆
81
82
          this.$emit('success')
          this.visible = false
27dcfde5   wuxw   系统全面测试完成
83
          this.$router.push(`/views/system/assetImportLogDetail?logId=${response.logId}&logType=importOwnerCar`)
eafabeed   wuxw   开发完成业主车辆
84
85
        } catch (error) {
          console.error('导入失败:', error)
35126b43   wuxw   v1.9 修复车辆导入 报错提示不...
86
          this.$message.error(error )
eafabeed   wuxw   开发完成业主车辆
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
        } finally {
          this.loading = false
        }
      },
  
      checkFileType(fileName) {
        const ext = fileName.split('.').pop().toLowerCase()
        return ['xlsx', 'xls'].includes(ext)
      },
  
      checkFileSize(size) {
        const maxSize = 2 * 1024 * 1024 // 2MB
        return size <= maxSize
      },
  
      resetForm() {
        this.file = null
        this.fileName = ''
      }
    }
  }
  </script>