Blame view

src/components/room/deleteUnit.vue 1.64 KB
af1bcbd6   wuxw   房屋页面开发中
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
  <template>
    <el-dialog
      :title="$t('deleteUnit.title')"
      :visible.sync="visible"
      width="30%"
      :before-close="handleClose"
    >
      <div class="text-center">
        <p>{{ $t('deleteUnit.confirmMessage') }}</p>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="handleClose">{{ $t('deleteUnit.cancel') }}</el-button>
        <el-button type="danger" @click="deleteUnit">{{ $t('deleteUnit.confirm') }}</el-button>
      </span>
    </el-dialog>
  </template>
  
  <script>
  import { deleteUnit } from '@/api/room/deleteUnitApi'
  
  export default {
    name: 'DeleteUnit',
    data() {
      return {
        visible: false,
        deleteUnitInfo: {
          _currentFloorId: '',
          _currentUnitId: ''
        }
      }
    },
    methods: {
      open(params) {
        this.deleteUnitInfo._currentFloorId = params.floorId
        this.deleteUnitInfo._currentUnitId = params.unitId
        this.visible = true
      },
      handleClose() {
        this.visible = false
      },
      async deleteUnit() {
        const param = {
          floorId: this.deleteUnitInfo._currentFloorId,
          unitId: this.deleteUnitInfo._currentUnitId,
          communityId: this.getCommunityId()
        }
        
        try {
          await deleteUnit(param)
          this.$message.success(this.$t('deleteUnit.successMessage'))
          this.$emit('refresh-tree', { floorId: this.deleteUnitInfo._currentFloorId })
          this.$emit('refresh-data', { floorId: this.deleteUnitInfo._currentFloorId })
          this.handleClose()
        } catch (error) {
          console.error('删除单元失败:', error)
          this.$message.error(error.message || this.$t('deleteUnit.errorMessage'))
        }
      }
    }
  }
  </script>