Blame view

src/components/staff/editStaff.vue 5.49 KB
a42b3256   wuxw   HC小区管理系统前段vue版正在开发中
1
2
  <!-- components/staff/editStaff.vue -->
  <template>
ebc1053d   wuxw   加入运营员工详情功能
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
    <el-dialog
      :title="$t('staff.modifyStaff')"
      :visible.sync="visible"
      width="50%"
      @close="handleClose"
    >
      <el-form ref="form" :model="editStaffInfo" label-width="120px">
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item :label="$t('staff.name')" prop="username">
              <el-input
                v-model="editStaffInfo.username"
                :placeholder="$t('staff.requiredName')"
              />
            </el-form-item>
            <el-form-item :label="$t('email')" prop="email">
              <el-input
                v-model="editStaffInfo.email"
                :placeholder="$t('staff.optionalEmail')"
              />
            </el-form-item>
            <el-form-item :label="$t('staff.phone')" prop="tel">
              <el-input
                v-model="editStaffInfo.tel"
                :placeholder="$t('staff.requiredPhone')"
              />
            </el-form-item>
            <el-form-item :label="$t('staff.gender')" prop="sex">
              <el-select
                v-model="editStaffInfo.sex"
                :placeholder="$t('staff.requiredGender')"
                style="width: 100%"
a42b3256   wuxw   HC小区管理系统前段vue版正在开发中
35
              >
ebc1053d   wuxw   加入运营员工详情功能
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
                <el-option :value="0" :label="$t('staff.male')" />
                <el-option :value="1" :label="$t('staff.female')" />
              </el-select>
            </el-form-item>
            <el-form-item :label="$t('staff.address')" prop="address">
              <el-input
                v-model="editStaffInfo.address"
                :placeholder="$t('staff.requiredAddress')"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12" style="text-align: center">
            <el-image
              style="width: 200px; height: 200px"
              :src="editStaffInfo.photoUrl"
              fit="cover"
            >
              <div slot="error" class="image-slot">
                <i class="el-icon-picture-outline"></i>
a42b3256   wuxw   HC小区管理系统前段vue版正在开发中
55
              </div>
ebc1053d   wuxw   加入运营员工详情功能
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
            </el-image>
            <div style="margin-top: 20px">
              <el-upload
                action=""
                :auto-upload="false"
                :show-file-list="false"
                :on-change="handlePhotoChange"
              >
                <el-button type="primary">{{ $t('staff.uploadPhoto') }}</el-button>
              </el-upload>
            </div>
          </el-col>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="handleClose">{{ $t('staff.cancel') }}</el-button>
        <el-button type="primary" @click="editStaffSubmit">{{ $t('staff.edit') }}</el-button>
      </span>
    </el-dialog>
  </template>
  
  <script>
  import { modifyStaff } from '@/api/staff/staffApi'
  
  export default {
    name: 'EditStaff',
    props: {
      visible: {
        type: Boolean,
        default: false
a42b3256   wuxw   HC小区管理系统前段vue版正在开发中
86
      },
ebc1053d   wuxw   加入运营员工详情功能
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
      staffInfo: {
        type: Object,
        default: () => ({})
      }
    },
    data() {
      return {
        loading: false,
        editStaffInfo: {
          userId: '',
          username: '',
          email: '',
          tel: '',
          sex: '',
          address: '',
          photo: '',
          photoUrl: '',
          relCd: '',
          relCds: [],
          branchOrgs: [],
          departmentOrgs: [],
          parentOrgId: '',
          parentOrgName: '',
          parentTwoOrgId: '',
          orgNewName: '',
          orgId: ''
a42b3256   wuxw   HC小区管理系统前段vue版正在开发中
113
        }
ebc1053d   wuxw   加入运营员工详情功能
114
115
116
117
118
119
120
121
122
123
124
      }
    },
    watch: {
      staffInfo: {
        immediate: true,
        handler(val) {
          if (val) {
            this.editStaffInfo = {
              ...val,
              username: val.name,
              photoUrl: val.faceUrl || '/img/noPhoto.jpg'
a42b3256   wuxw   HC小区管理系统前段vue版正在开发中
125
126
127
            }
          }
        }
ebc1053d   wuxw   加入运营员工详情功能
128
129
130
131
132
133
134
135
136
137
      }
    },
    methods: {
      open(row){
        this.editStaffInfo = {
              ...row,
              username: row.name,
              photoUrl: row.faceUrl || '/img/noPhoto.jpg'
            }
        this.visible = true
a42b3256   wuxw   HC小区管理系统前段vue版正在开发中
138
      },
ebc1053d   wuxw   加入运营员工详情功能
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
      handleClose() {
        this.$emit('update:visible', false)
      },
      handlePhotoChange(file) {
        if (file.size > 2 * 1024 * 1024) {
          this.$message.error(this.$t('staff.photoSizeLimit'))
          return false
        }
        
        const reader = new FileReader()
        reader.onload = (e) => {
          this.editStaffInfo.photoUrl = e.target.result
          // Here you would typically upload the file to server
          // and set editStaffInfo.photo to the returned file ID
          this.editStaffInfo.photo = file.uid // Temporary, replace with actual file ID
        }
        reader.readAsDataURL(file.raw)
      },
      validateForm() {
        if (!this.editStaffInfo.username) {
          this.$message.error(this.$t('staff.requiredName'))
          return false
        }
        if (!this.editStaffInfo.tel) {
          this.$message.error(this.$t('staff.requiredPhone'))
          return false
        }
        if (this.editStaffInfo.sex === '') {
          this.$message.error(this.$t('staff.requiredGender'))
          return false
        }
        if (!this.editStaffInfo.address) {
          this.$message.error(this.$t('staff.requiredAddress'))
          return false
        }
        return true
      },
      async editStaffSubmit() {
        if (!this.validateForm()) return
        
        try {
          this.loading = true
          const data = {
            ...this.editStaffInfo,
            name: this.editStaffInfo.username,
            staffId: this.editStaffInfo.userId
a42b3256   wuxw   HC小区管理系统前段vue版正在开发中
185
          }
a42b3256   wuxw   HC小区管理系统前段vue版正在开发中
186
          
ebc1053d   wuxw   加入运营员工详情功能
187
188
189
190
191
192
193
194
195
          await modifyStaff(data)
          this.visible =false
          this.$message.success(this.$t('staff.modifySuccess'))
          this.$emit('success')
          this.handleClose()
        } catch (error) {
          this.$message.error(error.message)
        } finally {
          this.loading = false
a42b3256   wuxw   HC小区管理系统前段vue版正在开发中
196
197
198
        }
      }
    }
ebc1053d   wuxw   加入运营员工详情功能
199
200
  }
  </script>