瀏覽代碼

fix: 执行者编辑、新增的逻辑bug

fix: 编号规则请求问题
lanjianrong 2 年之前
父節點
當前提交
47e241f0ef

+ 0 - 1
src/app.tsx

@@ -52,7 +52,6 @@ const authHeaderInterceptor = options => {
 
 const errorHandler = (error: any, opts: any) => {
   if (opts?.skipErrorHandler) return
-
   const errorInfo = error.info
   if (errorInfo) {
     const { errorMessage = '请求失败', errorCode } = errorInfo

+ 20 - 12
src/pages/Business/Process/components/MemberItem.tsx

@@ -1,7 +1,7 @@
 import { queryAcountListByInstitutionID } from '@/services/api/institution'
 import { queryInstitutionRoleList } from '@/services/api/project'
 import consts from '@/utils/consts'
-import { isArray } from '@/utils/is'
+import { isArray, isString } from '@/utils/is'
 import { useRequest } from '@umijs/max'
 import { Select, TreeSelect } from 'antd'
 import { useState } from 'react'
@@ -19,9 +19,9 @@ const auditTypeOptions = [
 ]
 
 type MemberItemProps = {
-  value: {
-    type: AuditType
-    value: string | string[]
+  value?: {
+    type?: AuditType
+    value?: string | string[]
   }
   onChange: (value?: { type: AuditType; value: string[] }) => void
 }
@@ -64,6 +64,7 @@ const MemberItem: React.FC<MemberItemProps> = ({ value, onChange }) => {
     memberOptions: [],
     members: value
   })
+
   useRequest(
     () => {
       let requestFn: Nullable<() => Promise<void>> = null
@@ -93,38 +94,45 @@ const MemberItem: React.FC<MemberItemProps> = ({ value, onChange }) => {
     }
   )
   const toggleChange = value => {
+    let val = value
+    if (!isArray(val)) {
+      val = [value]
+    }
     if (value) {
-      onChange?.({ type: state.auditType, value })
+      onChange?.({ type: state.auditType, value: val })
     }
-    setState({ ...state, members: { ...state.members, value } })
+    setState({ ...state, members: { ...state.members, value: val } })
   }
   const toggleAuditType = (value: AuditType) =>
     setState({ ...state, auditType: value, members: { type: value, value: [] } })
 
   return (
-    <div>
+    <div className="flex flex-row">
       <Select
         value={state.auditType}
         options={auditTypeOptions}
         onChange={toggleAuditType}
-        style={{ width: '100%' }}
+        style={{ width: '30%' }}
       />
       {state.auditType === AuditType.ACCOUNT ? (
         <TreeSelect
-          value={state.members?.value.map(item => item.ID)}
+          value={state.members?.value.map(item => {
+            if (isString(item)) return item
+            return item.ID
+          })}
           treeData={state.memberOptions}
           onChange={toggleChange}
           multiple
           maxTagCount="responsive"
-          style={{ width: '100%', marginTop: '4px' }}
+          style={{ width: '70%', marginLeft: '4px' }}
         />
       ) : (
         <Select
-          value={state.members?.value.map(item => item.ID)}
+          value={state.members?.value?.[0]?.ID || state.members?.value?.[0]}
           options={state.memberOptions}
           onChange={toggleChange}
           fieldNames={{ label: 'title' }}
-          style={{ width: '100%', marginTop: '4px' }}
+          style={{ width: '70%', marginLeft: '4px' }}
         />
       )}
     </div>

+ 16 - 12
src/pages/Business/Process/hooks/useScripts.tsx

@@ -4,7 +4,7 @@ import { useState } from 'react'
 import { useRequest } from 'ahooks'
 import { addExecutor, delExecutor, queryExecutorList, updateExecutor } from '@/services/api/business'
 import { ApprovalType, BusinessType, ExecutorSetType } from '@/enums/gc'
-import { ExclamationCircleFilled } from '@ant-design/icons'
+import { QuestionCircleFilled } from '@ant-design/icons'
 import { Form, message, Tooltip } from 'antd'
 import ProForm, { ProFormRadio, ProFormText } from '@ant-design/pro-form'
 
@@ -16,7 +16,7 @@ const setTypeOptions = [
       <div>
         <span className="mr-1">预置成员</span>
         <Tooltip title="审批用户为该角色绑定成员">
-          <ExclamationCircleFilled style={{ color: 'orange' }} />
+          <QuestionCircleFilled style={{ color: 'orange' }} />
         </Tooltip>
       </div>
     ),
@@ -27,7 +27,7 @@ const setTypeOptions = [
       <div>
         <span className="mr-1">步骤设置</span>
         <Tooltip title="审批用户为该角色动态配置">
-          <ExclamationCircleFilled style={{ color: 'orange' }} />
+          <QuestionCircleFilled style={{ color: 'orange' }} />
         </Tooltip>
       </div>
     ),
@@ -53,6 +53,8 @@ export default function useScripts(modal: ModalAction, business: BusinessType) {
   })
 
   const addOrEdit = (mode: 'add' | 'edit', initialValues?: API.ExecutorItem) => {
+    console.log(initialValues)
+
     const text = mode === 'add' ? '新增执行者' : '编辑执行者'
     modal.open({
       title: text,
@@ -97,12 +99,12 @@ export default function useScripts(modal: ModalAction, business: BusinessType) {
         } else {
           requestFn = updateExecutor
         }
-        const { code = -1 } = await requestFn?.(values)
-        if (code === consts.RET_CODE.SUCCESS) {
+        try {
+          await requestFn?.(values)
           refresh()
           modal.close()
           message.success(text + '成功')
-        }
+        } catch (error) {}
       }
     })
   }
@@ -114,12 +116,14 @@ export default function useScripts(modal: ModalAction, business: BusinessType) {
       cancelText: '取消',
       children: <div>确定删除该执行者吗?</div>,
       onOk: async () => {
-        const { code = -1 } = await delExecutor({ ID })
-        if (code === consts.RET_CODE.SUCCESS) {
-          refresh()
-          modal.close()
-          message.success('删除成功')
-        }
+        try {
+          const { code = -1 } = await delExecutor({ ID })
+          if (code === consts.RET_CODE.SUCCESS) {
+            refresh()
+            modal.close()
+            message.success('删除成功')
+          }
+        } catch (error) {}
       }
     })
   }

+ 16 - 6
src/pages/Business/RuleCode/components/LeftMenu/index.tsx

@@ -10,20 +10,30 @@ type LeftMenuProps = {
 }
 
 const itemsChild = [
-  { label: '预算审核', key: 'yuS' },
-  { label: '结算审核', key: 'jieS' },
-  { label: '决算审核', key: 'jueS' }
+  { label: '预算审核', key: '_yuS' },
+  { label: '结算审核', key: '_jieS' },
+  { label: '决算审核', key: '_jueS' }
 ]
 
-const LeftMenu: React.FC<LeftMenuProps> = ({ title = '业务主体列表', options, onChange, value }) => {
+const LeftMenu: React.FC<LeftMenuProps> = ({ title = '业务主体列表', options, onChange, value, initFn }) => {
+  const handleOnSelect = ({ key }) => {
+    console.log(key)
+    onChange(key, initFn({ tab: key.split('_')[1], subjectID: key[0] }))
+  }
+
   return (
     <div className="w-216px rounded-20px" style={{ height: 'calc(100vh - 122px)', background: '#ffffff' }}>
       <div className="p-5 text-16px text-opacity-85 menu-title">{title}</div>
       <Menu
+        style={{ height: 'calc(100vh - 200px)' }}
         defaultSelectedKeys={[value]}
-        onSelect={({ key }) => onChange(key)}
+        onSelect={handleOnSelect}
         mode="inline"
-        items={options.map(item => ({ label: item.name, key: item.ID, type: 'group', children: itemsChild }))}
+        items={options.map(item => ({
+          label: item.name,
+          key: item.ID,
+          children: itemsChild.map(data => ({ label: data.label, key: item.ID + data.key }))
+        }))}
       />
     </div>
   )

+ 18 - 11
src/pages/Business/RuleCode/index.tsx

@@ -9,7 +9,6 @@ import LeftMenu from './components/LeftMenu'
 import { querySubject } from '@/services/api/subject'
 
 const { TabPane } = Tabs
-const contentHeight = document.body.clientHeight - 122
 
 const connectorOption = [
   { label: '无', value: '' },
@@ -88,13 +87,14 @@ const RulesCode = () => {
   const [state, setState] = useState({
     ruleTypeValue: RuleOptionEunm.APPROVALTYPE,
     tabId: 'yuS',
+    subjectList: '',
+    activeKey: '',
+    subjectID: '',
     connector: '-',
     approvalTypeValue: '01',
     digits: '5',
     autoCode: '00001',
-    fixedText: '',
-    subjectList: '',
-    subjectID: ''
+    fixedText: ''
   })
   console.log(state.subjectID)
 
@@ -127,7 +127,7 @@ const RulesCode = () => {
   }
 
   const { run: tryRuleCode } = useRequest(
-    () => queryRuleCodeList({ tab: state.tabId, subjectID: state.subjectID }),
+    () => queryRuleCodeList({ tab: state.tabId, subjectID: state.activeKey.split('_')[0] }),
     {
       manual: true,
       onSuccess: result => {
@@ -187,12 +187,13 @@ const RulesCode = () => {
   }
 
   const renderExtraTabContent = () =>
-    state.subjectID ? (
+    state.activeKey ? (
       <Button
         type="primary"
         onClick={() => {
           tryUpdateRuleCode({
             tab: state.tabId,
+            subjectID: state.subjectID,
             rules: ruleArr.map(item => ({
               type: item.type,
               value: item.value,
@@ -212,8 +213,16 @@ const RulesCode = () => {
           <LeftMenu
             title="业务主体列表"
             options={state.subjectList}
-            value={state.subjectID}
-            onChange={key => setState({ ...state, subjectID: key })}
+            value={state.activeKey}
+            initFn={() => tryRuleCode()}
+            onChange={key =>
+              setState({
+                ...state,
+                activeKey: key,
+                tabId: key.split('_')[1],
+                subjectID: key.split('_')[0]
+              })
+            }
           />
         ) : null}
 
@@ -228,7 +237,7 @@ const RulesCode = () => {
               })
             }}>
             <TabPane key="yuS" tab="预算编号规则">
-              {state.subjectID ? (
+              {state.activeKey ? (
                 <>
                   <div className="flex items-center mb-3">
                     <div className="w-100px text-right mr-1">编号预览:</div>
@@ -346,8 +355,6 @@ const RulesCode = () => {
           </Tabs>
         </div>
       </div>
-
-      <div className="p-4 bg-white" style={{ height: `${contentHeight}px` }} />
     </PageContainer>
   )
 }

+ 1 - 1
src/services/api/business.ts

@@ -57,7 +57,7 @@ export async function moveTemplate(params: { ID: string; moveID: string }) {
 }
 
 /** 编号规则生成器查询详情 */
-export async function queryRuleCodeList(params: { tab: string }) {
+export async function queryRuleCodeList(params: { tab: string; subjectID: string }) {
   return request('/RuleCode/list', {
     method: 'GET',
     params

+ 5 - 0
src/services/api/typings.d.ts

@@ -418,6 +418,11 @@ declare namespace API {
     rules: any[]
   }
 
+  type RuleCodeParams = {
+    tab: string
+    subjectID: string
+  }
+
   type ExecutorItem = {
     ID?: string
     name?: string