Blame view

src/components/room/addUnit.vue 3.38 KB
af1bcbd6   wuxw   房屋页面开发中
1
  <template>
81955f61   wuxw   优化房屋页面
2
    <el-dialog :title="$t('addUnit.title')" :visible.sync="visible" width="50%" :before-close="handleClose">
af1bcbd6   wuxw   房屋页面开发中
3
4
      <el-form ref="form" :model="addUnitInfo" label-width="120px">
        <el-form-item :label="$t('addUnit.unitNum')" prop="unitNum" required>
81955f61   wuxw   优化房屋页面
5
          <el-input v-model="addUnitInfo.unitNum" :placeholder="$t('addUnit.unitNumPlaceholder')"></el-input>
af1bcbd6   wuxw   房屋页面开发中
6
        </el-form-item>
81955f61   wuxw   优化房屋页面
7
  
af1bcbd6   wuxw   房屋页面开发中
8
        <el-form-item :label="$t('addUnit.layerCount')" prop="layerCount" required>
81955f61   wuxw   优化房屋页面
9
10
          <el-input v-model.number="addUnitInfo.layerCount" type="number"
            :placeholder="$t('addUnit.layerCountPlaceholder')"></el-input>
af1bcbd6   wuxw   房屋页面开发中
11
        </el-form-item>
81955f61   wuxw   优化房屋页面
12
  
af1bcbd6   wuxw   房屋页面开发中
13
        <el-form-item :label="$t('addUnit.unitArea')" prop="unitArea" required>
81955f61   wuxw   优化房屋页面
14
          <el-input v-model="addUnitInfo.unitArea" :placeholder="$t('addUnit.unitAreaPlaceholder')"></el-input>
af1bcbd6   wuxw   房屋页面开发中
15
        </el-form-item>
81955f61   wuxw   优化房屋页面
16
  
af1bcbd6   wuxw   房屋页面开发中
17
        <el-form-item :label="$t('addUnit.lift')" prop="lift" required>
81955f61   wuxw   优化房屋页面
18
19
20
          <el-select v-model="addUnitInfo.lift" :placeholder="$t('addUnit.liftPlaceholder')" style="width: 100%">
            <el-option :label="$t('addUnit.liftOption1')" value="1010"></el-option>
            <el-option :label="$t('addUnit.liftOption2')" value="2020"></el-option>
af1bcbd6   wuxw   房屋页面开发中
21
22
          </el-select>
        </el-form-item>
81955f61   wuxw   优化房屋页面
23
  
af1bcbd6   wuxw   房屋页面开发中
24
        <el-form-item :label="$t('addUnit.remark')">
81955f61   wuxw   优化房屋页面
25
26
          <el-input v-model="addUnitInfo.remark" type="textarea" :rows="3"
            :placeholder="$t('addUnit.remarkPlaceholder')"></el-input>
af1bcbd6   wuxw   房屋页面开发中
27
28
        </el-form-item>
      </el-form>
81955f61   wuxw   优化房屋页面
29
  
af1bcbd6   wuxw   房屋页面开发中
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
87
88
89
90
91
92
93
      <span slot="footer" class="dialog-footer">
        <el-button @click="handleClose">{{ $t('addUnit.cancel') }}</el-button>
        <el-button type="primary" @click="addUnit">{{ $t('addUnit.save') }}</el-button>
      </span>
    </el-dialog>
  </template>
  
  <script>
  import { saveUnit } from '@/api/room/addUnitApi'
  
  export default {
    name: 'AddUnit',
    data() {
      return {
        visible: false,
        addUnitInfo: {
          floorId: '',
          unitNum: '',
          layerCount: '',
          lift: '',
          remark: '',
          communityId: '',
          unitArea: ''
        }
      }
    },
    methods: {
      open(params) {
        this.refreshAddUnitInfo()
        if (params && params.floorId) {
          this.addUnitInfo.floorId = params.floorId
        }
        this.addUnitInfo.communityId = this.getCommunityId()
        this.visible = true
      },
      handleClose() {
        this.visible = false
      },
      refreshAddUnitInfo() {
        this.addUnitInfo = {
          floorId: '',
          unitNum: '',
          layerCount: '',
          lift: '',
          remark: '',
          communityId: '',
          unitArea: ''
        }
        this.$nextTick(() => {
          if (this.$refs.form) {
            this.$refs.form.clearValidate()
          }
        })
      },
      validateForm() {
        return new Promise((resolve) => {
          this.$refs.form.validate((valid) => {
            resolve(valid)
          })
        })
      },
      async addUnit() {
        const isValid = await this.validateForm()
        if (!isValid) return
81955f61   wuxw   优化房屋页面
94
  
af1bcbd6   wuxw   房屋页面开发中
95
96
97
98
        if (this.addUnitInfo.unitNum === '0') {
          this.$message.warning(this.$t('addUnit.zeroUnitWarning'))
          return
        }
81955f61   wuxw   优化房屋页面
99
  
af1bcbd6   wuxw   房屋页面开发中
100
101
102
        try {
          await saveUnit(this.addUnitInfo)
          this.$message.success(this.$t('addUnit.successMessage'))
81955f61   wuxw   优化房屋页面
103
104
          this.$emit('handleRefreshTree', {})
  
af1bcbd6   wuxw   房屋页面开发中
105
106
107
108
109
110
111
112
113
          this.handleClose()
        } catch (error) {
          console.error('添加单元失败:', error)
          this.$message.error(error.message || this.$t('addUnit.errorMessage'))
        }
      }
    }
  }
  </script>