Преглед на файлове

feat: 客户来源添加修改

outaozhen преди 3 години
родител
ревизия
169441ff90
променени са 3 файла, в които са добавени 125 реда и са изтрити 37 реда
  1. 99 36
      src/pages/Business/Contact/index.tsx
  2. 17 1
      src/services/user/api.ts
  3. 9 0
      src/services/user/typings.d.ts

+ 99 - 36
src/pages/Business/Contact/index.tsx

@@ -12,7 +12,9 @@ import {
   delBusinessGroupById,
   getBusinessgroupList,
   updateBusinessGroup,
-  getClientSourceList
+  getClientSourceList,
+  addClientSource,
+  updateClientSource
 } from '@/services/user/api'
 import type { ColumnsType } from 'antd/lib/table'
 import { Delete } from '@icon-park/react'
@@ -23,6 +25,11 @@ enum modalType {
   UPDATE = 1
 }
 
+const modalTitleType = {
+  1: '商机角色',
+  2: '来源'
+}
+
 interface StageSettingsType {
   id: React.Key
   name?: string
@@ -178,6 +185,27 @@ const Contact: React.FC = () => {
     }
   })
 
+  const { run: tryAddClientSource } = useRequest(addClientSource, {
+    manual: true,
+    onSuccess: async () => {
+      tryGetClientSourceList()
+      message.success('添加成功')
+    },
+    onError: e => {
+      message.error(e.message)
+    }
+  })
+  const { run: tryUpdateClientSource } = useRequest(updateClientSource, {
+    manual: true,
+    onSuccess: async () => {
+      tryGetClientSourceList()
+      message.success('编辑成功')
+    },
+    onError: e => {
+      message.error(e.message)
+    }
+  })
+
   useEffect(() => {
     if (!department.length) {
       fetchDepartment()
@@ -262,7 +290,19 @@ const Contact: React.FC = () => {
     },
     {
       dataIndex: 'opreate',
-      title: '操作'
+      title: '操作',
+      render: (_, record) => (
+        <div className="divide-x divide-bg-gray-400 flex flex-row">
+          <div
+            className="pr-2 text-primary cursor-pointer hover:text-hex-967bbd"
+            onClick={() => {
+              formRef.current?.setFieldsValue({ ...record })
+              setState({ ...state, visible: true, type: modalType.UPDATE })
+            }}>
+            编辑
+          </div>
+        </div>
+      )
     }
   ]
   return (
@@ -319,57 +359,80 @@ const Contact: React.FC = () => {
         visible={state.visible}
         formRef={formRef}
         onVisibleChange={show => setState({ ...state, visible: show })}
-        title={state.type === modalType.CREATE ? '创建商机角色' : '更新商机角色'}
+        title={`${state.type === modalType.CREATE ? '创建' : '更新'}${
+          modalTitleType[state.menuId]
+        }`}
         onFinish={async value => {
           try {
-            if (state.type === modalType.CREATE) {
+            if (state.type === modalType.CREATE && state.menuId === 1) {
               await tryAddBusinessgroup({
                 ...value,
                 stageSettings: JSON.stringify(value.stageSettings.filter(item => !item.isDefault))
               })
-            } else {
+            }
+            if (state.type === modalType.UPDATE && state.menuId === 1) {
               await tryUpdateBusinessGroup({
                 ...value,
                 stageSettings: JSON.stringify(value.stageSettings.filter(item => !item.isDefault))
               })
             }
+            if (state.type === modalType.CREATE && state.menuId === 2) {
+              await tryAddClientSource({
+                ...value
+              })
+            }
+            if (state.type === modalType.UPDATE && state.menuId === 2) {
+              await tryUpdateClientSource({
+                ...value
+              })
+            }
             return true
           } catch (error) {
             message.error(`${state.type === modalType.CREATE ? '创建' : '更新'}失败,请重试`)
             return false
           }
         }}>
-        <ProFormText name="name" label="组名称" required />
-        <ProFormText name="id" hidden />
-        <ProForm.Item name="departmentIds" label="应用部门" required>
-          <TreeSelect treeData={department} multiple={true} />
-        </ProForm.Item>
-        <ProForm.Item
-          label="状态设置"
-          name="stageSettings"
-          initialValue={defaultData}
-          trigger="onValuesChange">
-          <EditableProTable<StageSettingsType>
-            rowKey="id"
-            toolBarRender={false}
-            columns={columns}
-            recordCreatorProps={{
-              newRecordType: 'dataSource',
-              position: 'bottom',
-              record: () => ({
-                id: Date.now()
-              })
-            }}
-            editable={{
-              type: 'multiple',
-              editableKeys,
-              onChange: setEditableRowKeys,
-              actionRender: (row, _, dom) => {
-                return [dom.delete]
-              }
-            }}
-          />
-        </ProForm.Item>
+        {state.menuId === 1 ? (
+          <>
+            <ProFormText name="name" label="组名称" required />
+            <ProFormText name="id" hidden />
+            <ProForm.Item name="departmentIds" label="应用部门" required>
+              <TreeSelect treeData={department} multiple={true} />
+            </ProForm.Item>
+            <ProForm.Item
+              label="状态设置"
+              name="stageSettings"
+              initialValue={defaultData}
+              trigger="onValuesChange">
+              <EditableProTable<StageSettingsType>
+                rowKey="id"
+                toolBarRender={false}
+                columns={columns}
+                recordCreatorProps={{
+                  newRecordType: 'dataSource',
+                  position: 'bottom',
+                  record: () => ({
+                    id: Date.now()
+                  })
+                }}
+                editable={{
+                  type: 'multiple',
+                  editableKeys,
+                  onChange: setEditableRowKeys,
+                  actionRender: (row, _, dom) => {
+                    return [dom.delete]
+                  }
+                }}
+              />
+            </ProForm.Item>
+          </>
+        ) : null}
+        {state.menuId === 2 ? (
+          <>
+            <ProFormText name="id" hidden />
+            <ProFormText name="name" label="来源名称" required />
+          </>
+        ) : null}
       </ModalForm>
     </div>
   )

+ 17 - 1
src/services/user/api.ts

@@ -188,7 +188,23 @@ export async function sendNotice(params: Api.SendNoticeParams) {
   })
 }
 
-/** 获得来源列表 */
+/** 获得来源列表 */
 export async function getClientSourceList() {
   return request<API.ClientSourceList[]>('/ClientSource/list')
 }
+
+/** 新增来源 */
+export async function addClientSource(params: API.AddClientSourceParam) {
+  return request('/ClientSource/add', {
+    method: 'POST',
+    data: params
+  })
+}
+
+/** 更新编辑 */
+export async function updateClientSource(params: API.UpdateClientSourceParam) {
+  return request('/ClientSource/update', {
+    method: 'POST',
+    data: params
+  })
+}

+ 9 - 0
src/services/user/typings.d.ts

@@ -281,4 +281,13 @@ declare namespace API {
     id: string
     name: string
   }
+
+  type AddClientSourceParam = {
+    name: string
+  }
+
+  type UpdateClientSourceParam = {
+    id: string
+    name: string
+  }
 }