Ver código fonte

feat: 商机组列表增加数据权限相关params

lanjianrong 4 anos atrás
pai
commit
ba24e78c83
2 arquivos alterados com 77 adições e 59 exclusões
  1. 73 57
      src/pages/Customer/Business/index.jsx
  2. 4 2
      src/services/customer.js

+ 73 - 57
src/pages/Customer/Business/index.jsx

@@ -13,11 +13,13 @@ import { getPermAuthCache } from '@/utils/auth'
 import { PermDataTypeEunm } from '@/pages/Customer/Company/components/PermSelect'
 
 const Business = ({ dispatch, groupList, shouldUpdate, loading }) => {
+  const [defaultPermAuthCache, defaultStaffIds] = getPermAuthCache(PermDataTypeEunm.CUSTOMER)
   const tRef = useRef(null)
   const { toggleDrawer, setDrawerProps } = useModal()
   const [state, setState] = useState({
     orderIds: [],
-    params: { businessGroupId: null, dataPermission: 'oneself', staffIds: null },
+    params: { businessGroupId: null },
+    groupParams: { staffIds: defaultStaffIds, dataPermission: defaultPermAuthCache },
     funnelData: []
   })
   const { initialState: { permData } = { permData: {} } } = useModel('@@initialState')
@@ -25,15 +27,24 @@ const Business = ({ dispatch, groupList, shouldUpdate, loading }) => {
     setState({ ...state, params: { ...state.params, search: value } })
   }
 
+  const initGroupList = (payload = {}) => {
+    dispatch({
+      type: 'business/fetchGroup',
+      payload
+    })
+  }
   useEffect(() => {
     if (!groupList) {
-      dispatch({
-        type: 'business/fetchGroup'
-      })
+      initGroupList(state.groupParams)
     }
     if (groupList) {
       const group = groupList[0]
       if (group) {
+        console.log(
+          group.items
+            ?.filter(item => !item.endProcess)
+            ?.map(item => ({ ...item, percentage: parseInt(item.percentage, 10) }))
+        )
         setState({
           ...state,
           params: { ...state.params, businessGroupId: group.value },
@@ -43,7 +54,7 @@ const Business = ({ dispatch, groupList, shouldUpdate, loading }) => {
         })
       }
     }
-  }, [groupList])
+  }, [groupList, state.groupParams])
   useEffect(() => {
     if (shouldUpdate) {
       tRef.current.reload()
@@ -76,7 +87,8 @@ const Business = ({ dispatch, groupList, shouldUpdate, loading }) => {
       render: (text, record) => (
         <span
           onClick={() => showDrawer(record.id)}
-          className="text-primary cursor-pointer hover:text-[#967bbd]">
+          className="text-primary cursor-pointer hover:text-[#967bbd]"
+        >
           {text}
         </span>
       )
@@ -85,17 +97,15 @@ const Business = ({ dispatch, groupList, shouldUpdate, loading }) => {
       dataIndex: 'customerName',
       title: '单位名称',
       width: '20%',
-      render: (text, record) => {
-        return record.customerId !== consts.ENCRYPTION_ZERO ? (
+      render: (text, record) =>
+        record.customerId && (
           <span
             onClick={() => showDrawer(record.customerId, true)}
-            className="text-primary cursor-pointer hover:text-[#967bbd]">
+            className="text-primary cursor-pointer hover:text-[#967bbd]"
+          >
             {text}
           </span>
-        ) : (
-          '-'
         )
-      }
     },
     {
       dataIndex: 'businessStatusName',
@@ -134,8 +144,8 @@ const Business = ({ dispatch, groupList, shouldUpdate, loading }) => {
     shape: 'pyramid',
     conversionTag: false
   }
-
-  const [defaultPermAuthCache] = getPermAuthCache(PermDataTypeEunm.CUSTOMER)
+  const handleOnPermChange = ({ staffIds, dataPermission }) =>
+    setState({ ...state, groupParams: { ...state.groupParams, staffIds, dataPermission } })
   return (
     <div className="h-full w-full flex flex-row justify-between">
       <div className="h-full w-3/20 rounded-4px shadow-card">
@@ -170,52 +180,58 @@ const Business = ({ dispatch, groupList, shouldUpdate, loading }) => {
       </div>
       <div className="w-17/20">
         <div className="ml-8 bg-white shadow-card">
-          {state.params.businessGroupId ? (
-            <BasicTable
-              actionRef={tRef}
-              mainMenuType="customer"
-              columnStateType="BUSINESS"
-              params={state.params}
-              rowKey={record => record.id}
-              columns={columns}
-              request={async (params, sort, filter) => {
-                const {
-                  code = -1,
-                  data: { business = [], total = 0 }
-                } = await getBusinessList({ ...params, ...sort, ...filter })
-                setState({ ...state, orderIds: business.map(item => item.id) })
+          <BasicTable
+            actionRef={tRef}
+            mainMenuType="customer"
+            columnStateType="BUSINESS"
+            onPermChange={handleOnPermChange}
+            params={state.params}
+            rowKey={record => record.id}
+            columns={columns}
+            request={async (params, sort, filter) => {
+              if (!state.params.businessGroupId) {
                 return {
-                  data: business,
-                  success: code === consts.RET_CODE.SUCCESS,
-                  total
+                  data: [],
+                  success: true,
+                  total: 0
                 }
-              }}
-              search={false}
-              toolbar={{
-                search: (
-                  <Tooltip placement="bottom" title="输入商机名称、单位名称">
-                    <Input.Search
-                      style={{ width: '300px' }}
-                      allowClear={true}
-                      placeholder={`在${
-                        permData[PermDataTypeEunm.CUSTOMER]?.find(
-                          item => item.value === defaultPermAuthCache
-                        )?.label
-                      }下搜索`}
-                      onSearch={handleSearch}
-                    />
-                  </Tooltip>
-                ),
-                actions: [
-                  <AddBusiness
-                    key="add"
-                    groupList={state.groupList}
-                    reload={() => tRef.current?.reload()}
+              }
+              const {
+                code = -1,
+                data: { business = [], total = 0 }
+              } = await getBusinessList({ ...params, ...sort, ...filter })
+              setState({ ...state, orderIds: business.map(item => item.id) })
+              return {
+                data: business,
+                success: code === consts.RET_CODE.SUCCESS,
+                total
+              }
+            }}
+            search={false}
+            toolbar={{
+              search: (
+                <Tooltip placement="bottom" title="输入商机名称、单位名称">
+                  <Input.Search
+                    style={{ width: '300px' }}
+                    allowClear={true}
+                    placeholder={`在${
+                      permData[PermDataTypeEunm.CUSTOMER]?.find(
+                        item => item.value === defaultPermAuthCache
+                      )?.label
+                    }下搜索`}
+                    onSearch={handleSearch}
                   />
-                ]
-              }}
-            />
-          ) : null}
+                </Tooltip>
+              ),
+              actions: [
+                <AddBusiness
+                  key="add"
+                  groupList={state.groupList}
+                  reload={() => tRef.current?.reload()}
+                />
+              ]
+            }}
+          />
         </div>
       </div>
     </div>

+ 4 - 2
src/services/customer.js

@@ -184,8 +184,10 @@ export async function apiAddCustomerService(payload) {
 }
 
 /** 获取商机组列表 */
-export async function getBusinessGroupList() {
-  return request.get('/business/group/list')
+export async function getBusinessGroupList(params) {
+  return request.get('/business/group/list', {
+    params
+  })
 }
 
 /** 获取商机列表 */