Blame view

src/components/room/addFloor.vue 4.14 KB
6ec243d6   wuxw   v1.9 点击提交后,成功提示没有...
1
  <template>
af1bcbd6   wuxw   房屋页面开发中
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
    <el-dialog
      :title="$t('room.addFloor.title')"
      :visible.sync="visible"
      width="50%"
      :before-close="handleClose"
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item :label="$t('room.addFloor.floorNum')" prop="floorNum">
          <el-input v-model="form.floorNum" :placeholder="$t('room.addFloor.floorNumPlaceholder')" />
        </el-form-item>
        
        <el-form-item :label="$t('room.addFloor.name')" prop="name">
          <el-input v-model="form.name" :placeholder="$t('room.addFloor.namePlaceholder')" />
        </el-form-item>
        
        <el-form-item :label="$t('room.addFloor.floorArea')" prop="floorArea">
          <el-input v-model="form.floorArea" :placeholder="$t('room.addFloor.floorAreaPlaceholder')">
            <template slot="append">m²</template>
          </el-input>
        </el-form-item>
        
81955f61   wuxw   优化房屋页面
23
        <el-form-item :label="$t('room.addFloor.seq')" class="text-left" prop="seq">
af1bcbd6   wuxw   房屋页面开发中
24
25
26
27
28
29
30
          <el-input-number v-model="form.seq" :min="1" />
        </el-form-item>
        
        <el-form-item :label="$t('room.addFloor.remark')" prop="remark">
          <el-input v-model="form.remark" type="textarea" :placeholder="$t('room.addFloor.remarkPlaceholder')" />
        </el-form-item>
        
af1bcbd6   wuxw   房屋页面开发中
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
      </el-form>
      
      <span slot="footer" class="dialog-footer">
        <el-button @click="handleClose">{{ $t('common.cancel') }}</el-button>
        <el-button type="primary" @click="handleSave">{{ $t('common.save') }}</el-button>
      </span>
    </el-dialog>
  </template>
  
  <script>
  import { addFloor } from '@/api/room/addFloorApi'
  
  export default {
    name: 'AddFloor',
    props: {
      callBackListener: String,
      callBackFunction: String
    },
    data() {
      return {
        visible: false,
        form: {
          communityId: this.getCommunityId(),
          floorNum: '',
          name: '',
          floorArea: '',
          seq: 1,
          remark: ''
        },
        errorInfo: '',
        rules: {
          floorNum: [
            { required: true, message: this.$t('room.addFloor.floorNumRequired'), trigger: 'blur' },
            { min: 1, max: 64, message: this.$t('room.addFloor.floorNumLength'), trigger: 'blur' }
          ],
          name: [
            { required: true, message: this.$t('room.addFloor.nameRequired'), trigger: 'blur' },
            { min: 2, max: 64, message: this.$t('room.addFloor.nameLength'), trigger: 'blur' }
          ],
          floorArea: [
            { required: true, message: this.$t('room.addFloor.floorAreaRequired'), trigger: 'blur' },
            { pattern: /^\d+(\.\d{1,2})?$/, message: this.$t('room.addFloor.floorAreaFormat'), trigger: 'blur' }
          ],
          seq: [
            { required: true, message: this.$t('room.addFloor.seqRequired'), trigger: 'blur' },
            { type: 'number', message: this.$t('room.addFloor.seqNumber'), trigger: 'blur' }
          ],
          remark: [
            { max: 200, message: this.$t('room.addFloor.remarkMaxLength'), trigger: 'blur' }
          ]
        }
      }
    },
    watch: {
      'form.floorNum': function(newVal) {
        if (newVal) {
          this.form.name = `${newVal}${this.$t('room.addFloor.buildingSuffix')}`
        } else {
          this.form.name = ''
        }
      }
    },
    methods: {
      open() {
        this.visible = true
        this.resetForm()
      },
      handleClose() {
        this.visible = false
        this.resetForm()
      },
      resetForm() {
        this.form = {
          communityId: this.getCommunityId(),
          floorNum: '',
          name: '',
          floorArea: '',
          seq: 1,
          remark: ''
        }
        this.errorInfo = ''
        this.$refs.form.resetFields()
      },
      async handleSave() {
        this.$refs.form.validate(async (valid) => {
          if (!valid) return
          
          try {
81955f61   wuxw   优化房屋页面
119
  
af1bcbd6   wuxw   房屋页面开发中
120
121
            const response = await addFloor(this.form)
            
81955f61   wuxw   优化房屋页面
122
            if (response.code == 0) {
6ec243d6   wuxw   v1.9 点击提交后,成功提示没有...
123
              this.$message.success(this.$t('common.operationSuccess'))
af1bcbd6   wuxw   房屋页面开发中
124
              this.handleClose()
81955f61   wuxw   优化房屋页面
125
              this.$emit('handleRefreshTree', {})
af1bcbd6   wuxw   房屋页面开发中
126
127
128
129
130
131
132
133
            } else {
              this.errorInfo = response.msg || this.$t('room.addFloor.saveFailed')
            }
          } catch (error) {
            this.errorInfo = this.$t('room.addFloor.saveError')
          }
        })
      },
af1bcbd6   wuxw   房屋页面开发中
134
135
136
    }
  }
  </script>