From 0b958cf528b44e1d6c0558d5551e05ebbec274c4 Mon Sep 17 00:00:00 2001
From: wjh <wwwjh0710@163.com>
Date: Mon, 8 Jul 2024 16:55:46 +0800
Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=89=8B=E6=9C=BA?=
 =?UTF-8?q?=E7=AB=AF=E5=AE=A1=E6=89=B9=E6=97=A0=E6=B3=95=E9=80=9A=E8=BF=87?=
 =?UTF-8?q?=E5=92=8C=E7=8A=B6=E6=80=81=E6=B2=A1=E6=9C=89=E6=98=BE=E7=A4=BA?=
 =?UTF-8?q?=20(#1287)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Reviewed-on: https://git.daoyoucloud.com/daoyoucloud/tachybase/pulls/1287
Reviewed-by: sealday <zhanglin@daoyoucloud.com>
Co-authored-by: wjh <wwwjh0710@163.com>
Co-committed-by: wjh <wwwjh0710@163.com>
---
 .../client/approval/todos/hook/useSubmit.tsx  | 21 ++++++++++++++++---
 .../components/antd-mobile/Select/Select.tsx  |  8 ++++++-
 2 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/packages/plugins/@hera/plugin-approval-mobile/src/client/approval/todos/hook/useSubmit.tsx b/packages/plugins/@hera/plugin-approval-mobile/src/client/approval/todos/hook/useSubmit.tsx
index 943132613..0b8e40b25 100644
--- a/packages/plugins/@hera/plugin-approval-mobile/src/client/approval/todos/hook/useSubmit.tsx
+++ b/packages/plugins/@hera/plugin-approval-mobile/src/client/approval/todos/hook/useSubmit.tsx
@@ -1,4 +1,4 @@
-import { useActionContext, useAPIClient, useTableBlockContext } from '@tachybase/client';
+import { useActionContext, useAPIClient, useCollection, useTableBlockContext } from '@tachybase/client';
 import { useFlowContext } from '@tachybase/plugin-workflow/client';
 import { useField, useFieldSchema, useForm } from '@tachybase/schema';
 
@@ -7,12 +7,14 @@ import { Toast } from 'antd-mobile';
 import { useContextApprovalExecution } from '../../context/ApprovalExecution';
 import { useContextApprovalAction } from '../provider/ApprovalAction';
 
-export function useSubmit() {
+export function useSubmit(props) {
   const field = useField();
   const api = useAPIClient();
   const form = useForm();
   const { id } = useContextApprovalExecution();
   const { status } = useContextApprovalAction();
+  const collection = useCollection();
+  const needUpdateRecord = props?.source === 'updateRecord';
   return {
     run: async () => {
       try {
@@ -22,9 +24,22 @@ export function useSubmit() {
         await form.submit();
         field.data = field.data ?? {};
         field.data.loading = true;
+        if (needUpdateRecord) {
+          const collectionName = collection.name;
+          const targetId = form.values.id;
+
+          await api.resource(collectionName).update({
+            filterByTk: targetId,
+            values: form.values,
+          });
+        }
         const res = await api.resource('approvalRecords').submit({
           filterByTk: id,
-          values: { ...form.values, status },
+          values: {
+            status,
+            needUpdateRecord,
+            data: form.values,
+          },
         });
         field.data.loading = false;
         if (res.status === 202) {
diff --git a/packages/plugins/@tachybase/plugin-mobile-client/src/client/core/schema/components/antd-mobile/Select/Select.tsx b/packages/plugins/@tachybase/plugin-mobile-client/src/client/core/schema/components/antd-mobile/Select/Select.tsx
index d82e57692..654887dc9 100644
--- a/packages/plugins/@tachybase/plugin-mobile-client/src/client/core/schema/components/antd-mobile/Select/Select.tsx
+++ b/packages/plugins/@tachybase/plugin-mobile-client/src/client/core/schema/components/antd-mobile/Select/Select.tsx
@@ -28,7 +28,13 @@ export const MSelect = connect(
     return { ...filterProps };
   }),
   mapReadPretty((props) => {
-    return <AssociationField.ReadPretty {...props} />;
+    const collectionField = useCollectionField();
+    if (typeof props.value === 'object') {
+      return <AssociationField.ReadPretty {...props} />;
+    } else {
+      const option = collectionField?.uiSchema?.enum?.find((item) => item.value === props.value);
+      return <Tag color={getMobileColor(option?.color)}>{option?.label}</Tag>;
+    }
   }),
 );