Procházet zdrojové kódy

fix: 锁库更换锁列表滚动bug

lanjianrong před 5 roky
rodič
revize
bf1fe486b8

+ 22 - 19
src/pages/Product/Lock/Lockstore/components/LocksDetail/LockModal.jsx

@@ -43,9 +43,9 @@ const LockModal = props => {
     longle: [],
     client: [],
     searchVal: '',
-    radioVal: 3,
-    page: 1,
-    size: 10,
+    status: 3,
+    current: 1,
+    pageSize: 10,
     total: 0
   })
   // 获取软件锁产品列表
@@ -61,7 +61,7 @@ const LockModal = props => {
         params
       )
       if (code === consts.RET_CODE.SUCCESS) {
-        if (params?.page === 1) {
+        if (params?.current === 1) {
           // 请求的是第一页
           setState({ ...state, longle, total, laoding: false })
         } else {
@@ -74,14 +74,15 @@ const LockModal = props => {
         params
       )
       if (code === consts.RET_CODE.SUCCESS) {
-        if (params?.page === 1) {
+        if (params?.current === 1) {
+          scrollRef.current?.scrollTo({ top: 0 })
           // 请求的是第一页
           setState({
             ...state,
             client,
             total,
             laoding: false,
-            radioVal: params.status || lockTypeEnum.SALE
+            ...params
           })
         } else {
           setState({
@@ -89,28 +90,30 @@ const LockModal = props => {
             client: state.client.concat(client),
             total,
             laoding: true,
-            radioVal: params.status
+            ...params
           })
         }
       }
     }
   }
-  useEffect(() => {
-    if (type === lockTypeEnum.CHANGE || type === lockTypeEnum.SALE) {
-      initData({ page: 1, size: 10 })
-    }
-  }, [type])
   const onChange = e => {
     const { value = '' } = e.target || e.currentTarget
     if (type === lockTypeEnum.CHANGE || type === lockTypeEnum.SALE) {
-      initData({ search: value, page: state.page, size: state.size })
+      initData({ search: value, current: 1, pageSize: state.pageSize })
     }
   }
 
   const { run: handleInputChange } = useDebounceFn(onChange)
   useEffect(() => {
     if (visible) {
-      setState({ ...state, searchVal: '' })
+      if (type === lockTypeEnum.CHANGE) {
+        initData({ current: 1, pageSize: 10 })
+        return
+      }
+      if (type === lockTypeEnum.SALE) {
+        initData({ current: 1, pageSize: 10, status: state.status })
+        return
+      }
       form.resetFields()
       if (type === lockTypeEnum.RECOVER) {
         form.setFieldsValue({ longleId, status })
@@ -125,15 +128,15 @@ const LockModal = props => {
   }
 
   const checkGroupOnChange = e => {
-    const { value = '' } = e.target
-    initData({ status: value, page: 1, size: 10 })
+    const { value = '' } = e.target || {}
+    initData({ status: value, current: 1, pageSize: 10 })
   }
 
   // 关联联系人
   const connectClient = async id => {
     const { code = -1 } = await apiSoftwareAddLonglelog({
       clientId: id,
-      status: state.radioVal,
+      status: state.status,
       longleId
     })
     if (code === consts.RET_CODE.SUCCESS) {
@@ -168,7 +171,7 @@ const LockModal = props => {
       scrollRef.current.scrollTop
     ) {
       // 已到底部
-      initData({ page: state.page + 1, size: state.size })
+      initData({ current: state.current + 1, pageSize: state.pageSize, status: state.status })
     }
   }
 
@@ -214,7 +217,7 @@ const LockModal = props => {
       {type === lockTypeEnum.SALE ? (
         <>
           <div className="text-center mb-6">
-            <Radio.Group value={state.radioVal} buttonStyle="solid" onChange={checkGroupOnChange}>
+            <Radio.Group value={state.status} buttonStyle="solid" onChange={checkGroupOnChange}>
               <Radio.Button value={3}>借出</Radio.Button>
               <Radio.Button value={4}>销售</Radio.Button>
               <Radio.Button value={9}>赠送</Radio.Button>