Kaynağa Gözat

feat: 完善审批模板单位角色模式逻辑

lanjianrong 2 yıl önce
ebeveyn
işleme
ec9bee41be

+ 20 - 4
src/pages/Project/Verification/Detail/Flow/components/Drawer/ParticipantCard.tsx

@@ -16,7 +16,7 @@ type ParticipantCardProps = {
     institutionID: string | null
     configure: ConfigureType[]
   }
-  institutionList: { label: string; value: string }[]
+  institutionList: { label: string; value: string; member?: { ID: string; name: string }[] }[]
   updateAction: (values: Recordable<string>) => void
 }
 
@@ -116,7 +116,14 @@ const ParticipantCard: React.FC<ParticipantCardProps> = ({
               { label: '单位角色模式', value: ParticipantMode.ROLE }
             ]}
             onChange={value => {
-              updateAction({ ...defaultData, participantMode: value })
+              // 切换了模式,数据清空
+              updateAction({
+                ...defaultData,
+                participantMode: value,
+                institutionID: null,
+                ID: null,
+                name: null
+              })
             }}
           />
         </div>
@@ -124,10 +131,19 @@ const ParticipantCard: React.FC<ParticipantCardProps> = ({
           <Select
             className="w-full"
             value={defaultData.institutionID}
-            options={institutionList}
-            onChange={async value => {
+            options={
+              defaultData.participantMode === ParticipantMode.ACCOUNT
+                ? institutionList
+                : institutionList.filter(item => item.member?.length)
+            }
+            onChange={async (value, option) => {
               if (value && defaultData.participantMode === ParticipantMode.ACCOUNT) {
                 await tryUpdateStaffList(value)
+              } else {
+                const staff: undefined | { ID: string; name: string } = option.member?.[0]
+                staff &&
+                  updateAction({ ...defaultData, institutionID: value, ID: staff.ID, name: staff.name })
+                return
               }
               updateAction({ ...defaultData, institutionID: value, ID: null, name: null })
             }}

+ 7 - 1
src/pages/Project/Verification/Detail/Flow/components/Drawer/index.tsx

@@ -38,7 +38,11 @@ const FlowDrawer = () => {
     onSuccess(result) {
       setState({
         ...state,
-        institutionList: result.items.map(item => ({ label: item.name, value: item.ID }))
+        institutionList: result.items.map(item => ({
+          label: item.name,
+          value: item.ID,
+          member: item.approvalMember
+        }))
       })
     }
   })
@@ -75,6 +79,8 @@ const FlowDrawer = () => {
   const handleOnOk = async () => {
     setState({ ...state, loading: true })
     const { approvalWay, accounts } = state
+    console.log(state)
+
     if (!accounts.every(item => item.institutionID && item.ID)) {
       setState({
         ...state,