Blame view

src/components/owner/editOwner.vue 11.2 KB
6ec243d6   wuxw   v1.9 点击提交后,成功提示没有...
1
  <template>
88f005b5   wuxw   业主页面开发完成
2
3
4
5
6
7
    <el-dialog :title="$t('listOwner.buttons.edit')" :visible.sync="visible" width="800px" @close="resetForm">
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item :label="$t('listOwner.columns.type')" prop="personType">
              <el-select v-model="form.personType" style="width:100%">
911b5549   wuxw   修改平凉客户 反馈的bug 修复
8
                <el-option v-for="(type, index) in personTypes" :key="index" :label="type.label" :value="type.value" />
88f005b5   wuxw   业主页面开发完成
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
              </el-select>
            </el-form-item>
  
            <el-form-item :label="$t('listOwner.columns.role')" prop="personRole">
              <el-select v-model="form.personRole" style="width:100%">
                <el-option v-for="role in personRoles" :key="role.value" :label="role.label" :value="role.value" />
              </el-select>
            </el-form-item>
  
            <el-form-item :label="$t('listOwner.columns.name')" prop="name">
              <el-input v-model="form.name" :placeholder="$t('listOwner.placeholders.name')" />
            </el-form-item>
  
            <el-form-item v-if="form.personType === 'C'" :label="$t('listOwner.buttons.member')">
              <el-input v-model="form.concactPerson" />
            </el-form-item>
  
            <el-form-item :label="$t('listOwner.columns.phone')" prop="link">
              <el-input v-model="form.link" :placeholder="$t('listOwner.placeholders.phone')" />
            </el-form-item>
  
            <el-form-item v-if="form.personType === 'P'" :label="$t('listOwner.columns.gender')" prop="sex">
              <el-select v-model="form.sex" style="width:100%">
                <el-option v-for="gender in genders" :key="gender.value" :label="gender.label" :value="gender.value" />
              </el-select>
            </el-form-item>
          </el-col>
  
          <el-col :span="12" class="text-center">
            <el-image style="width: 200px; height: 150px; border: 1px dashed #ccc;"
              :src="form.ownerPhotoUrl || '/img/noPhoto.jpg'" fit="cover" />
a87d01dc   wuxw   v1.9 业主页面男女 bug 修复
40
            <el-upload class="mt-10" :show-file-list="false" :before-upload="beforeUpload" :http-request="uploadImage" action="">
88f005b5   wuxw   业主页面开发完成
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
              <el-button size="small" type="primary">
                {{ $t('common.upload') }}
              </el-button>
            </el-upload>
          </el-col>
        </el-row>
  
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item :label="$t('listOwner.columns.backupPhone')">
              <el-input v-model="form.concactLink" />
            </el-form-item>
          </el-col>
  
          <el-col :span="12">
            <el-form-item :label="$t('listOwner.columns.address')">
              <el-input v-model="form.address" />
            </el-form-item>
          </el-col>
        </el-row>
  
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item v-if="form.personType === 'C'" :label="$t('listOwner.columns.idCard')">
              <el-input v-model="form.idCard" />
            </el-form-item>
  
            <el-form-item v-else :label="$t('listOwner.columns.idCard')">
              <el-input v-model="form.idCard" />
            </el-form-item>
          </el-col>
  
          <el-col :span="12">
            <el-form-item :label="$t('common.remark')">
              <el-input v-model="form.remark" />
            </el-form-item>
          </el-col>
        </el-row>
  
        <div v-for="(item, index) in attrs" :key="index">
          <el-row :gutter="20" v-if="index % 2 === 0">
            <el-col :span="12">
              <el-form-item :label="item.specName">
a5f85f5f   wuxw   v1.9 修复修改业主,修改门禁钥...
84
85
86
87
88
89
90
91
92
93
94
95
96
97
                <input v-if="item.specType === '2233'" 
                       v-model="item.value" 
                       :placeholder="item.specHoldplace"
                       class="custom-input" />
                <select v-else-if="item.specType === '3344'" 
                        v-model="item.value" 
                        class="custom-select">
                  <option v-for="val in item.values" 
                          :key="val.value" 
                          :label="val.valueName" 
                          :value="val.value">
                    {{ val.valueName }}
                  </option>
                </select>
88f005b5   wuxw   业主页面开发完成
98
99
100
101
102
              </el-form-item>
            </el-col>
  
            <el-col :span="12" v-if="index < attrs.length - 1">
              <el-form-item :label="attrs[index + 1].specName">
