Commit cbb31cedd725f7dbf9860f231947d510f15d4729

Authored by boyang
1 parent 58558396

fix: 修改隐私页面bug

src/pages/Prepaid/PrivatePocket/components/AddPrivatePocketModal.tsx
1 import { 1 import {
  2 + postCanrdApiUserList,
2 postCanrdPrivatePocketSave, 3 postCanrdPrivatePocketSave,
3 postServiceOrderQuerySalesCode, 4 postServiceOrderQuerySalesCode,
4 } from '@/services'; 5 } from '@/services';
5 import { getUserInfo } from '@/utils/user'; 6 import { getUserInfo } from '@/utils/user';
6 -import { Form, Input, Modal, Select, message } from 'antd'; 7 +import { Form, Modal, Select, message } from 'antd';
7 import React, { useEffect, useState } from 'react'; 8 import React, { useEffect, useState } from 'react';
8 9
9 interface AddPrivatePocketModalProps { 10 interface AddPrivatePocketModalProps {
@@ -17,6 +18,15 @@ interface SalesCodeItem { @@ -17,6 +18,15 @@ interface SalesCodeItem {
17 userName: string; 18 userName: string;
18 } 19 }
19 20
  21 +interface UserItem {
  22 + uid: string;
  23 + realName: string;
  24 + institution?: string;
  25 + nowMoney?: string | number;
  26 + phone: string;
  27 + [key: string]: any;
  28 +}
  29 +
20 const AddPrivatePocketModal: React.FC<AddPrivatePocketModalProps> = ({ 30 const AddPrivatePocketModal: React.FC<AddPrivatePocketModalProps> = ({
21 visible, 31 visible,
22 onCancel, 32 onCancel,
@@ -25,6 +35,8 @@ const AddPrivatePocketModal: React.FC&lt;AddPrivatePocketModalProps&gt; = ({ @@ -25,6 +35,8 @@ const AddPrivatePocketModal: React.FC&lt;AddPrivatePocketModalProps&gt; = ({
25 const [form] = Form.useForm(); 35 const [form] = Form.useForm();
26 const [salesCodeList, setSalesCodeList] = useState<SalesCodeItem[]>([]); 36 const [salesCodeList, setSalesCodeList] = useState<SalesCodeItem[]>([]);
27 const [loading, setLoading] = useState<boolean>(false); 37 const [loading, setLoading] = useState<boolean>(false);
  38 + const [userList, setUserList] = useState<any[]>([]);
  39 + const [searchKeywords, setSearchKeywords] = useState<string>('');
28 const userInfo = getUserInfo(); 40 const userInfo = getUserInfo();
29 const userName = userInfo?.username || ''; 41 const userName = userInfo?.username || '';
30 42
@@ -40,6 +52,30 @@ const AddPrivatePocketModal: React.FC&lt;AddPrivatePocketModalProps&gt; = ({ @@ -40,6 +52,30 @@ const AddPrivatePocketModal: React.FC&lt;AddPrivatePocketModalProps&gt; = ({
40 } 52 }
41 }; 53 };
42 54
  55 + // Define a function to fetch user list that can be called from multiple places
  56 + const fetchUserList = async (keywords: string) => {
  57 + try {
  58 + const res = await postCanrdApiUserList({
  59 + data: { keywords: keywords, pageSize: 1000000 },
  60 + });
  61 +
  62 + if (res?.data?.data) {
  63 + setUserList(res.data.data);
  64 + }
  65 + return res?.data?.data || [];
  66 + } catch (error) {
  67 + console.error('获取用户列表失败:', error);
  68 + return [];
  69 + }
  70 + };
  71 +
  72 + // Initial fetch when component mounts
  73 + useEffect(() => {
  74 + if (visible) {
  75 + fetchUserList('');
  76 + }
  77 + }, [visible]);
  78 +
43 useEffect(() => { 79 useEffect(() => {
44 if (visible) { 80 if (visible) {
45 fetchSalesCodeList(); 81 fetchSalesCodeList();
@@ -86,9 +122,75 @@ const AddPrivatePocketModal: React.FC&lt;AddPrivatePocketModalProps&gt; = ({ @@ -86,9 +122,75 @@ const AddPrivatePocketModal: React.FC&lt;AddPrivatePocketModalProps&gt; = ({
86 <Form.Item 122 <Form.Item
87 name="account" 123 name="account"
88 label="绑定普通账户" 124 label="绑定普通账户"
89 - rules={[{ required: true, message: '请输入手机号' }]} 125 + rules={[{ required: true, message: '请选择账户' }]}
90 > 126 >
91 - <Input placeholder="请输入手机号" /> 127 + <Select
  128 + showSearch
  129 + placeholder="请选择账户"
  130 + optionFilterProp="children"
  131 + defaultActiveFirstOption={false}
  132 + notFoundContent={null}
  133 + filterOption={false} // Disable built-in filtering to use server-side search
  134 + onSearch={async (value) => {
  135 + setSearchKeywords(value);
  136 + // Immediately fetch results when searching
  137 + await fetchUserList(value);
  138 + }}
  139 + onChange={(value) => {
  140 + // When a value is selected, find the corresponding phone from userList
  141 + // or use the value directly if it's a custom entry
  142 +
  143 + // Check if this is a custom entry (value is the same as searchKeywords)
  144 + if (value === searchKeywords && searchKeywords.trim() !== '') {
  145 + form.setFieldsValue({ account: searchKeywords });
  146 + return;
  147 + }
  148 +
  149 + // Find the selected user from userList to get their phone
  150 + const selectedUser = userList.find((user) => user.uid === value);
  151 + if (selectedUser && selectedUser.phone) {
  152 + form.setFieldsValue({ account: selectedUser.phone });
  153 + }
  154 + }}
  155 + dropdownRender={(menu) => (
  156 + <div>
  157 + {menu}
  158 + {searchKeywords.trim() !== '' && (
  159 + <div
  160 + style={{
  161 + padding: '8px',
  162 + cursor: 'pointer',
  163 + borderTop: '1px solid #e8e8e8',
  164 + }}
  165 + onClick={() => {
  166 + form.setFieldsValue({ account: searchKeywords });
  167 + }}
  168 + >
  169 + <span style={{ color: '#333333' }}>{searchKeywords}</span>
  170 + {' | '}
  171 + <span style={{ color: 'orange' }}>自定义</span>
  172 + </div>
  173 + )}
  174 + </div>
  175 + )}
  176 + >
  177 + {userList.map((user: UserItem) => {
  178 + const displayText = `${user.realName || '-'} | ${
  179 + user.institution || '-'
  180 + } | ${user.nowMoney || '0'}¥ | ${user.phone || '-'}`;
  181 + return (
  182 + <Select.Option
  183 + key={user.uid}
  184 + value={user.uid}
  185 + title={displayText}
  186 + >
  187 + <div>
  188 + <span>{displayText}</span>
  189 + </div>
  190 + </Select.Option>
  191 + );
  192 + })}
  193 + </Select>
92 </Form.Item> 194 </Form.Item>
93 <Form.Item 195 <Form.Item
94 name="salesCode" 196 name="salesCode"
src/pages/Prepaid/PrivatePocket/constant.tsx
@@ -8,7 +8,7 @@ export const PRIVATE_POCKET_COLUMNS = [ @@ -8,7 +8,7 @@ export const PRIVATE_POCKET_COLUMNS = [
8 hideInSearch: true, 8 hideInSearch: true,
9 }, 9 },
10 { 10 {
11 - title: '用户账号', 11 + title: '普通账户',
12 dataIndex: 'account', 12 dataIndex: 'account',
13 key: 'account', 13 key: 'account',
14 valueType: 'text', 14 valueType: 'text',
@@ -17,21 +17,21 @@ export const PRIVATE_POCKET_COLUMNS = [ @@ -17,21 +17,21 @@ export const PRIVATE_POCKET_COLUMNS = [
17 }, 17 },
18 }, 18 },
19 { 19 {
20 - title: '真实姓名', 20 + title: '老师姓名',
21 dataIndex: 'realName', 21 dataIndex: 'realName',
22 key: 'realName', 22 key: 'realName',
23 valueType: 'text', 23 valueType: 'text',
24 hideInSearch: true, 24 hideInSearch: true,
25 }, 25 },
26 { 26 {
27 - title: '户余额', 27 + title: '普通账户余额',
28 dataIndex: 'nowMoney', 28 dataIndex: 'nowMoney',
29 key: 'nowMoney', 29 key: 'nowMoney',
30 valueType: 'money', 30 valueType: 'money',
31 hideInSearch: true, 31 hideInSearch: true,
32 }, 32 },
33 { 33 {
34 - title: '隐私余额', 34 + title: '隐私钱包余额',
35 dataIndex: 'privateMoney', 35 dataIndex: 'privateMoney',
36 key: 'privateMoney', 36 key: 'privateMoney',
37 valueType: 'money', 37 valueType: 'money',
@@ -47,19 +47,19 @@ export const PRIVATE_POCKET_COLUMNS = [ @@ -47,19 +47,19 @@ export const PRIVATE_POCKET_COLUMNS = [
47 }, 47 },
48 }, 48 },
49 { 49 {
50 - title: '创建人',  
51 - dataIndex: 'createByName',  
52 - key: 'createByName',  
53 - valueType: 'text',  
54 - hideInSearch: true,  
55 - },  
56 - {  
57 title: '创建时间', 50 title: '创建时间',
58 dataIndex: 'createTime', 51 dataIndex: 'createTime',
59 key: 'createTime', 52 key: 'createTime',
60 valueType: 'dateTime', 53 valueType: 'dateTime',
61 hideInSearch: true, 54 hideInSearch: true,
62 }, 55 },
  56 + {
  57 + title: '创建人',
  58 + dataIndex: 'createByName',
  59 + key: 'createByName',
  60 + valueType: 'text',
  61 + hideInSearch: true,
  62 + },
63 // { 63 // {
64 // title: '更新时间', 64 // title: '更新时间',
65 // dataIndex: 'updateTime', 65 // dataIndex: 'updateTime',