shenwu 6 bulan lalu
induk
melakukan
d39aa12dfb

+ 108 - 4
src/pages/Distributor/Account/index.tsx

@@ -1,12 +1,37 @@
-import { PageContainer, ProTable } from "@ant-design/pro-components"
+import { ActionType, BetaSchemaForm, PageContainer, ProFormInstance, ProTable } from "@ant-design/pro-components"
 import { columns } from "./tableConfig"
 import { useAjax } from "@/Hook/useAjax"
-import { distributorAccountList } from "@/services/distributor/account"
+import { distributorAccountAdd, distributorAccountList, distributorAccountUpdate } from "@/services/distributor/account"
+import { Button, message } from "antd"
+import { useRef, useState } from "react"
+import { PlusCircleOutlined } from "@ant-design/icons"
 
 const Page: React.FC = () => {
+    const actionRef = useRef<ActionType>();
+    const formRef = useRef<ProFormInstance>();
+    const [open, setOpen] = useState(false)
     let getList = useAjax((params) => distributorAccountList(params), { type: 'table' })
+    let DistributorAccountUpdate = useAjax((params) => distributorAccountUpdate(params));
+    let add = useAjax((params) => distributorAccountAdd(params));
+    const upDate = (id: any, enabled: boolean) => {
+        DistributorAccountUpdate.run({ id, enabled }).then(res => {
+            if (res.code === 200) {
+                message.success(enabled ? '启动成功' : '停用成功');
+                actionRef.current?.reload()
+            }
+        })
+    }
+    const submit = async (values: any) => {
+        console.log(values)
+        add.run(values).then(res => {
+            actionRef?.current?.reload();
+            message.success('操作成功!');
+            setOpen(false);
+        })
+    }
     return <PageContainer>
         <ProTable<any, any>
+            actionRef={actionRef}
             headerTitle={"账号列表"}
             rowKey={(r) => r.id}
             search={{
@@ -15,9 +40,88 @@ const Page: React.FC = () => {
             request={async (params) => {
                 return await getList.run(params)
             }}
-            columns={columns()}
+            columns={columns(upDate)}
             scroll={{ x: "auto" }}
-            // bordered
+            toolBarRender={() => {
+                return [
+                    <Button
+                        type="primary"
+                        onClick={() => {
+                            setOpen(true);
+                        }}
+                    >
+                        <PlusCircleOutlined />
+                        新增账号
+                    </Button>,
+                ];
+            }}
+        // bordered
+        />
+        <BetaSchemaForm
+            title={'新增账号'}
+            formRef={formRef}
+            width={600}
+            open={open}
+            modalProps={{ destroyOnClose: true }}
+            onOpenChange={(b) => {
+                !b && setOpen(b);
+            }}
+            layoutType={'ModalForm'}
+            labelCol={{ span: 6 }}
+            wrapperCol={{ span: 14 }}
+            // grid={true}
+            layout="horizontal"
+            onFinish={submit}
+            columns={[
+                {
+                    title: '账号昵称',
+                    dataIndex: 'nickname',
+                    formItemProps: {
+                        style: { marginBottom: 10 },
+                        rules: [
+                            {
+                                required: true,
+                                message: '此项为必填项',
+                            },
+                        ],
+                    },
+                },
+                {
+                    title: '账号密码',
+                    dataIndex: 'password',
+                    formItemProps: {
+                        style: { marginBottom: 10 },
+                        rules: [
+                            {
+                                required: true,
+                                message: '此项为必填项',
+                            },
+                        ],
+                    },
+                },
+                {
+                    title: '联系人电话',
+                    dataIndex: 'phoneNum',
+                    formItemProps: {
+                        style: { marginBottom: 10 },
+                        rules: [
+                            {
+                                required: true,
+                                message: '此项为必填项',
+                            },
+                        ],
+                    },
+                },
+                {
+                    title: '备注',
+                    dataIndex: 'remark',
+                    valueType: 'textarea',
+                    formItemProps: {
+                        style: { marginBottom: 10 },
+                    },
+                }
+            ]}
+            loading={add?.loading}
         />
     </PageContainer>
 

+ 18 - 8
src/pages/Distributor/Account/tableConfig.tsx

@@ -1,7 +1,7 @@
 import { ProColumns } from "@ant-design/pro-components";
-import { Badge } from "antd";
+import { Badge, Switch } from "antd";
 
-export const columns = (): ProColumns<any>[] => {
+export const columns = (upDate: (id: any, enabled: boolean) => void): ProColumns<any>[] => {
     return [
         {
             title: "ID",
@@ -30,14 +30,24 @@ export const columns = (): ProColumns<any>[] => {
             align: "center",
         },
         {
-            title: "状态",
+            title: '状态',
             dataIndex: 'enabled',
-            key: "enabled",
+            key: 'enabled',
+            align: 'center',
+            ellipsis: true,
             hideInSearch: true,
-            align: "center",
-            render: (a) => {
-                return <Badge status={a ? "processing" : "error"} text={a ? "正常" : "停用"} />
-            }
+            render: (a: any, b: any) => {
+                return (
+                    <Switch
+                        checkedChildren="正常"
+                        unCheckedChildren="停用"
+                        checked={b?.enabled}
+                        onChange={(enabled) => {
+                            upDate(b?.id, enabled)
+                        }}
+                    />
+                );
+            },
         },
     ];
 }

+ 33 - 11
src/services/distributor/account/index.tsx

@@ -1,24 +1,46 @@
 import { api } from '@/services/api';
 import { request } from '@umijs/max';
-type Page={
-    pageSize:number|string,
-    pageNum:number|string
+type Page = {
+  pageSize: number | string,
+  pageNum: number | string
 }
 
-interface Params extends Page{
-    distributorId?:string,//分销商ID
-    nickname?:string,//账号昵称
-    phoneNum?:string,//手机
+interface Params extends Page {
+  distributorId?: string,//分销商ID
+  nickname?: string,//账号昵称
+  phoneNum?: string,//手机
 }
 /**获取分销商账号列表 */
-export async function distributorAccountList(params:Params) {
-  return request(api+'/admin/distributorAccount/list', {
+export async function distributorAccountList(params: Params) {
+  return request(api + '/admin/distributorAccount/list', {
     method: 'GET',
     params
   });
 }
+/**获取分销商账号全部列表无分页 */
 export async function distributorAccountAll() {
-  return request(api+'/admin/distributorAccount/all', {
+  return request(api + '/admin/distributorAccount/all', {
     method: 'GET',
   });
-}
+}
+
+type Data = {
+
+}
+/**新增 */
+export async function distributorAccountAdd(data: Data) {
+  return request(api + '/admin/distributorAccount/save', {
+    method: 'POST',
+    data
+  });
+}
+
+/**启停 */
+export async function distributorAccountUpdate(params: { id: any, enabled: boolean }) {
+  let { id, enabled } = params
+  return request(api + `/admin/distributorAccount/updateEnabled/${id}`, {
+    method: 'PUT',
+    data: { enabled }
+  });
+}
+