a5f85f5f   wuxw   v1.9 修复修改业主,修改门禁钥...
103
104
105
106
107
108
109
110
111
112
113
114
115
116
                <input v-if="attrs[index + 1].specType === '2233'" 
                       v-model="attrs[index + 1].value"
                       :placeholder="attrs[index + 1].specHoldplace"
                       class="custom-input" />
                <select v-else-if="attrs[index + 1].specType === '3344'" 
                        v-model="attrs[index + 1].value"
                        class="custom-select">
                  <option v-for="val in attrs[index + 1].values" 
                          :key="val.value" 
                          :label="val.valueName"
                          :value="val.value">
                    {{ val.valueName }}
                  </option>
                </select>
88f005b5   wuxw   业主页面开发完成
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
              </el-form-item>
            </el-col>
          </el-row>
        </div>
      </el-form>
  
      <div slot="footer" class="dialog-footer">
        <el-button @click="visible = false">
          {{ $t('listOwner.buttons.cancel') }}
        </el-button>
        <el-button type="primary" @click="updateOwner">
          {{ $t('listOwner.buttons.save') }}
        </el-button>
      </div>
    </el-dialog>
  </template>
  
  <script>
  import { editOwner, getAttrValue, uploadImage } from '@/api/owner/ownerApi'
  import { getAttrSpecList } from '@/api/dev/attrSpecApi'
  
  export default {
    name: 'EditOwner',
    data() {
      return {
        visible: false,
        form: {
          ownerId: '',
          name: '',
          link: '',
          address: '',
          sex: '',
          remark: '',
          ownerPhoto: '',
          ownerPhotoUrl: '',
          idCard: '',
          personType: 'P',
          personRole: '1',
          concactPerson: '',
          concactLink: ''
        },
        attrs: [],
        personTypes: [
          { value: 'P', label: this.$t('listOwner.personType.personal') },
          { value: 'C', label: this.$t('listOwner.personType.company') }
        ],
        personRoles: [
          { value: '1', label: this.$t('listOwner.role.owner') },
          { value: '2', label: this.$t('listOwner.role.tenant') }
        ],
        genders: [
          { value: '0', label: this.$t('listOwner.gender.male') },
          { value: '1', label: this.$t('listOwner.gender.female') }
        ],
        rules: {
          name: [
911b5549   wuxw   修改平凉客户 反馈的bug 修复
173
            { required: true, message: this.$t('listOwner.placeholders.name'), trigger: 'blur' },
88f005b5   wuxw   业主页面开发完成
174
175
          ],
          personType: [
911b5549   wuxw   修改平凉客户 反馈的bug 修复
176
            { required: true, message: this.$t('listOwner.placeholders.typeRequired'), trigger: 'change' }
88f005b5   wuxw   业主页面开发完成
177
178
          ],
          personRole: [
911b5549   wuxw   修改平凉客户 反馈的bug 修复
179
            { required: true, message: this.$t('listOwner.placeholders.roleRequired'), trigger: 'change' }
88f005b5   wuxw   业主页面开发完成
180
181
          ],
          link: [
911b5549   wuxw   修改平凉客户 反馈的bug 修复
182
            { required: true, message: this.$t('listOwner.placeholders.phoneRequired'), trigger: 'blur' },
88f005b5   wuxw   业主页面开发完成
183
184
          ],
          sex: [
911b5549   wuxw   修改平凉客户 反馈的bug 修复
185
            { required: true, message: this.$t('listOwner.placeholders.genderRequired'), trigger: 'change' }
88f005b5   wuxw   业主页面开发完成
186
187
188
189
190
191
192
          ]
        }
      }
    },
    methods: {
      open(owner) {
        this.form = { ...owner }
b96589a4   wuxw   v1.9 业主相关bug
193
        this.form.ownerPhotoUrl = owner.faceUrl || '/img/noPhoto.jpg'
88f005b5   wuxw   业主页面开发完成
194
195
196
197
198
199
        this.visible = true
        this.loadAttributes()
      },
  
      async loadAttributes() {
        try {
a87d01dc   wuxw   v1.9 业主页面男女 bug 修复
200
201
202
203
          const {data} = await getAttrSpecList({ page: 1, row: 100, tableName: 'building_owner_attr' })
          if (data.length == 0) {
            return
          }
88f005b5   wuxw   业主页面开发完成
204
205
206
          this.attrs = data.filter(item => item.specShow === 'Y')
  
          for (const attr of this.attrs) {
a87d01dc   wuxw   v1.9 业主页面男女 bug 修复
207
            attr.value = ''
88f005b5   wuxw   业主页面开发完成
208
209
210
211
212
213
214
215
            if (attr.specType === '3344') {
              attr.values = await getAttrValue(attr.specCd)
            }
  
            // 设置已有属性值
            if (this.form.ownerAttrDtos) {
              const attrDto = this.form.ownerAttrDtos.find(dto => dto.specCd === attr.specCd)
              attr.value = attrDto ? attrDto.value : ''
a5f85f5f   wuxw   v1.9 修复修改业主,修改门禁钥...
216
              attr.attrId = attrDto ? attrDto.attrId : ''
88f005b5   wuxw   业主页面开发完成
217
218
219
220
221
222
223
224
225
226
227
228
            }
          }
        } catch (error) {
          console.error('Failed to load attributes:', error)
        }
      },
  
      beforeUpload(file) {
        const isJPG = file.type === 'image/jpeg'
        const isLt2M = file.size / 1024 / 1024 < 2
  
        if (!isJPG) {
69e18472   wuxw   v1.9 员工头像不对问题
229
          this.$message.error(this.$t('common.jpgOnly'))
88f005b5   wuxw   业主页面开发完成
230
231
        }
        if (!isLt2M) {
69e18472   wuxw   v1.9 员工头像不对问题
232
          this.$message.error(this.$t('common.sizeLimit'))
88f005b5   wuxw   业主页面开发完成
233
234
235
236
237
238
239
        }
        return isJPG && isLt2M
      },
  
      async uploadImage({ file }) {
        try {
          const res = await uploadImage({ file })
a87d01dc   wuxw   v1.9 业主页面男女 bug 修复
240
241
242
          this.form.ownerPhoto = res.fileId
          this.form.ownerPhotoUrl = res.url
          this.$forceUpdate()
88f005b5   wuxw   业主页面开发完成
243
244
245
246
247
248
249
250
251
252
253
254
255
        } catch (error) {
          this.$message.error(this.$t('listOwner.upload.failed'))
        }
      },
  
      async updateOwner() {
        this.$refs.form.validate(async valid => {
          if (!valid) return
  
          try {
            const params = {
              ...this.form,
              attrs: this.attrs.map(attr => ({
a5f85f5f   wuxw   v1.9 修复修改业主,修改门禁钥...
256
                attrId: attr.attrId,
88f005b5   wuxw   业主页面开发完成
257
258
259
260
261
262
                specCd: attr.specCd,
                value: attr.value
              }))
            }
  
            await editOwner(params)
6ec243d6   wuxw   v1.9 点击提交后,成功提示没有...
263
            this.$message.success(this.$t('common.operationSuccess'))
88f005b5   wuxw   业主页面开发完成
264
265
266
            this.visible = false
            this.$emit('success')
          } catch (error) {
e3aca637   wuxw   v1.9 优化组织修改显示不正确bug
267
            this.$message.error(error)
88f005b5   wuxw   业主页面开发完成
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
          }
        })
      },
  
      resetForm() {
        this.$refs.form.resetFields()
        this.form = {
          ownerId: '',
          name: '',
          link: '',
          address: '',
          sex: '',
          remark: '',
          ownerPhoto: '',
          ownerPhotoUrl: '',
          idCard: '',
          personType: 'P',
          personRole: '1',
          concactPerson: '',
          concactLink: ''
        }
        this.attrs = []
      }
    }
  }
  </script>
  
  <style scoped>
  .text-center {
    text-align: center;
  }
  
  .mt-10 {
    margin-top: 10px;
  }
