Просмотр исходного кода

feat: 调整商机漏斗图表数据刷新逻辑

lanjianrong 4 лет назад
Родитель
Сommit
9236c73490

+ 3 - 0
src/pages/Customer/Business/components/BusinessDetail/Step/index.jsx

@@ -16,6 +16,9 @@ const Step = ({ id, statusId, groupStatus = [], isOwner }) => {
         type: 'refresh/commitAction',
         payload: 'business'
       })
+      dispatch({
+        type: 'business/toggleRefreshGroupStatus'
+      })
     }
   })
 

+ 15 - 6
src/pages/Customer/Business/index.jsx

@@ -13,7 +13,7 @@ import { getAuthCache, getPermAuthCache, setAuthCache } from '@/utils/auth'
 import { PermDataTypeEunm } from '@/pages/Customer/Company/components/PermSelect'
 import { BUSINESS_GROUP_KEY } from '@/utils/cache/cacheEnum'
 
-const Business = ({ dispatch, groupList, shouldUpdate, loading }) => {
+const Business = ({ dispatch, groupList, shouldUpdate, loading, refreshGroupList }) => {
   const [defaultPermAuthCache, defaultStaffIds] = getPermAuthCache(PermDataTypeEunm.CUSTOMER)
   const tRef = useRef(null)
   const { toggleDrawer, setDrawerProps } = useModal()
@@ -29,7 +29,7 @@ const Business = ({ dispatch, groupList, shouldUpdate, loading }) => {
   })
 
   const funnelData = useMemo(() => {
-    if (!groupList) return null
+    if (!groupList?.length) return null
     return groupList
       .find(item => item.value === state.params.businessGroupId)
       ?.items?.filter(item => !item.endProcess)
@@ -57,7 +57,13 @@ const Business = ({ dispatch, groupList, shouldUpdate, loading }) => {
     if (!groupList) {
       initGroupList(state.groupParams)
     }
-  }, [])
+    if (refreshGroupList) {
+      initGroupList()
+      dispatch({
+        type: 'business/toggleRefreshGroupStatus'
+      })
+    }
+  }, [refreshGroupList])
   useEffect(() => {
     if (shouldUpdate) {
       tRef.current.reload()
@@ -166,7 +172,7 @@ const Business = ({ dispatch, groupList, shouldUpdate, loading }) => {
         <div className="p-4 border-b-1 border-solid border-black border-opacity-10 bg-[#f7f9fa] flex justify-around items-center">
           <div className="w-1/2 text-md">商机漏斗</div>
           <div className="w-1/2">
-            {groupList && (
+            {groupList?.length ? (
               <Select
                 placeholder="请选择商机组"
                 size="small"
@@ -176,11 +182,13 @@ const Business = ({ dispatch, groupList, shouldUpdate, loading }) => {
                 defaultValue={defaultGroupId}
                 onChange={handleBussinessChange}
               />
-            )}
+            ) : null}
           </div>
         </div>
         <div className="p-4 bg-white " style={{ height: 'calc(100% - 1rem*2 - 20px)' }}>
-          <div className="max-h-1/3">{funnelData && <Funnel data={funnelData} {...conifg} />}</div>
+          <div className="max-h-1/3">
+            {funnelData?.length ? <Funnel data={funnelData} {...conifg} /> : null}
+          </div>
         </div>
       </div>
       <div className="w-17/20">
@@ -245,6 +253,7 @@ const Business = ({ dispatch, groupList, shouldUpdate, loading }) => {
 
 export default connect(({ business, refresh, loading }) => ({
   groupList: business.groupList,
+  refreshGroupList: business.refreshGroupList,
   loading: loading.models.business,
   shouldUpdate: refresh.business
 }))(Business)

+ 13 - 1
src/pages/Customer/Business/model.js

@@ -4,7 +4,8 @@ import { getBusinessGroupList } from '@/services/customer'
 export default {
   namespace: 'business',
   state: {
-    groupList: null
+    groupList: null,
+    refreshGroupList: false
   },
   effects: {
     *fetchGroup({ payload }, { call, put }) {
@@ -23,6 +24,11 @@ export default {
           }
         })
       }
+    },
+    *toggleRefreshGroupStatus(_, { put }) {
+      yield put({
+        type: 'changeGroupStatus'
+      })
     }
   },
   reducers: {
@@ -32,6 +38,12 @@ export default {
         ...state,
         [action.payload.key]: action.payload.data
       }
+    },
+    changeGroupStatus(state) {
+      return {
+        ...state,
+        refreshGroupList: !state.refreshGroupList
+      }
     }
   }
 }