Просмотр исходного кода

feat: 更新员工基本信息

lanjianrong 4 лет назад
Родитель
Сommit
4886c29e26
2 измененных файлов с 43 добавлено и 13 удалено
  1. 29 13
      src/pages/User/Account/Settings/components/BaseView.jsx
  2. 14 0
      src/services/user.js

+ 29 - 13
src/pages/User/Account/Settings/components/BaseView.jsx

@@ -1,5 +1,5 @@
 import React, { useState, useEffect, useRef } from 'react'
-import { Button, Col, Row, Tabs, Upload } from 'antd'
+import { Button, Col, message, Row, Tabs, Upload } from 'antd'
 import ProForm, {
   ProFormDatePicker,
   ProFormSelect,
@@ -15,7 +15,7 @@ import {
   marriageOptions
 } from '@/components/EditableForm/src/useOptions'
 import { UploadOutlined } from '@ant-design/icons'
-import { queryStaffOwner } from '@/services/user'
+import { queryStaffOwner, updateBaseStaff, updateFinanceStaff } from '@/services/user'
 import consts from '@/consts'
 
 const { TabPane } = Tabs
@@ -49,19 +49,12 @@ const AvatarView = ({ avatar }) => (
 
 const BaseView = () => {
   const baseRef = useRef(null)
-  // const baseRef = useRef(null)
-  const financialRef = useRef(null)
   const [staff, setStaff] = useState(null)
   const layout = {
     layout: 'horizontal',
     labelCol: { flex: '120px' }
   }
-  const handleTabChange = key => {
-    console.log(key)
-    if (key === '3') {
-      financialRef.current?.setFieldsValue({ ...staff })
-    }
-  }
+
   useEffect(() => {
     async function initData() {
       const { code = -1, data = {} } = await queryStaffOwner()
@@ -73,14 +66,20 @@ const BaseView = () => {
     initData()
   }, [])
   return (
-    <Tabs defaultActiveKey="1" onChange={handleTabChange}>
+    <Tabs defaultActiveKey="1">
       <TabPane tab="基本信息" key="1">
         <div className={styles.baseView}>
           <div className={styles.left}>
             <ProForm
               {...layout}
               formRef={baseRef}
-              // onFinish={handleFinish}
+              onFinish={async values => {
+                const { code = -1 } = await updateBaseStaff(values)
+                if (code === consts.RET_CODE.SUCCESS) {
+                  message.success('更新成功')
+                }
+                return true
+              }}
               submitter={{
                 resetButtonProps: false,
                 submitButtonProps: {
@@ -232,7 +231,24 @@ const BaseView = () => {
       <TabPane tab="财务信息" key="3">
         <div className={styles.baseView}>
           <div className="w-3/4">
-            <ProForm layout="horizontal" labelCol={{ flex: '150px' }} formRef={financialRef}>
+            <ProForm
+              layout="horizontal"
+              labelCol={{ flex: '150px' }}
+              onFinish={async values => {
+                const { code = -1 } = await updateFinanceStaff(values)
+                if (code === consts.RET_CODE.SUCCESS) {
+                  message.success('更新成功')
+                }
+                return true
+              }}
+              submitter={{
+                resetButtonProps: false,
+                submitButtonProps: {
+                  className: 'ml-150px'
+                }
+              }}
+              initialValues={{ ...staff }}
+            >
               {/* <ProFormGroup title="报销收款帐号"> */}
               <h4 className="mb-4 font-bold">报销收款帐号</h4>
               <Row>

+ 14 - 0
src/services/user.js

@@ -23,3 +23,17 @@ export async function queryPermData(params) {
 export async function queryStaffOwner() {
   return request('/staff/own')
 }
+
+/** 更新员工基本信息 */
+export async function updateBaseStaff(params) {
+  return request.post('/staff/update/base', {
+    data: params
+  })
+}
+
+/** 更新员工财务信息 */
+export async function updateFinanceStaff(params) {
+  return request.post('/staff/update/finance', {
+    data: params
+  })
+}