a5f85f5f   wuxw   v1.9 修复修改业主,修改门禁钥...
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
  
  /* 自定义输入框样式,模拟 el-input */
  .custom-input {
    width: 100%;
    height: 32px;
    line-height: 32px;
    padding: 0 12px;
    border: 1px solid #dcdfe6;
    border-radius: 4px;
    font-size: 14px;
    color: #606266;
    background-color: #fff;
    transition: border-color 0.2s cubic-bezier(0.645, 0.045, 0.355, 1);
    box-sizing: border-box;
  }
  
  .custom-input:focus {
    outline: none;
    border-color: #409eff;
  }
  
  .custom-input:hover {
    border-color: #c0c4cc;
  }
  
  .custom-input::placeholder {
    color: #c0c4cc;
  }
  
  /* 自定义选择框样式,模拟 el-select */
  .custom-select {
    width: 100%;
    height: 32px;
    line-height: 32px;
    padding: 0 12px;
    border: 1px solid #dcdfe6;
    border-radius: 4px;
    font-size: 14px;
    color: #606266;
    background-color: #fff;
    transition: border-color 0.2s cubic-bezier(0.645, 0.045, 0.355, 1);
    box-sizing: border-box;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='m6 8 4 4 4-4'/%3e%3c/svg%3e");
    background-position: right 8px center;
    background-repeat: no-repeat;
    background-size: 16px;
    padding-right: 32px;
  }
  
  .custom-select:focus {
    outline: none;
    border-color: #409eff;
  }
  
  .custom-select:hover {
    border-color: #c0c4cc;
  }
  
  .custom-select option {
    padding: 8px 12px;
    background-color: #fff;
    color: #606266;
  }
  
  .custom-select option:hover {
    background-color: #f5f7fa;
  }
88f005b5   wuxw   业主页面开发完成
372
  </style>