Bläddra i källkod

feat: 从项目节点击到合同的数据刷新问题

lanjianrong 4 år sedan
förälder
incheckning
c1c135f557

+ 18 - 16
src/pages/Contract/Content/Income/components/Tabs/File/index.tsx

@@ -16,34 +16,36 @@ interface iFileState {
   createTime: string
 }
 
+interface FiltTable {
+  data: iFileState[]
+  total: number
+  pageNo: number
+  pageSize: number
+}
+
 const File: React.FC<{ type: 'income' | 'expenditure' }> = ({ type }) => {
-  const [ data, setData ] = useState<Array<iFileState>>([])
-  const [ total, setTotal ] = useState<number>(0)
+  const [ state, setState ] = useState<FiltTable>({ data: [], total: 0, pageNo: 1, pageSize: 7 })
   const [ id, setId ] = useState<string>('')
-  const [ pagination, setPagination ] = useState({
-    pageNo: 1,
-    pageSize: 7
-  })
+
   useEffect(() => {
     if (contractStore.contract.id) {
       if (contractStore.contract.id !== id) {
         setId(contractStore.contract.id)
         initData()
       } else if (contractStore.activeKey && contractStore.activeKey === '3') {
-        initData(pagination.pageNo, pagination.pageSize)
+        initData(state.pageNo, state.pageSize)
       }
     } else {
-      setData([])
-      setTotal(0)
+      setState({ ...state, data: [], total: 0 })
+      setId('')
     }
   }, [ contractStore.contract.id, contractStore.activeKey ])
 
   const initData = async (pageNo: number = 1, pageSize: number = 7) => {
-    setPagination({ ...pagination, pageNo, pageSize })
+    setState({ ...state, pageNo, pageSize })
     const { code = -1, data = [], total = 0 } = await apiGetFileList(type === ContractType.INCOME ? consts.DATA_TYPE.INCOME : consts.DATA_TYPE.EXPENDITURE, contractStore.contract.id, pageNo, pageSize)
     if (code === consts.RET_CODE.SUCCESS) {
-      setData(data)
-      setTotal(total)
+      setState({ ...state, data, total })
       contractStore.activeKey && (contractStore.changeActiveKey(''))
     }
   }
@@ -51,8 +53,8 @@ const File: React.FC<{ type: 'income' | 'expenditure' }> = ({ type }) => {
   const deleteFile = async (id: string) => {
     const { code = -1 } = await apiDelFile(id)
     if (code === consts.RET_CODE.SUCCESS) {
-      const newData = data.filter((file: iFileState) => file.id !== id)
-      setData(newData)
+      const newData = state.data.filter((file: iFileState) => file.id !== id)
+      setState({ ...state, data: newData })
     }
   }
   const columns: ColumnsType<iFileState> = [
@@ -98,7 +100,7 @@ const File: React.FC<{ type: 'income' | 'expenditure' }> = ({ type }) => {
   ]
   return (
     <Table
-      dataSource={data}
+      dataSource={state.data}
       columns={columns}
       bordered
       rowKey={record => record.id}
@@ -107,7 +109,7 @@ const File: React.FC<{ type: 'income' | 'expenditure' }> = ({ type }) => {
         size: "small",
         pageSize: 7,
         onChange: (page, pageSize) => initData(page, pageSize),
-        total
+        total: state.total
       }}
     />
   )

+ 2 - 2
src/pages/Contract/Content/Income/components/Tabs/Receivable/index.tsx

@@ -85,7 +85,6 @@ const Receivable: React.FC<ReceivableProps> = ({ updateTreeAndContract, type })
   }
 
   useEffect(() => {
-    console.log(contractStore.activeKey)
 
     !commonStore.returnWayOptions.length && (commonStore.queryWayOptions())
     if (contractStore.contract.id) {
@@ -93,14 +92,15 @@ const Receivable: React.FC<ReceivableProps> = ({ updateTreeAndContract, type })
         setId(contractStore.contract.id)
         initData()
       } else if (contractStore.activeKey && contractStore.activeKey === '2') {
-        console.log('进来了')
 
         initData()
       }
     } else {
+      setId('')
       // 项目节的点击,数据为空数组
       setData([])
     }
+
   }, [ contractStore.activeKey, contractStore.contract.id ])
 
   const initData = async () => {