Browse Source

fix:代理商列表分页bug

lvkun 3 years ago
parent
commit
410f9fe6ff
2 changed files with 22 additions and 6 deletions
  1. 5 3
      src/pages/agent/list/detail.tsx
  2. 17 3
      src/pages/agent/list/index.tsx

+ 5 - 3
src/pages/agent/list/detail.tsx

@@ -40,7 +40,7 @@ type userInfoType = {
   phoneNumber: string;
   followBarNum: number | null;
   followBars: followBarsType[];
-  tags: string[];
+  tags: string[] | null;
   [key: string]: any;
 };
 
@@ -123,7 +123,7 @@ const DetailModal: React.FC<DetailModalType> = ({ visible, id, closeModal }) =>
   const clearTags = (e: React.MouseEvent<HTMLElement, MouseEvent> | undefined, _tag: string) => {
     e && e.preventDefault();
 
-    const tags = userInfo.tags;
+    const tags = userInfo.tags == null ? [] : userInfo.tags;
 
     const residueTags = tags.filter((tag) => tag !== _tag && tag !== newTagName);
 
@@ -132,7 +132,9 @@ const DetailModal: React.FC<DetailModalType> = ({ visible, id, closeModal }) =>
 
   // 添加标签
   const addTags = () => {
-    const residueTags = userInfo.tags.filter((_tag) => _tag !== newTagName);
+    const tags = userInfo.tags == null ? [] : userInfo.tags;
+
+    const residueTags = tags.filter((_tag) => _tag !== newTagName);
 
     residueTags.push(tagName);
 

+ 17 - 3
src/pages/agent/list/index.tsx

@@ -51,7 +51,10 @@ const reducer: React.Reducer<initStateType, Action> = (State, action): initState
 
   switch (type) {
     case 'page':
+      console.log(2233);
+
       return { ...State, curPage: value };
+
     case 'state':
       return { ...State, state: value };
     case 'label':
@@ -116,12 +119,16 @@ const Agent: React.FC = () => {
   };
 
   useEffect(() => {
-    GetAgent();
     GetRoleList();
   }, []);
 
+  useEffect(() => {
+    GetAgent();
+  }, [state.curPage]);
+
   // 重置搜索条件
   const reloadSate = (): void => dispatch({ type: 'reload', value: '' });
+
   // 打开弹窗
   const openModal = (value: Record<string, any>): void => {
     setVisible(true);
@@ -142,7 +149,7 @@ const Agent: React.FC = () => {
   const changeRole = (value: string): void => dispatch({ type: 'roleId', value });
 
   // 分页
-  const pagination = (changePage: number): void => dispatch({ type: 'page', value: changePage });
+  const pagination = async (changePage: number) => dispatch({ type: 'page', value: changePage });
 
   return (
     <PageContainer title="代理商列表">
@@ -196,7 +203,14 @@ const Agent: React.FC = () => {
           dataSource={agentList}
           style={{ marginTop: '20px' }}
         >
-          <Table.Column<User> title="姓名" dataIndex="nickName" key="nickName" />
+          <Table.Column<User>
+            title="姓名"
+            dataIndex="nickName"
+            key="nickName"
+            render={(text, records) => (
+              <span>{records.nickName ? records.nickName : '微信用户'}</span>
+            )}
+          />
           <Table.Column<User> title="手机号" dataIndex="phoneNumber" key="phoneNumber" />
           <Table.Column<User>
             title="地区"