Explorar o código

修改客户自动刷新

outaozhen %!s(int64=5) %!d(string=hai) anos
pai
achega
7007422c1a
Modificáronse 2 ficheiros con 33 adicións e 22 borrados
  1. 31 21
      src/components/PopContent/Companys/index.jsx
  2. 2 1
      src/models/refresh.js

+ 31 - 21
src/components/PopContent/Companys/index.jsx

@@ -7,16 +7,17 @@ import { apiCompanyDetail } from '@/services/company'
 import CompanyForm from '@/components/PopContent/Companys/CompanyForm'
 import CompanyLowerList from '@/components/PopContent/Companys/CompanyLowerList'
 import CompanyTabList from '@/components/PopContent/Companys/CompanyTabList'
+import { connect } from 'dva'
 
 const index = props => {
-  const { visible, onClose,collapsed, id = '' } = props
+  const { dispatch, shouldUpdate, visible, onClose, collapsed, id = '' } = props
   const needSubtractHeight = 55 // 需要被裁掉的高度
   // const needSubtractWidth = (collapsed ? 208 : 48) + 48 + 48 + 48 // 需要被裁掉的高度
-  const [x,y] = useAutoTable(collapsed, needSubtractHeight)
+  const [x, y] = useAutoTable(collapsed, needSubtractHeight)
   const [clientWidth, setClientWidth] = useState(document.body.clientWidth * 0.75)
   const [state, setState] = useState({
     customer: {},
-    log:[]
+    log: []
   })
   const initData = async () => {
     const {
@@ -24,11 +25,17 @@ const index = props => {
       code = -1
     } = await apiCompanyDetail(id)
     if (code === consts.RET_CODE.SUCCESS) {
+      if (shouldUpdate) {
+        dispatch({
+          type: 'refresh/commitAction',
+          payload: 'company'
+        })
+      }
       setState({ ...state, customer, log })
     }
   }
   useEffect(() => {
-    if (visible) {
+    if (visible || shouldUpdate) {
       initData()
     }
     window.addEventListener('resize', () => {
@@ -37,27 +44,27 @@ const index = props => {
     return () => {
       window.removeEventListener('resize', () => {})
     }
-  }, [visible])
+  }, [visible, shouldUpdate])
   return (
     <div>
-      <div className='sheet-box'>
+      <div className="sheet-box">
         <Drawer
-            title="公司"
-            placement="right"
-            bodyStyle={{
-              height:y,
-              overflowY:'hidden'
-            }}
-            width={clientWidth}
-            closable
-            onClose={onClose}
-            visible={visible}
-            // mask={false}
-          >
+          title="公司"
+          placement="right"
+          bodyStyle={{
+            height: y,
+            overflowY: 'hidden'
+          }}
+          width={clientWidth}
+          closable
+          onClose={onClose}
+          visible={visible}
+          // mask={false}
+        >
           <Row>
-            <Col span={12} className="sheet-box-left" style={{ height:y-25,overflowY:'auto' }}>
+            <Col span={12} className="sheet-box-left" style={{ height: y - 25, overflowY: 'auto' }}>
               <div className="sheet-left-panel zh-pd-right-15">
-                <CompanyForm customer={state.customer}/>
+                <CompanyForm customer={state.customer} />
               </div>
             </Col>
             <Col span={12}>
@@ -71,4 +78,7 @@ const index = props => {
   )
 }
 
-export default index
+// export default index
+export default connect(({ refresh }) => ({
+  shouldUpdate: refresh.company
+}))(index)

+ 2 - 1
src/models/refresh.js

@@ -1,7 +1,8 @@
 export default {
   namespace: 'refresh',
   state: {
-    contact: false
+    contact: false,
+    company: false
   },
   // 用于处理异步操作和业务逻辑,由action触发,但不能修改state
   effects: {