Blame view

src/components/room/importOwnerRoom.vue 3.53 KB
af1bcbd6   wuxw   房屋页面开发中
1
  <template>
81955f61   wuxw   优化房屋页面
2
3
    <el-dialog :title="$t('room.importOwnerRoom.title')" :visible.sync="visible" width="40%" :before-close="handleClose">
      <el-form ref="form" :model="form" label-width="120px" class="text-left">
af1bcbd6   wuxw   房屋页面开发中
4
        <el-form-item :label="$t('room.importOwnerRoom.selectFile')">
81955f61   wuxw   优化房屋页面
5
          <el-upload ref="upload" action="" :auto-upload="false" :on-change="handleFileChange" accept=".xls,.xlsx" class="margin-left">
af1bcbd6   wuxw   房屋页面开发中
6
7
8
9
10
11
            <el-button size="small" type="primary">{{ $t('room.importOwnerRoom.clickUpload') }}</el-button>
            <div slot="tip" class="el-upload__tip">
              {{ fileName || $t('room.importOwnerRoom.requiredFile') }}
            </div>
          </el-upload>
        </el-form-item>
81955f61   wuxw   优化房屋页面
12
  
af1bcbd6   wuxw   房屋页面开发中
13
        <el-form-item :label="$t('room.importOwnerRoom.downloadTemplate')">
81955f61   wuxw   优化房屋页面
14
          <span class="margin-left">{{ $t('room.importOwnerRoom.downloadFirst') }}</span>
af1bcbd6   wuxw   房屋页面开发中
15
16
17
18
19
20
          <el-link type="primary" :href="templateUrl" target="_blank">
            {{ $t('room.importOwnerRoom.propertyTemplate') }}
          </el-link>
          <span>{{ $t('room.importOwnerRoom.prepareData') }}</span>
        </el-form-item>
      </el-form>
81955f61   wuxw   优化房屋页面
21
  
af1bcbd6   wuxw   房屋页面开发中
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
      <span slot="footer" class="dialog-footer">
        <el-button @click="handleClose">{{ $t('common.cancel') }}</el-button>
        <el-button type="primary" @click="handleImport">{{ $t('common.import') }}</el-button>
      </span>
    </el-dialog>
  </template>
  
  <script>
  import { importOwnerRoom } from '@/api/room/importOwnerRoomApi'
  
  export default {
    name: 'ImportOwnerRoom',
    data() {
      return {
        visible: false,
        form: {
          communityId: this.getCommunityId(),
          file: null
        },
        fileName: '',
        templateUrl: '/import/importRoom.xlsx'
      }
    },
    methods: {
      open() {
        this.visible = true
        this.resetForm()
      },
      handleClose() {
        this.visible = false
        this.resetForm()
      },
      resetForm() {
        this.form.file = null
        this.fileName = ''
        if (this.$refs.upload) {
          this.$refs.upload.clearFiles()
        }
      },
      handleFileChange(file) {
        this.form.file = file.raw
        this.fileName = file.name
      },
      validate() {
        if (!this.form.file) {
          this.$message.error(this.$t('room.importOwnerRoom.fileRequired'))
          return false
        }
81955f61   wuxw   优化房屋页面
70
  
af1bcbd6   wuxw   房屋页面开发中
71
72
73
74
75
        const fileType = this.fileName.split('.').pop().toLowerCase()
        if (!['xls', 'xlsx'].includes(fileType)) {
          this.$message.error(this.$t('room.importOwnerRoom.invalidFormat'))
          return false
        }
81955f61   wuxw   优化房屋页面
76
  
af1bcbd6   wuxw   房屋页面开发中
77
78
79
80
        if (this.form.file.size > 2 * 1024 * 1024) {
          this.$message.error(this.$t('room.importOwnerRoom.fileSizeExceeded'))
          return false
        }
81955f61   wuxw   优化房屋页面
81
  
af1bcbd6   wuxw   房屋页面开发中
82
83
84
85
        return true
      },
      async handleImport() {
        if (!this.validate()) return
81955f61   wuxw   优化房屋页面
86
  
af1bcbd6   wuxw   房屋页面开发中
87
88
89
90
91
        try {
          const formData = new FormData()
          formData.append('uploadFile', this.form.file)
          formData.append('communityId', this.form.communityId)
          formData.append('importAdapt', 'importRoomOwner')
81955f61   wuxw   优化房屋页面
92
  
af1bcbd6   wuxw   房屋页面开发中
93
          const response = await importOwnerRoom(formData)
81955f61   wuxw   优化房屋页面
94
  
af1bcbd6   wuxw   房屋页面开发中
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
          if (response.code === 0) {
            this.$message.success(this.$t('room.importOwnerRoom.importSuccess'))
            this.handleClose()
            this.$router.push({
              path: '/property/assetImportLogDetail',
              query: {
                logId: response.data.logId,
                logType: 'importRoomOwner'
              }
            })
          } else {
            this.$message.error(response.msg || this.$t('room.importOwnerRoom.importFailed'))
          }
        } catch (error) {
          this.$message.error(this.$t('room.importOwnerRoom.importError'))
        }
      },
af1bcbd6   wuxw   房屋页面开发中
112
113
114
    }
  }
  </script>