Blame view

src/components/staff/editStaff.vue 5.87 KB
6ec243d6   wuxw   v1.9 点击提交后,成功提示没有...
1
  <!-- components/staff/editStaff.vue -->
a42b3256   wuxw   HC小区管理系统前段vue版正在开发中
2
  <template>
702baeae   wuxw   v1.9 优化员工没有岗位问题
3
    <el-dialog :title="$t('staff.modifyStaff')" :visible.sync="visible" width="50%" @close="handleClose">
ebc1053d   wuxw   加入运营员工详情功能
4
5
6
7
      <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">
702baeae   wuxw   v1.9 优化员工没有岗位问题
8
              <el-input v-model="editStaffInfo.username" :placeholder="$t('staff.requiredName')" />
ebc1053d   wuxw   加入运营员工详情功能
9
10
            </el-form-item>
            <el-form-item :label="$t('email')" prop="email">
702baeae   wuxw   v1.9 优化员工没有岗位问题
11
              <el-input v-model="editStaffInfo.email" :placeholder="$t('staff.optionalEmail')" />
ebc1053d   wuxw   加入运营员工详情功能
12
13
            </el-form-item>
            <el-form-item :label="$t('staff.phone')" prop="tel">
702baeae   wuxw   v1.9 优化员工没有岗位问题
14
              <el-input v-model="editStaffInfo.tel" :placeholder="$t('staff.requiredPhone')" />
ebc1053d   wuxw   加入运营员工详情功能
15
16
            </el-form-item>
            <el-form-item :label="$t('staff.gender')" prop="sex">
702baeae   wuxw   v1.9 优化员工没有岗位问题
17
18
19
20
21
22
23
24
25
              <el-select v-model="editStaffInfo.sex" :placeholder="$t('staff.requiredGender')" style="width: 100%">
                <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.relCd')" prop="relCd">
              <el-select v-model="editStaffInfo.relCd" :placeholder="$t('staff.relCdPlaceholder')" style="width: 100%">
                <el-option v-for="(item,index) in editStaffInfo.relCds" :key="index" :label="item.name"
                  :value="item.statusCd" />
ebc1053d   wuxw   加入运营员工详情功能
26
27
28
              </el-select>
            </el-form-item>
            <el-form-item :label="$t('staff.address')" prop="address">
702baeae   wuxw   v1.9 优化员工没有岗位问题
29
              <el-input v-model="editStaffInfo.address" :placeholder="$t('staff.requiredAddress')" />
ebc1053d   wuxw   加入运营员工详情功能
30
31
32
            </el-form-item>
          </el-col>
          <el-col :span="12" style="text-align: center">
69e18472   wuxw   v1.9 员工头像不对问题
33
34
35
36
37
38
39
            <el-image style="width: 200px; height: 150px; border: 1px dashed #ccc;"
              :src="editStaffInfo.photoUrl || '/img/noPhoto.jpg'" fit="cover" />
            <el-upload class="mt-10" :show-file-list="false" :before-upload="beforeUpload" :http-request="uploadImage" action="">
              <el-button size="small" type="primary">
                {{ $t('common.upload') }}
              </el-button>
            </el-upload>
ebc1053d   wuxw   加入运营员工详情功能
40
41
42
43
44
45
46
47
48
49
50
51
          </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'
702baeae   wuxw   v1.9 优化员工没有岗位问题
52
  import { getDict } from '../../api/community/communityApi'
69e18472   wuxw   v1.9 员工头像不对问题
53
54
  import { uploadImage } from '@/api/owner/ownerApi'
  
