Blame view

src/components/room/addPropertyRightRegistration.vue 11.9 KB
f92fd6ac   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
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
  <template>
    <el-dialog :title="$t('propertyRightRegistration.add.title')" :visible.sync="visible" width="70%"
      @close="handleClose">
      <el-form ref="form" :model="formData" label-width="120px">
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item :label="$t('propertyRightRegistration.add.floor')" prop="floorId"
              :rules="[{ required: true, message: $t('propertyRightRegistration.add.floorRequired'), trigger: 'change' }]">
              <el-select v-model="formData.floorId" :placeholder="$t('propertyRightRegistration.add.floorPlaceholder')"
                style="width:100%" @change="handleFloorChange">
                <el-option v-for="item in floors" :key="item.floorId"
                  :label="`${item.floorNum}${$t('propertyRightRegistration.add.floorUnit')}`" :value="item.floorId" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="$t('propertyRightRegistration.add.unit')" prop="unitId"
              :rules="[{ required: true, message: $t('propertyRightRegistration.add.unitRequired'), trigger: 'change' }]">
              <el-select v-model="formData.unitId" :placeholder="$t('propertyRightRegistration.add.unitPlaceholder')"
                style="width:100%" @change="handleUnitChange">
                <el-option v-for="item in units" :key="item.unitId"
                  :label="`${item.unitNum}${$t('propertyRightRegistration.add.unitUnit')}`" :value="item.unitId" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
  
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item :label="$t('propertyRightRegistration.add.room')" prop="roomId"
              :rules="[{ required: true, message: $t('propertyRightRegistration.add.roomRequired'), trigger: 'change' }]">
              <el-select v-model="formData.roomId" :placeholder="$t('propertyRightRegistration.add.roomPlaceholder')"
                style="width:100%">
                <el-option v-for="item in rooms" :key="item.roomId" :label="item.roomNum" :value="item.roomId" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="$t('propertyRightRegistration.add.name')" prop="name" :rules="[
              { required: true, message: $t('propertyRightRegistration.add.nameRequired'), trigger: 'blur' },
              { min: 2, max: 64, message: $t('propertyRightRegistration.add.nameLength'), trigger: 'blur' }
            ]">
              <el-input v-model.trim="formData.name" :placeholder="$t('propertyRightRegistration.add.namePlaceholder')" />
            </el-form-item>
          </el-col>
        </el-row>
  
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item :label="$t('propertyRightRegistration.add.link')" prop="link"
              :rules="[{ required: true, message: $t('propertyRightRegistration.add.linkRequired'), trigger: 'blur' }]">
              <el-input v-model.trim="formData.link" :placeholder="$t('propertyRightRegistration.add.linkPlaceholder')" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="$t('propertyRightRegistration.add.idCard')" prop="idCard" :rules="[
              { required: true, message: $t('propertyRightRegistration.add.idCardRequired'), trigger: 'blur' },
            ]">
              <el-input v-model.trim="formData.idCard"
                :placeholder="$t('propertyRightRegistration.add.idCardPlaceholder')" />
            </el-form-item>
          </el-col>
        </el-row>
  
        <el-form-item :label="$t('propertyRightRegistration.add.address')" prop="address" :rules="[
          { required: true, message: $t('propertyRightRegistration.add.addressRequired'), trigger: 'blur' },
          { max: 255, message: $t('propertyRightRegistration.add.addressMax'), trigger: 'blur' }
        ]">
          <el-input v-model.trim="formData.address"
            :placeholder="$t('propertyRightRegistration.add.addressPlaceholder')" />
        </el-form-item>
  
        <el-form-item :label="$t('propertyRightRegistration.add.idCardPhotos')" prop="idCardPhotos"
          :rules="[{ required: true, message: $t('propertyRightRegistration.add.idCardPhotosRequired'), trigger: 'change' }]">
          <upload-image-url ref="idCardUpload" :image-count="2" @notifyUploadCoverImage="handleIdCardChange" />
          <p class="tip">{{ $t('propertyRightRegistration.add.idCardPhotosTip') }}</p>
        </el-form-item>
  
        <el-form-item :label="$t('propertyRightRegistration.add.housePurchasePhotos')" prop="housePurchasePhotos"
          :rules="[{ required: true, message: $t('propertyRightRegistration.add.housePurchasePhotosRequired'), trigger: 'change' }]">
          <upload-image-url ref="housePurchaseUpload" :image-count="10" @notifyUploadCoverImage="handleHousePurchaseChange" />
          <p class="tip">{{ $t('propertyRightRegistration.add.housePurchasePhotosTip') }}</p>
        </el-form-item>
  
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item :label="$t('propertyRightRegistration.add.isTrue')" prop="isTrue"
              :rules="[{ required: true, message: $t('propertyRightRegistration.add.isTrueRequired'), trigger: 'change' }]">
              <el-select v-model="formData.isTrue" :placeholder="$t('propertyRightRegistration.add.isTruePlaceholder')"
                style="width:100%" @change="handleIsTrueChange">
                <el-option :label="$t('common.yes')" value="true" />
                <el-option :label="$t('common.no')" value="false" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col v-if="formData.isTrue === 'true'" :span="12">
            <el-form-item :label="$t('propertyRightRegistration.add.repairPhotos')" prop="repairPhotos"
              :rules="[{ required: true, message: $t('propertyRightRegistration.add.repairPhotosRequired'), trigger: 'change' }]">
              <upload-image-url ref="repairUpload" :image-count="3" @notifyUploadCoverImage="handleRepairChange" />
            </el-form-item>
          </el-col>
        </el-row>
  
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item :label="$t('propertyRightRegistration.add.flag')" prop="flag"
              :rules="[{ required: true, message: $t('propertyRightRegistration.add.flagRequired'), trigger: 'change' }]">
              <el-select v-model="formData.flag" :placeholder="$t('propertyRightRegistration.add.flagPlaceholder')"
                style="width:100%" @change="handleFlagChange">
                <el-option :label="$t('common.yes')" value="0" />
                <el-option :label="$t('common.no')" value="1" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col v-if="formData.flag === '0'" :span="12">
            <el-form-item :label="$t('propertyRightRegistration.add.deedTaxPhotos')" prop="deedTaxPhotos"
              :rules="[{ required: true, message: $t('propertyRightRegistration.add.deedTaxPhotosRequired'), trigger: 'change' }]">
              <upload-image-url ref="deedTaxUpload" :image-count="3" @notifyUploadCoverImage="handleDeedTaxChange" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
  
      <div slot="footer" class="dialog-footer">
        <el-button @click="visible = false">{{ $t('common.cancel') }}</el-button>
        <el-button type="primary" @click="handleSubmit">{{ $t('common.confirm') }}</el-button>
      </div>
    </el-dialog>
  </template>
  
  <script>
  import { getCommunityId } from '@/api/community/communityApi'
  import { getFloors, getUnits, queryRooms } from '@/api/room/roomApi'
  import { savePropertyRightRegistration } from '@/api/room/propertyRightRegistrationManageApi'
  import UploadImageUrl from '@/components/upload/UploadImageUrl'
  
  export default {
    name: 'AddPropertyRightRegistration',
    components: {
      UploadImageUrl
    },
    data() {
      return {
        visible: false,
        formData: {
          prrId: '',
          roomId: '',
          floorId: '',
          unitId: '',
          name: '',
          link: '',
          idCard: '',
          address: '',
          isTrue: '',
          flag: '',
          state: '0',
          idCardPhotos: [],
          housePurchasePhotos: [],
          repairPhotos: [],
          deedTaxPhotos: [],
          communityId: getCommunityId()
        },
        floors: [],
        units: [],
        rooms: []
      }
    },
    methods: {
      open() {
        this.visible = true
        this.getFloors()
        this.$nextTick(() => {
          this.$refs.form && this.$refs.form.resetFields()
          this.$refs.idCardUpload && this.$refs.idCardUpload.clearImages()
          this.$refs.housePurchaseUpload && this.$refs.housePurchaseUpload.clearImages()
          this.$refs.repairUpload && this.$refs.repairUpload.clearImages()
          this.$refs.deedTaxUpload && this.$refs.deedTaxUpload.clearImages()
        })
      },
      handleClose() {
        this.$refs.form.resetFields()
        this.formData = {
          prrId: '',
          roomId: '',
          floorId: '',
          unitId: '',
          name: '',
          link: '',
          idCard: '',
          address: '',
          isTrue: '',
          flag: '',
          state: '0',
          idCardPhotos: [],
          housePurchasePhotos: [],
          repairPhotos: [],
          deedTaxPhotos: [],
          communityId: getCommunityId()
        }
      },
      async getFloors() {
        try {
          const params = {
            communityId: this.formData.communityId,
            page: 1,
            row: 50
          }
          const data = await getFloors(params)
          this.floors = data.apiFloorDataVoList || []
        } catch (error) {
          console.error('获取楼栋数据失败:', error)
        }
      },
      async handleFloorChange(floorId) {
        try {
          const params = {
            floorId,
            communityId: this.formData.communityId,
            page: 1,
            row: 50
          }
          const data = await getUnits(params)
          this.units = data || []
          this.formData.unitId = ''
          this.rooms = []
          this.formData.roomId = ''
        } catch (error) {
          console.error('获取单元数据失败:', error)
        }
      },
      async handleUnitChange(unitId) {
        try {
          const params = {
            unitId,
            communityId: this.formData.communityId,
            page: 1,
            row: 50
          }
          const data = await queryRooms(params)
          this.rooms = data.rooms || []
          this.formData.roomId = ''
        } catch (error) {
          console.error('获取房间数据失败:', error)
        }
      },
      handleIsTrueChange(val) {
        if (val !== 'true') {
          this.formData.repairPhotos = []
          this.$refs.repairUpload && this.$refs.repairUpload.clearImages()
        }
      },
      handleFlagChange(val) {
        if (val !== '0') {
          this.formData.deedTaxPhotos = []
          this.$refs.deedTaxUpload && this.$refs.deedTaxUpload.clearImages()
        }
      },
      handleIdCardChange(photos) {
        this.formData.idCardPhotos = photos
      },
      handleHousePurchaseChange(photos) {
        this.formData.housePurchasePhotos = photos
      },
      handleRepairChange(photos) {
        this.formData.repairPhotos = photos
      },
      handleDeedTaxChange(photos) {
        this.formData.deedTaxPhotos = photos
      },
  
      async handleSubmit() {
        try {
          await this.$refs.form.validate()
          this.loading = true
  
          const params = {
            ...this.formData,
            idCardPhotos: this.formData.idCardPhotos,
            housePurchasePhotos: this.formData.housePurchasePhotos,
            repairPhotos: this.formData.repairPhotos,
            deedTaxPhotos: this.formData.deedTaxPhotos
          }
  
          await savePropertyRightRegistration(params)
          this.$message.success(this.$t('propertyRightRegistration.add.success'))
          this.visible = false
          this.$emit('success')
        } catch (error) {
          console.error('保存失败:', error)
          if (error !== 'validate') {
            this.$message.error(this.$t('propertyRightRegistration.add.error'))
          }
        } finally {
          this.loading = false
        }
      }
    }
  }
  </script>
  
  <style scoped>
  .tip {
    color: #999;
    font-size: 12px;
    margin-top: 5px;
  }
  </style>