Blame view

src/components/room/importOwnerRoom.vue 3.29 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')">
84aec3bc   wuxw   彻底开发完成 房屋管理页面
5
6
          <el-upload ref="upload" action="" :auto-upload="false" :on-change="handleFileChange" accept=".xls,.xlsx"
            class="margin-left">
af1bcbd6   wuxw   房屋页面开发中
7
8
9
10
11
12
            <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   优化房屋页面
13
  
af1bcbd6   wuxw   房屋页面开发中
14
        <el-form-item :label="$t('room.importOwnerRoom.downloadTemplate')">
81955f61   wuxw   优化房屋页面
15
          <span class="margin-left">{{ $t('room.importOwnerRoom.downloadFirst') }}</span>
af1bcbd6   wuxw   房屋页面开发中
16
17
18
19
20
21
          <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   优化房屋页面
22
  
af1bcbd6   wuxw   房屋页面开发中
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
      <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   优化房屋页面
71
  
af1bcbd6   wuxw   房屋页面开发中
72
73
74
75
76
        const fileType = this.fileName.split('.').pop().toLowerCase()
        if (!['xls', 'xlsx'].includes(fileType)) {
          this.$message.error(this.$t('room.importOwnerRoom.invalidFormat'))
          return false
        }
81955f61   wuxw   优化房屋页面
77
  
af1bcbd6   wuxw   房屋页面开发中
78
79
80
81
        if (this.form.file.size > 2 * 1024 * 1024) {
          this.$message.error(this.$t('room.importOwnerRoom.fileSizeExceeded'))
          return false
        }
81955f61   wuxw   优化房屋页面
82
  
af1bcbd6   wuxw   房屋页面开发中
83
84
85
86
        return true
      },
      async handleImport() {
        if (!this.validate()) return
81955f61   wuxw   优化房屋页面
87
  
af1bcbd6   wuxw   房屋页面开发中
88
89
90
91
92
        try {
          const formData = new FormData()
          formData.append('uploadFile', this.form.file)
          formData.append('communityId', this.form.communityId)
          formData.append('importAdapt', 'importRoomOwner')
81955f61   wuxw   优化房屋页面
93
  
af1bcbd6   wuxw   房屋页面开发中
94
          const response = await importOwnerRoom(formData)
81955f61   wuxw   优化房屋页面
95
  
84aec3bc   wuxw   彻底开发完成 房屋管理页面
96
97
98
99
          this.handleClose()
          this.$router.push({
            path: '/property/assetImportLogDetail',
            query: {
48ea9c43   wuxw   巡检开发完成
100
              logId: response.logId,
84aec3bc   wuxw   彻底开发完成 房屋管理页面
101
102
103
              logType: 'importRoomOwner'
            }
          })
af1bcbd6   wuxw   房屋页面开发中
104
105
106
107
        } catch (error) {
          this.$message.error(this.$t('room.importOwnerRoom.importError'))
        }
      },
af1bcbd6   wuxw   房屋页面开发中
108
109
110
    }
  }
  </script>