Blame view

src/components/owner/AddOwnerCommittee.vue 12.3 KB
20e526fa   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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
  <template>
    <el-dialog
      :title="$t('addOwnerCommittee.addTitle')"
      :visible.sync="visible"
      width="80%"
      @close="resetForm"
    >
      <el-form ref="form" :model="formData" label-width="120px" :rules="rules">
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item :label="$t('addOwnerCommittee.name')" prop="name">
              <el-input
                v-model="formData.name"
                :placeholder="$t('addOwnerCommittee.required') + $t('addOwnerCommittee.name')"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="$t('addOwnerCommittee.sex')" prop="sex">
              <el-select
                v-model="formData.sex"
                :placeholder="$t('addOwnerCommittee.required') + $t('addOwnerCommittee.sex')"
                style="width:100%"
              >
                <el-option :label="$t('addOwnerCommittee.male')" value="B" />
                <el-option :label="$t('addOwnerCommittee.female')" value="G" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
  
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item :label="$t('addOwnerCommittee.phone')" prop="link">
              <el-input
                v-model="formData.link"
                :placeholder="$t('addOwnerCommittee.required') + $t('addOwnerCommittee.phone')"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="$t('addOwnerCommittee.idCard')" prop="idCard">
              <el-input
                v-model="formData.idCard"
                :placeholder="$t('addOwnerCommittee.required') + $t('addOwnerCommittee.idCard')"
              />
            </el-form-item>
          </el-col>
        </el-row>
  
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item :label="$t('addOwnerCommittee.address')" prop="address">
              <el-input
                v-model="formData.address"
                :placeholder="$t('addOwnerCommittee.required') + $t('addOwnerCommittee.address')"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="$t('addOwnerCommittee.position')" prop="position">
              <el-input
                v-model="formData.position"
                :placeholder="$t('addOwnerCommittee.required') + $t('addOwnerCommittee.position')"
              />
            </el-form-item>
          </el-col>
        </el-row>
  
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item :label="$t('addOwnerCommittee.post')" prop="post">
              <el-input
                v-model="formData.post"
                :placeholder="$t('addOwnerCommittee.required') + $t('addOwnerCommittee.post')"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="$t('addOwnerCommittee.postDesc')">
              <el-input
                v-model="formData.postDesc"
                :placeholder="$t('addOwnerCommittee.optional') + $t('addOwnerCommittee.postDesc')"
              />
            </el-form-item>
          </el-col>
        </el-row>
  
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item :label="$t('addOwnerCommittee.appointTime')" prop="appointTime">
              <el-input
                v-model="formData.appointTime"
                :placeholder="$t('addOwnerCommittee.required') + $t('addOwnerCommittee.appointTime')"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="$t('addOwnerCommittee.curTime')" prop="curTime">
              <el-input
                v-model="formData.curTime"
                :placeholder="$t('addOwnerCommittee.required') + $t('addOwnerCommittee.curTime')"
              />
            </el-form-item>
          </el-col>
        </el-row>
  
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item :label="$t('addOwnerCommittee.state')" prop="state">
              <el-select
                v-model="formData.state"
                :placeholder="$t('addOwnerCommittee.required') + $t('addOwnerCommittee.state')"
                style="width:100%"
              >
                <el-option :label="$t('addOwnerCommittee.inService')" value="1000" />
                <el-option :label="$t('addOwnerCommittee.leave')" value="2000" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="$t('addOwnerCommittee.remark')">
              <el-input
                v-model="formData.remark"
                type="textarea"
                :placeholder="$t('addOwnerCommittee.optional') + $t('addOwnerCommittee.remark')"
              />
            </el-form-item>
          </el-col>
        </el-row>
  
        <el-card class="box-card" style="margin-top:20px">
          <div slot="header" class="clearfix">
            <span>{{ $t('addOwnerCommittee.emergencyContact') }}</span>
            <el-button type="primary" size="mini" style="float: right; padding: 3px 0" @click="addContract">
              {{ $t('addOwnerCommittee.add') }}
            </el-button>
          </div>
          <el-table :data="formData.contracts" border style="width: 100%">
            <el-table-column :label="$t('addOwnerCommittee.contactRelation')" align="center">
              <template slot-scope="scope">
                <el-input
                  v-model="scope.row.relName"
                  :placeholder="$t('addOwnerCommittee.required') + $t('addOwnerCommittee.contactRelation')"
                />
              </template>
            </el-table-column>
            <el-table-column :label="$t('addOwnerCommittee.contactName')" align="center">
              <template slot-scope="scope">
                <el-input
                  v-model="scope.row.name"
                  :placeholder="$t('addOwnerCommittee.required') + $t('addOwnerCommittee.contactName')"
                />
              </template>
            </el-table-column>
            <el-table-column :label="$t('addOwnerCommittee.contactPhone')" align="center">
              <template slot-scope="scope">
                <el-input
                  v-model="scope.row.link"
                  :placeholder="$t('addOwnerCommittee.required') + $t('addOwnerCommittee.contactPhone')"
                />
              </template>
            </el-table-column>
            <el-table-column :label="$t('addOwnerCommittee.contactAddress')" align="center" width="250">
              <template slot-scope="scope">
                <el-input
                  v-model="scope.row.address"
                  :placeholder="$t('addOwnerCommittee.required') + $t('addOwnerCommittee.contactAddress')"
                />
              </template>
            </el-table-column>
            <el-table-column :label="$t('addOwnerCommittee.operation')" align="center" width="100">
              <template slot-scope="scope">
                <el-button type="danger" size="mini" @click="deleteContract(scope.row)">
                  {{ $t('addOwnerCommittee.delete') }}
                </el-button>
              </template>
            </el-table-column>
          </el-table>
        </el-card>
      </el-form>
  
      <div slot="footer" class="dialog-footer">
        <el-button @click="visible = false">{{ $t('addOwnerCommittee.back') }}</el-button>
        <el-button type="primary" @click="saveOwnerCommitteeInfo">{{ $t('addOwnerCommittee.save') }}</el-button>
      </div>
    </el-dialog>
  </template>
  
  <script>
  import { saveOwnerCommittee } from '@/api/owner/addOwnerCommitteeApi'
  import { getCommunityId } from '@/api/community/communityApi'
  
  export default {
    name: 'AddOwnerCommittee',
    data() {
      return {
        visible: false,
        formData: {
          name: '',
          sex: '',
          link: '',
          idCard: '',
          address: '',
          position: '',
          post: '',
          postDesc: '',
          appointTime: '',
          curTime: '',
          state: '',
          remark: '',
          contracts: []
        },
        rules: {
          name: [
            { required: true, message: this.$t('addOwnerCommittee.required') + this.$t('addOwnerCommittee.name'), trigger: 'blur' },
            { max: 30, message: this.$t('addOwnerCommittee.name') + this.$t('addOwnerCommittee.maxLength30'), trigger: 'blur' }
          ],
          sex: [
            { required: true, message: this.$t('addOwnerCommittee.required') + this.$t('addOwnerCommittee.sex'), trigger: 'change' }
          ],
          link: [
            { required: true, message: this.$t('addOwnerCommittee.required') + this.$t('addOwnerCommittee.phone'), trigger: 'blur' },
            { max: 11, message: this.$t('addOwnerCommittee.phone') + this.$t('addOwnerCommittee.maxLength11'), trigger: 'blur' }
          ],
          idCard: [
            { required: true, message: this.$t('addOwnerCommittee.required') + this.$t('addOwnerCommittee.idCard'), trigger: 'blur' },
            { max: 18, message: this.$t('addOwnerCommittee.idCard') + this.$t('addOwnerCommittee.maxLength18'), trigger: 'blur' }
          ],
          address: [
            { required: true, message: this.$t('addOwnerCommittee.required') + this.$t('addOwnerCommittee.address'), trigger: 'blur' },
            { max: 256, message: this.$t('addOwnerCommittee.address') + this.$t('addOwnerCommittee.maxLength256'), trigger: 'blur' }
          ],
          position: [
            { required: true, message: this.$t('addOwnerCommittee.required') + this.$t('addOwnerCommittee.position'), trigger: 'blur' },
            { max: 64, message: this.$t('addOwnerCommittee.position') + this.$t('addOwnerCommittee.maxLength64'), trigger: 'blur' }
          ],
          post: [
            { required: true, message: this.$t('addOwnerCommittee.required') + this.$t('addOwnerCommittee.post'), trigger: 'blur' },
            { max: 64, message: this.$t('addOwnerCommittee.post') + this.$t('addOwnerCommittee.maxLength64'), trigger: 'blur' }
          ],
          postDesc: [
            { max: 64, message: this.$t('addOwnerCommittee.postDesc') + this.$t('addOwnerCommittee.maxLength64'), trigger: 'blur' }
          ],
          appointTime: [
            { required: true, message: this.$t('addOwnerCommittee.required') + this.$t('addOwnerCommittee.appointTime'), trigger: 'blur' },
            { max: 256, message: this.$t('addOwnerCommittee.appointTime') + this.$t('addOwnerCommittee.maxLength256'), trigger: 'blur' }
          ],
          curTime: [
            { required: true, message: this.$t('addOwnerCommittee.required') + this.$t('addOwnerCommittee.curTime'), trigger: 'blur' },
            { max: 256, message: this.$t('addOwnerCommittee.curTime') + this.$t('addOwnerCommittee.maxLength256'), trigger: 'blur' }
          ],
          state: [
            { required: true, message: this.$t('addOwnerCommittee.required') + this.$t('addOwnerCommittee.state'), trigger: 'change' }
          ],
          remark: [
            { max: 200, message: this.$t('addOwnerCommittee.remark') + this.$t('addOwnerCommittee.maxLength200'), trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      open() {
        this.visible = true
      },
      resetForm() {
        this.$refs.form.resetFields()
        this.formData = {
          name: '',
          sex: '',
          link: '',
          idCard: '',
          address: '',
          position: '',
          post: '',
          postDesc: '',
          appointTime: '',
          curTime: '',
          state: '',
          remark: '',
          contracts: []
        }
      },
      addContract() {
        this.formData.contracts.push({
          id: this.generateUUID(),
          relName: '',
          name: '',
          link: '',
          address: ''
        })
      },
      deleteContract(contract) {
        const index = this.formData.contracts.findIndex(item => item.id === contract.id)
        if (index !== -1) {
          this.formData.contracts.splice(index, 1)
        }
      },
      generateUUID() {
        return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
          const r = Math.random() * 16 | 0
          const v = c === 'x' ? r : (r & 0x3 | 0x8)
          return v.toString(16)
        })
      },
      async saveOwnerCommitteeInfo() {
        this.$refs.form.validate(async valid => {
          if (valid) {
            try {
              const communityId = await getCommunityId()
              const data = {
                ...this.formData,
                communityId
              }
              await saveOwnerCommittee(data)
              this.$message.success(this.$t('common.saveSuccess'))
              this.visible = false
              this.$emit('success')
            } catch (error) {
              this.$message.error(error.message || this.$t('common.saveFailed'))
            }
          }
        })
      }
    }
  }
  </script>