Blame view

src/components/room/addUnit.vue 3.87 KB
6ec243d6   wuxw   v1.9 点击提交后,成功提示没有...
1
  <template>
81955f61   wuxw   优化房屋页面
2
    <el-dialog :title="$t('addUnit.title')" :visible.sync="visible" width="50%" :before-close="handleClose">
7caa1e00   wuxw   v1.9 优化添加单元乱码问题
3
4
      <el-form ref="form" :model="addUnitInfo" :rules="rules" label-width="120px">
        <el-form-item :label="$t('addUnit.unitNum')" prop="unitNum">
81955f61   wuxw   优化房屋页面
5
          <el-input v-model="addUnitInfo.unitNum" :placeholder="$t('addUnit.unitNumPlaceholder')"></el-input>
af1bcbd6   wuxw   房屋页面开发中
6
        </el-form-item>
81955f61   wuxw   优化房屋页面
7
  
7caa1e00   wuxw   v1.9 优化添加单元乱码问题
8
        <el-form-item :label="$t('addUnit.layerCount')" prop="layerCount">
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
  
7caa1e00   wuxw   v1.9 优化添加单元乱码问题
13
        <el-form-item :label="$t('addUnit.unitArea')" prop="unitArea">
81955f61   wuxw   优化房屋页面
14
          <el-input v-model="addUnitInfo.unitArea" :placeholder="$t('addUnit.unitAreaPlaceholder')"></el-input>
af1bcbd6   wuxw   房屋页面开发中
15
        </el-form-item>
81955f61   wuxw   优化房屋页面
16
  
7caa1e00   wuxw   v1.9 优化添加单元乱码问题
17
        <el-form-item :label="$t('addUnit.lift')" prop="lift">
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
      <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: ''
7caa1e00   wuxw   v1.9 优化添加单元乱码问题
53
54
55
56
57
58
59
60
61
62
63
64
65
66
        },
        rules: {
          unitNum: [
            { required: true, message: this.$t('addUnit.unitNumRequired'), trigger: 'blur' }
          ],
          layerCount: [
            { required: true, message: this.$t('addUnit.layerCountRequired'), trigger: 'blur' }
          ],
          unitArea: [
            { required: true, message: this.$t('addUnit.unitAreaRequired'), trigger: 'blur' }
          ],
          lift: [
            { required: true, message: this.$t('addUnit.liftRequired'), trigger: 'change' }
          ]
af1bcbd6   wuxw   房屋页面开发中
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
        }
      }
    },
    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   优化房屋页面
108
  
af1bcbd6   wuxw   房屋页面开发中
109
110
111
112
        if (this.addUnitInfo.unitNum === '0') {
          this.$message.warning(this.$t('addUnit.zeroUnitWarning'))
          return
        }
81955f61   wuxw   优化房屋页面
113
  
af1bcbd6   wuxw   房屋页面开发中
114
115
        try {
          await saveUnit(this.addUnitInfo)
6ec243d6   wuxw   v1.9 点击提交后,成功提示没有...
116
          this.$message.success(this.$t('common.operationSuccess'))
81955f61   wuxw   优化房屋页面
117
118
          this.$emit('handleRefreshTree', {})
  
af1bcbd6   wuxw   房屋页面开发中
119
120
121
122
123
124
125
126
127
          this.handleClose()
        } catch (error) {
          console.error('添加单元失败:', error)
          this.$message.error(error.message || this.$t('addUnit.errorMessage'))
        }
      }
    }
  }
  </script>