staffDetail.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. <script setup lang="ts">
  2. defineOptions({ name: 'staffDetail' })
  3. import { useQuery, useMutation } from '@tanstack/vue-query'
  4. import { getRecordsDetail, editRecordsDetail } from '@/api/oa/staffRecords'
  5. import { formConfigList, formRules } from './index'
  6. import { FormInstance } from 'element-plus'
  7. const { query } = useRoute()
  8. const { id, type } = query
  9. const formRef = ref<FormInstance>()
  10. const formData = ref({})
  11. /**获取员工档案详情 */
  12. useQuery(
  13. ['fetch-staff-detail', id],
  14. async () => {
  15. return await getRecordsDetail({ userId: id })
  16. },
  17. {
  18. onSuccess: (res) => {
  19. formData.value = res
  20. }
  21. }
  22. )
  23. /**编辑员工档案详情 */
  24. const { mutate: addUserMutate } = useMutation({
  25. mutationFn: async (values: any) => {
  26. return await editRecordsDetail(values)
  27. },
  28. onSuccess(data) {
  29. if (data?.code === 20000) {
  30. ElMessage({
  31. message: '员工档案修改成功!',
  32. type: 'success'
  33. })
  34. } else {
  35. ElMessage({
  36. // message: data?.msg,
  37. message: '员工档案修改成功!',
  38. type: 'success'
  39. })
  40. }
  41. },
  42. onError() {
  43. ElMessage({
  44. message: '员工档案修改失败!',
  45. type: 'error'
  46. })
  47. }
  48. })
  49. /**表单保存 */
  50. const submitForm = (formEl: FormInstance | undefined) => {
  51. if (!formEl) return
  52. formEl.validate((valid) => {
  53. if (valid) {
  54. addUserMutate(formData.value)
  55. } else {
  56. console.log('error submit!')
  57. return false
  58. }
  59. })
  60. }
  61. const isEdit = computed(() => {
  62. return type === 'edit'
  63. })
  64. </script>
  65. <template>
  66. <div class="staff-files-wrap">
  67. <div class="staff-name">
  68. <span>{{ formData?.['nickname'] }}员工档案</span>
  69. </div>
  70. <div
  71. v-if="formData != undefined"
  72. :class="isEdit ? 'my-portrait' : 'my-portrait form-unable-edit'"
  73. >
  74. <el-form
  75. ref="formRef"
  76. :model="formData"
  77. :rules="formRules"
  78. label-width="150px"
  79. :disabled="!isEdit"
  80. >
  81. <div class="my-portrait-item" v-for="(item, index) in formConfigList" :key="index">
  82. <div class="title">
  83. <i></i>
  84. <span>{{ item.title }}</span>
  85. </div>
  86. <div class="my-portrait-card">
  87. <ul>
  88. <li v-for="(child, c) in item.children" :key="c">
  89. <el-form-item :label="`${child.title}:`" :prop="child.name">
  90. <el-date-picker
  91. v-if="child.type === 'time'"
  92. v-model="formData[child?.name]"
  93. style="width: 100%"
  94. :placeholder="isEdit ? child.title : ''"
  95. type="date"
  96. value-format="YYYY-MM-DD"
  97. />
  98. <el-select
  99. v-if="child.type === 'select'"
  100. v-model="formData[child?.name]"
  101. style="width: 100%"
  102. placeholder=""
  103. >
  104. <el-option
  105. v-for="item in child.options"
  106. :key="item.value"
  107. :label="item.label"
  108. :value="item.value"
  109. />
  110. </el-select>
  111. <el-input
  112. v-if="child?.type === undefined"
  113. v-model="formData[child?.name]"
  114. placeholder=""
  115. />
  116. </el-form-item>
  117. </li>
  118. <li></li>
  119. </ul>
  120. </div>
  121. </div>
  122. <el-row justify="end">
  123. <el-form-item v-if="isEdit">
  124. <el-button color="#1B80EB" type="primary" @click="submitForm(formRef)">保存</el-button>
  125. </el-form-item>
  126. </el-row>
  127. </el-form>
  128. </div>
  129. </div>
  130. </template>
  131. <style lang="scss" scoped>
  132. .staff-files-wrap {
  133. height: calc(100% - 10px);
  134. padding: 26px 30px;
  135. margin: 40px 0 25px;
  136. overflow: hidden;
  137. background: #fff;
  138. border-radius: 20px;
  139. .staff-name {
  140. span {
  141. display: block;
  142. font-family: 'Microsoft YaHei';
  143. font-size: 32px;
  144. font-weight: bold;
  145. color: #2d333c;
  146. text-align: center;
  147. }
  148. }
  149. .my-portrait {
  150. width: 100%;
  151. height: calc(100% - 40px);
  152. padding: 0 0 10px;
  153. overflow: auto;
  154. .my-portrait-item {
  155. margin-bottom: 20px;
  156. .title {
  157. display: flex;
  158. align-items: center;
  159. margin-bottom: 8px;
  160. i {
  161. display: block;
  162. width: 16px;
  163. height: 16px;
  164. margin-right: 9px;
  165. background: url('../../../../assets/imgs/OA/mine/star.png') center no-repeat;
  166. background-size: 100%;
  167. }
  168. span {
  169. font-size: 18px;
  170. font-weight: bold;
  171. color: #2d333c;
  172. }
  173. }
  174. ul {
  175. display: flex;
  176. padding: 20px 40px 0;
  177. background: #f7f8fa;
  178. border-radius: 4px;
  179. flex-wrap: wrap;
  180. justify-content: space-between;
  181. li {
  182. width: calc(33.3% - 40px);
  183. }
  184. }
  185. }
  186. }
  187. .form-unable-edit {
  188. .my-portrait-item {
  189. ul {
  190. background: linear-gradient(90deg, #f2f7ff 0%, rgb(245 249 255 / 0%) 100%);
  191. border: 1px solid #e4e9f1;
  192. }
  193. }
  194. :deep(.el-form) {
  195. .el-input.is-disabled .el-input__wrapper {
  196. background-color: unset;
  197. box-shadow: none;
  198. }
  199. .el-form-item__label {
  200. font-size: 16px;
  201. color: #455773;
  202. }
  203. .el-form-item--default {
  204. margin-bottom: 10px;
  205. }
  206. .el-input__inner {
  207. font-family: 'Microsoft YaHei';
  208. font-size: 16px;
  209. font-weight: 500;
  210. color: #2d333c;
  211. }
  212. .el-input__suffix {
  213. display: none;
  214. }
  215. }
  216. }
  217. }
  218. </style>