|
@@ -0,0 +1,194 @@
|
|
|
+<script setup lang="ts">
|
|
|
+defineOptions({ name: 'staffDetail' })
|
|
|
+
|
|
|
+import { useQuery, useMutation } from '@tanstack/vue-query'
|
|
|
+import { getRecordsDetail, editRecordsDetail } from '@/api/oa/staffRecords'
|
|
|
+import { formConfigList, formRules } from './index'
|
|
|
+import { FormInstance } from 'element-plus'
|
|
|
+import { staffNumFormatter } from '@/utils/formatter'
|
|
|
+
|
|
|
+const { query } = useRoute()
|
|
|
+const { id, type } = query
|
|
|
+
|
|
|
+const formRef = ref<FormInstance>()
|
|
|
+
|
|
|
+const formData = ref({})
|
|
|
+
|
|
|
+/**获取员工档案详情 */
|
|
|
+const { data } = useQuery(
|
|
|
+ ['fetch-staff-detail', id],
|
|
|
+ async () => {
|
|
|
+ return await getRecordsDetail({ userId: id })
|
|
|
+ },
|
|
|
+ {
|
|
|
+ onSuccess: (res) => {
|
|
|
+ formData.value = res
|
|
|
+ }
|
|
|
+ }
|
|
|
+)
|
|
|
+
|
|
|
+/**编辑员工档案详情 */
|
|
|
+const { mutate: addUserMutate } = useMutation({
|
|
|
+ mutationFn: async (values: any) => {
|
|
|
+ return await editRecordsDetail(values)
|
|
|
+ },
|
|
|
+ onSuccess(data) {
|
|
|
+ if (data?.code === 20000) {
|
|
|
+ ElMessage({
|
|
|
+ message: '员工档案修改成功!',
|
|
|
+ type: 'success'
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ ElMessage({
|
|
|
+ // message: data?.msg,
|
|
|
+ message: '员工档案修改成功!',
|
|
|
+ type: 'success'
|
|
|
+ })
|
|
|
+ }
|
|
|
+ },
|
|
|
+ onError() {
|
|
|
+ ElMessage({
|
|
|
+ message: '员工档案修改失败!',
|
|
|
+ type: 'error'
|
|
|
+ })
|
|
|
+ }
|
|
|
+})
|
|
|
+
|
|
|
+/**表单保存 */
|
|
|
+const submitForm = (formEl: FormInstance | undefined) => {
|
|
|
+ if (!formEl) return
|
|
|
+ formEl.validate((valid) => {
|
|
|
+ if (valid) {
|
|
|
+ addUserMutate(formData.value)
|
|
|
+ } else {
|
|
|
+ console.log('error submit!')
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+/**重置表单 */
|
|
|
+const resetForm = (formEl: FormInstance | undefined) => {
|
|
|
+ if (!formEl) return
|
|
|
+ formEl.resetFields()
|
|
|
+ formData.value = data
|
|
|
+}
|
|
|
+</script>
|
|
|
+<template>
|
|
|
+ <div class="staff-files-wrap">
|
|
|
+ <div class="staff-name">
|
|
|
+ <span>{{ formData?.nickname }}员工档案</span>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <div class="my-portrait" v-if="formData != undefined">
|
|
|
+ <el-form
|
|
|
+ ref="formRef"
|
|
|
+ :model="formData"
|
|
|
+ :rules="formRules"
|
|
|
+ label-width="120px"
|
|
|
+ :disabled="type === 'view'"
|
|
|
+ >
|
|
|
+ <div class="my-portrait-item" v-for="(item, index) in formConfigList" :key="index">
|
|
|
+ <div class="title">
|
|
|
+ <i></i>
|
|
|
+ <span>{{ item.title }}</span>
|
|
|
+ </div>
|
|
|
+ <div class="my-portrait-card">
|
|
|
+ <ul>
|
|
|
+ <li v-for="(child, c) in item.children" :key="c">
|
|
|
+ <el-form-item :label="`${child.title}:`" :prop="child.name">
|
|
|
+ <el-date-picker
|
|
|
+ v-if="child.type === 'time'"
|
|
|
+ v-model="formData[child?.name]"
|
|
|
+ style="width: 100%"
|
|
|
+ :placeholder="child.title"
|
|
|
+ type="date"
|
|
|
+ value-format="YYYY-MM-DD"
|
|
|
+ />
|
|
|
+ <el-input v-else v-model="formData[child?.name]" placeholder="" />
|
|
|
+ </el-form-item>
|
|
|
+ <!-- :formatter="(value) => staffNumFormatter(value, child?.name)"
|
|
|
+ -->
|
|
|
+ </li>
|
|
|
+ <li></li>
|
|
|
+ </ul>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <el-row justify="center">
|
|
|
+ <el-form-item v-if="type === 'edit'">
|
|
|
+ <el-button color="#1B80EB" type="primary" @click="submitForm(formRef)">保存</el-button>
|
|
|
+ <el-button @click="resetForm(formRef)">重置</el-button>
|
|
|
+ </el-form-item>
|
|
|
+ </el-row>
|
|
|
+ </el-form>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<style lang="scss" scoped>
|
|
|
+.staff-files-wrap {
|
|
|
+ height: calc(100% - 10px);
|
|
|
+ padding: 26px 30px;
|
|
|
+ margin: 40px 0 25px;
|
|
|
+ overflow: hidden;
|
|
|
+ background: #fff;
|
|
|
+ border-radius: 20px;
|
|
|
+
|
|
|
+ .staff-name {
|
|
|
+ span {
|
|
|
+ display: block;
|
|
|
+ font-family: 'Microsoft YaHei';
|
|
|
+ font-size: 32px;
|
|
|
+ font-weight: bold;
|
|
|
+ color: #2d333c;
|
|
|
+ text-align: center;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ .my-portrait {
|
|
|
+ width: 100%;
|
|
|
+ height: calc(100% - 40px);
|
|
|
+ padding: 10px 0 0;
|
|
|
+ overflow: auto;
|
|
|
+
|
|
|
+ .my-portrait-item {
|
|
|
+ margin-bottom: 20px;
|
|
|
+
|
|
|
+ .title {
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ margin-bottom: 8px;
|
|
|
+
|
|
|
+ i {
|
|
|
+ display: block;
|
|
|
+ width: 16px;
|
|
|
+ height: 16px;
|
|
|
+ margin-right: 9px;
|
|
|
+ background: url('../../../../assets/imgs/OA/mine/star.png') center no-repeat;
|
|
|
+ background-size: 100%;
|
|
|
+ }
|
|
|
+
|
|
|
+ span {
|
|
|
+ font-size: 18px;
|
|
|
+ font-weight: bold;
|
|
|
+ color: #2d333c;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ ul {
|
|
|
+ display: flex;
|
|
|
+ padding: 20px 40px 0;
|
|
|
+ background-color: #f7f8fa;
|
|
|
+ border-radius: 4px;
|
|
|
+ flex-wrap: wrap;
|
|
|
+ justify-content: space-between;
|
|
|
+
|
|
|
+ li {
|
|
|
+ width: calc(33.3% - 40px);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+</style>
|