ebc1053d   wuxw   加入运营员工详情功能
55
56
57
58
  
  export default {
    name: 'EditStaff',
    props: {
ebc1053d   wuxw   加入运营员工详情功能
59
60
61
62
63
64
65
      staffInfo: {
        type: Object,
        default: () => ({})
      }
    },
    data() {
      return {
702baeae   wuxw   v1.9 优化员工没有岗位问题
66
        visible: false,
ebc1053d   wuxw   加入运营员工详情功能
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
        loading: false,
        editStaffInfo: {
          userId: '',
          username: '',
          email: '',
          tel: '',
          sex: '',
          address: '',
          photo: '',
          photoUrl: '',
          relCd: '',
          relCds: [],
          branchOrgs: [],
          departmentOrgs: [],
          parentOrgId: '',
          parentOrgName: '',
          parentTwoOrgId: '',
          orgNewName: '',
          orgId: ''
a42b3256   wuxw   HC小区管理系统前段vue版正在开发中
86
        }
ebc1053d   wuxw   加入运营员工详情功能
87
88
89
90
91
92
93
94
95
96
      }
    },
    watch: {
      staffInfo: {
        immediate: true,
        handler(val) {
          if (val) {
            this.editStaffInfo = {
              ...val,
              username: val.name,
a42b3256   wuxw   HC小区管理系统前段vue版正在开发中
97
98
99
            }
          }
        }
ebc1053d   wuxw   加入运营员工详情功能
100
101
102
      }
    },
    methods: {
702baeae   wuxw   v1.9 优化员工没有岗位问题
103
      open(row) {
69e18472   wuxw   v1.9 员工头像不对问题
104
105
106
107
        let _url =  '/img/noPhoto.jpg'
        if(row.urls && row.urls.length > 0){
          _url = row.urls[0]
        }
ebc1053d   wuxw   加入运营员工详情功能
108
        this.editStaffInfo = {
702baeae   wuxw   v1.9 优化员工没有岗位问题
109
110
          ...row,
          username: row.name,
69e18472   wuxw   v1.9 员工头像不对问题
111
          photo: _url
702baeae   wuxw   v1.9 优化员工没有岗位问题
112
        }
69e18472   wuxw   v1.9 员工头像不对问题
113
114
        this.editStaffInfo.photoUrl = row.photoUrl || '/img/noPhoto.jpg'
        console.log(this.editStaffInfo.photoUrl)
702baeae   wuxw   v1.9 优化员工没有岗位问题
115
        this.getRelCd()
ebc1053d   wuxw   加入运营员工详情功能
116
        this.visible = true
702baeae   wuxw   v1.9 优化员工没有岗位问题
117
118
119
120
121
122
        
      },
      async getRelCd() {
        const data = await getDict('u_org_staff_rel', "rel_cd")
        this.editStaffInfo.relCds = data
        this.$forceUpdate()
a42b3256   wuxw   HC小区管理系统前段vue版正在开发中
123
      },
ebc1053d   wuxw   加入运营员工详情功能
124
      handleClose() {
702baeae   wuxw   v1.9 优化员工没有岗位问题
125
        this.visible = false
ebc1053d   wuxw   加入运营员工详情功能
126
      },
ebc1053d   wuxw   加入运营员工详情功能
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
      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
702baeae   wuxw   v1.9 优化员工没有岗位问题
148
  
ebc1053d   wuxw   加入运营员工详情功能
149
150
151
152
153
154
        try {
          this.loading = true
          const data = {
            ...this.editStaffInfo,
            name: this.editStaffInfo.username,
            staffId: this.editStaffInfo.userId
a42b3256   wuxw   HC小区管理系统前段vue版正在开发中
155
          }
702baeae   wuxw   v1.9 优化员工没有岗位问题
156
  
ebc1053d   wuxw   加入运营员工详情功能
157
          await modifyStaff(data)
702baeae   wuxw   v1.9 优化员工没有岗位问题
158
          this.visible = false
6ec243d6   wuxw   v1.9 点击提交后,成功提示没有...
159
          this.$message.success(this.$t('common.operationSuccess'))
ebc1053d   wuxw   加入运营员工详情功能
160
161
162
163
164
165
          this.$emit('success')
          this.handleClose()
        } catch (error) {
          this.$message.error(error.message)
        } finally {
          this.loading = false
a42b3256   wuxw   HC小区管理系统前段vue版正在开发中
166
        }
69e18472   wuxw   v1.9 员工头像不对问题
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
      },
      beforeUpload(file) {
        const isJPG = file.type === 'image/jpeg'
        const isLt2M = file.size / 1024 / 1024 < 2
  
        if (!isJPG) {
          this.$message.error(this.$t('common.jpgOnly'))
        }
        if (!isLt2M) {
          this.$message.error(this.$t('common.sizeLimit'))
        }
        return isJPG && isLt2M
      },
      async uploadImage({ file }) {
        try {
          const res = await uploadImage({ file })
          this.editStaffInfo.photo = res.fileId
          this.editStaffInfo.photoUrl = res.url
          this.$forceUpdate()
        } catch (error) {
          this.$message.error(this.$t('listOwner.upload.failed'))
        }
      },
a42b3256   wuxw   HC小区管理系统前段vue版正在开发中
190
    }
ebc1053d   wuxw   加入运营员工详情功能
191
192
  }
  </script>