浏览代码

添加部门用户管理及客户管理功能

luocaiyang 3 年之前
父节点
当前提交
3099813ab3

+ 26 - 0
wispro.sp.api/Controllers/OrganizationController.cs

@@ -1,5 +1,6 @@
 using Microsoft.AspNetCore.Http;
 using Microsoft.AspNetCore.Mvc;
+using Microsoft.EntityFrameworkCore;
 using System;
 using System.Collections.Generic;
 using System.Linq;
@@ -142,6 +143,8 @@ namespace wispro.sp.api.Controllers
             return Context.Departments.ToList();
         }
 
+        
+
         public bool DeleteDept(int Id)
         {
             try
@@ -157,6 +160,29 @@ namespace wispro.sp.api.Controllers
             }
 
         }
+
+        public List<Position> GetPositions()
+        {
+            return Context.Positions.ToList();
+        }
+
+        public Position GetPosition(int deptId,int staffId)
+        {
+            var data = Context.DepartmentPositions.Include(pi => pi.Position).FirstOrDefault<DepartmentPosition>(s => s.StaffId == staffId);
+            if(data != null)
+            {
+                return data.Position;
+            }
+            else
+            {
+                return null;
+            }
+        }
+
+        public List<Customer> GetCustomers()
+        {
+            return Context.Customers.ToList();
+        }
         #endregion
     }
 }

+ 187 - 0
wispro.sp.api/Controllers/StaffController.cs

@@ -42,6 +42,193 @@ namespace wispro.sp.api.Controllers
             return ret;
         }
 
+        public ListApiResponse<Staff> QueryInDepartment(int deptId,int pageIndex,int pageSize)
+        {
+            ListApiResponse<Staff> ret = new ListApiResponse<Staff>();
+            var dept = Context.Departments.FirstOrDefault<Department>(d=>d.Id == deptId);
+
+            if (dept != null)
+            {
+                var retList = Context.Staffs.Where<Staff>(s => s.Positions.Where<DepartmentPosition>(dp => dp.department.ancestors.StartsWith(dept.ancestors)).Count() > 0);
+                ret.TotalCount = retList.Count();
+                ret.Results = retList.Skip<Staff>((pageIndex - 1) * pageSize).Take(pageSize).ToList();
+            }
+            else
+            {
+                ret.Results = new List<Staff>();
+            }
+
+            return ret;
+        }
+
+        public ApiSaveResponse Init()
+        {
+            using (var t = Context.Database.BeginTransaction())
+            {
+                try
+                {
+                    Position p = Context.Positions.FirstOrDefault<Position>(p=>p.Name == "普通成员");
+
+                    if (p == null)
+                    {
+                        p = new Position() { Name = "普通成员" };
+                        Context.Positions.Add(p);
+                        Context.SaveChanges();
+                    }
+
+                    foreach (var staff in Context.Staffs.ToList())
+                    {
+                        string[] temStrs = staff.Department.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
+
+                        Department dept = null;
+                        foreach (string depName in temStrs)
+                        {
+                            if (dept == null)
+                            {
+                                System.Text.RegularExpressions.Regex r = new System.Text.RegularExpressions.Regex("\\((.+?)\\)");
+                                System.Text.RegularExpressions.Match m = r.Match(depName);
+
+                                if (m.Success)
+                                {
+                                    var Name1 = depName.Substring(0, m.Index);
+                                    dept = Context.Departments.FirstOrDefault<Department>(d => d.Name == Name1.Trim());
+
+                                    var Name2 = m.Groups[1].Value;
+                                    dept = Context.Departments.FirstOrDefault<Department>(d => d.Name == Name2.Trim() && d.parentId == dept.Id);
+                                }
+                                else
+                                {
+                                    dept = Context.Departments.FirstOrDefault<Department>(d => d.Name == depName.Trim());
+                                }
+                                
+                            }
+                            else
+                            {
+                                dept = Context.Departments.FirstOrDefault<Department>(d => d.Name == depName.Trim() && d.parentId == dept.Id);
+                            }
+                        }
+
+                        if (dept != null)
+                        {
+                            DepartmentPosition dp = new DepartmentPosition();
+                            dp.StaffId = staff.Id;
+                            dp.PositionId = p.Id;
+                            dp.departmentId = dept.Id;
+
+                            Context.DepartmentPositions.Add(dp);
+
+                        }
+                        else
+                        {
+                            System.Diagnostics.Debug.WriteLine($"{staff.Name}\t{staff.Department}");
+                        }
+                    }
+                    Context.SaveChanges();
+
+                    t.Commit();
+                }
+                catch(Exception ex)
+                {
+                    t.Rollback();
+                }
+
+            }
+
+            return new ApiSaveResponse() { Success = true };
+        }
+
+        public ApiSaveResponse SaveUser(SaveUserObject saveUser)
+        {
+            ApiSaveResponse ret = new ApiSaveResponse();
+            using (var t = Context.Database.BeginTransaction())
+            {
+                try
+                {
+
+                    Staff staff = saveUser.staff;
+
+                    if (staff.Id == 0)
+                    {
+
+                        Staff temStaff = Context.Staffs.Where<Staff>(x => x.Name == staff.Name).FirstOrDefault();
+
+                        if (temStaff != null)
+                        {
+                            ret.Success = false;
+                            ret.ErrorMessage = $"用户【{staff.Name}】已存在!";
+                        }
+                        else
+                        {
+                            Context.Staffs.Add(staff);
+                            Context.SaveChanges();
+
+                            DepartmentPosition dp = new DepartmentPosition();
+                            dp.departmentId = saveUser.deptId;
+                            dp.PositionId = saveUser.deptId;
+                            dp.StaffId = temStaff.Id;
+                            Context.DepartmentPositions.Add(dp);
+                        }
+                    }
+                    else
+                    {
+                        Staff editObject = Context.Staffs.Where<Staff>(x => x.Id == staff.Id).FirstOrDefault();
+
+                        if (editObject != null)
+                        {
+                            editObject.Account = staff.Account;
+                            editObject.Department = staff.Department;
+                            editObject.EntyDate = staff.EntyDate;
+                            editObject.IsCalPerformsnce = staff.IsCalPerformsnce;
+                            editObject.IsOnJob = staff.IsOnJob;
+                            editObject.Mail = staff.Mail;
+                            editObject.Memo = staff.Memo;
+                            editObject.Mobile = staff.Mobile;
+                            editObject.Name = staff.Name;
+                            editObject.Password = staff.Password;
+                            editObject.Sex = staff.Sex;
+                            editObject.StaffGradeId = staff.StaffGradeId;
+                            editObject.Status = staff.Status;
+                            editObject.Tel = staff.Tel;
+                            editObject.WorkPlace = staff.WorkPlace;
+
+                            var temDP = Context.DepartmentPositions
+                                .FirstOrDefault<DepartmentPosition>(d =>
+                                    d.departmentId == saveUser.deptId &&
+                                    d.PositionId == saveUser.positionId &&
+                                    d.StaffId == editObject.Id);
+                            if (temDP == null)
+                            {
+                                DepartmentPosition dp = new DepartmentPosition();
+                                dp.departmentId = saveUser.deptId;
+                                dp.PositionId = saveUser.deptId;
+                                dp.StaffId = editObject.Id;
+                                Context.DepartmentPositions.Add(dp);
+                            }
+                        }
+                        else
+                        {
+                            ret.Success = false;
+                            ret.ErrorMessage = $"编号为【{staff.Id}】的用户不存在!";
+                        }
+
+                    }
+
+                    Context.SaveChanges();
+                    t.Commit();
+                    ret.Success = true;
+
+                }
+                catch (Exception ex)
+                {
+                    t.Rollback();
+                    ret.Success = false;
+                    ret.ErrorMessage = ex.Message;
+                }
+            }
+
+            return ret;
+        }
+
         [HttpPost]
         public ApiSaveResponse Save(Staff staff)
         {

+ 1 - 1
wispro.sp.api/spDbContext.cs

@@ -445,7 +445,7 @@ namespace wispro.sp.api
                     .HasForeignKey(d=>d.PositionId);
 
                 entity.HasOne(d => d.Staff)
-                    .WithMany()
+                    .WithMany(d=>d.Positions)
                     .HasForeignKey(d => d.StaffId);
             });
 

+ 18 - 0
wispro.sp.share/SaveUserObject.cs

@@ -0,0 +1,18 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using wispro.sp.entity;
+
+namespace wispro.sp.share
+{
+    public class SaveUserObject
+    {
+        public int deptId { get; set; }
+
+        public int positionId { get; set; }
+
+        public Staff staff { get; set; }
+    }
+}

+ 10 - 0
wispro.sp.web/Components/PositionSelect.razor

@@ -0,0 +1,10 @@
+<Select DataSource="@_allPositions"
+        DefaultValue="@PositionId"
+        LabelName="@nameof(wispro.sp.entity.Position.Name)"
+        ValueName="@nameof(wispro.sp.entity.Position.Id)"
+        Style="width: 200px"
+        Placeholder="选择一个职位"
+        IgnoreItemChanges="false"
+        AllowClear
+        OnSelectedItemChanged="OnSelectedItemChangedHandler">
+</Select>

+ 38 - 0
wispro.sp.web/Components/PositionSelect.razor.cs

@@ -0,0 +1,38 @@
+using Microsoft.AspNetCore.Components;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using wispro.sp.entity;
+using wispro.sp.web.Services;
+
+namespace wispro.sp.web.Components
+{
+    public partial class PositionSelect
+    {
+        private List<Position> _allPositions;
+        private Position _SelectedItem;
+
+        [Inject] OrganizationService _Service { get; set; }
+
+        [Parameter]
+        public int? PositionId { get; set; }
+
+
+        [Parameter]
+        public EventCallback<int?> PositionIdChanged { get; set; }
+
+        protected override async System.Threading.Tasks.Task OnInitializedAsync()
+        {
+            base.OnInitialized();
+
+            _allPositions = await _Service.getPositions();
+        }
+
+        private void OnSelectedItemChangedHandler(Position value)
+        {
+            _SelectedItem = value;
+            PositionIdChanged.InvokeAsync(_SelectedItem.Id);
+        }
+    }
+}

+ 32 - 9
wispro.sp.web/Components/RightMenuTreeNode.razor

@@ -1,9 +1,32 @@
-<ContextMenu Id="@($"righMenu-{Department.Id}")" Context="pp">
-    <Item OnClick="() => _OnCreate(Department)">添加</Item>
-    <Item OnClick="() => _OnEdit(Department)">修改</Item>
-    <Item OnClick="() => _OnDelete(Department)">删除</Item>
-</ContextMenu>
-
-<ContextMenuTrigger MenuId="@($"righMenu-{Department.Id}")">
-    <div>@Department.Name</div>
-</ContextMenuTrigger>
+
+
+
+    <Menu Mode=MenuMode.Horizontal Style="font-size: small;" TriggerSubMenuAction="Trigger.ContextMenu" >
+        <AntDesign.SubMenu>
+            <TitleTemplate>
+                <span>
+                    <Icon Type="folder" Theme="outline"></Icon>
+                    <span>@Department.Name</span>
+                </span>
+            </TitleTemplate>
+            <ChildContent>
+                <MenuItem Icon="folder-add" OnClick="() => _OnCreate(Department)">添加</MenuItem>
+                <MenuItem Icon="edit" OnClick="() =>_OnEdit(Department)">编辑</MenuItem>
+                <MenuItem Icon="delete" OnClick="() => _OnDelete(Department)">删除</MenuItem>
+            </ChildContent>
+        </AntDesign.SubMenu>
+    </Menu>
+  
+
+
+@*<Dropdown Trigger="@(new Trigger[] { Trigger.Click })">
+    <Overlay>
+        <MenuItem Icon="folder-add" OnClick="() => _OnCreate(Department)">添加</MenuItem>
+        <MenuItem Icon="edit" OnClick="() =>_OnEdit(Department)">编辑</MenuItem>
+        <MenuItem Icon="delete" OnClick="() => _OnDelete(Department)">删除</MenuItem>
+    </Overlay>
+    <Unbound>
+        <div>@Department.Name<Icon Type="down" Style="float:right"/></div>
+    </Unbound>
+</Dropdown>*@
+

+ 16 - 0
wispro.sp.web/Components/RightMenuTreeNode.razor.cs

@@ -1,4 +1,5 @@
 using Microsoft.AspNetCore.Components;
+using Microsoft.JSInterop;
 using System;
 using System.Collections.Generic;
 using System.Linq;
@@ -9,6 +10,8 @@ namespace wispro.sp.web.Components
 {
     public partial class RightMenuTreeNode
     {
+        bool menuVisiable = false;
+
         [Parameter]
         public Department Department { get; set; }
 
@@ -47,5 +50,18 @@ namespace wispro.sp.web.Components
             }
 
         }
+
+        
+        private  void ShowMenu(bool isShowmenu)
+        {
+            Console.WriteLine($"ShowMenu:{isShowmenu}");
+            menuVisiable = isShowmenu;
+        }
+
+        bool _isOverMenu = false;
+        private void isOverMenu(bool isOver)
+        {
+            _isOverMenu = isOver;
+        }
     }
 }

+ 7 - 0
wispro.sp.web/Layouts/BasicLayout.razor

@@ -125,6 +125,13 @@
                 },
                 new MenuDataItem
                 {
+                    Path ="/Department",
+                    Name ="部门管理",
+                    Key= "dept",
+                    Icon = ""
+                },
+                new MenuDataItem
+                {
                     Path ="/StaffGrade",
                     Name ="代理人系数设定",
                     Key= "sg",

+ 6 - 186
wispro.sp.web/Pages/CustomerList.razor.cs

@@ -1,198 +1,18 @@
 using AntDesign;
 using AntDesign.TableModels;
+using Microsoft.AspNetCore.Components;
 using Microsoft.AspNetCore.Components.Web;
 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Threading.Tasks;
+using wispro.sp.web.Services;
 
 namespace wispro.sp.web.Pages
 {
     public partial class CustomerList
     {
-        private List<entity.Customer> _Customers =new List<entity.Customer>()
-            {
-                new entity.Customer()
-                {
-                    Id=1,
-                    Name = "OPPO广东移动通信有限公司",
-                    Address="广东省东莞市长安镇乌沙海滨路18号",
-                    Phone="4001-666-888",
-                    ContactMan="刘波",
-                    ResponseMan= new entity.Staff(){Name ="钟子敏",Id =1},
-                    ResponseManId= 1
-},
-                new entity.Customer()
-                {
-                    Id = 2,
-                    Name = "OPPO广东移动通信有限公司",
-                    Address = "广东省东莞市长安镇乌沙海滨路18号",
-                    Phone = "4001-666-888",
-                    ContactMan = "刘波",
-                    ResponseMan= new entity.Staff(){Name ="钟子敏",Id =1},
-                    ResponseManId= 1
-                },
-                new entity.Customer()
-                {
-                    Id = 3,
-                    Name = "OPPO广东移动通信有限公司",
-                    Address = "广东省东莞市长安镇乌沙海滨路18号",
-                    Phone = "4001-666-888",
-                    ContactMan = "刘波",
-                    ResponseMan= new entity.Staff(){Name ="钟子敏",Id =1},
-                    ResponseManId= 1
-                },
-                new entity.Customer()
-                {
-                    Id = 4,
-                    Name = "OPPO广东移动通信有限公司",
-                    Address = "广东省东莞市长安镇乌沙海滨路18号",
-                    Phone = "4001-666-888",
-                    ContactMan = "刘波",
-                    ResponseMan= new entity.Staff(){Name ="钟子敏",Id =1},
-                    ResponseManId= 1
-                },
-                new entity.Customer()
-                {
-                    Id = 5,
-                    Name = "OPPO广东移动通信有限公司",
-                    Address = "广东省东莞市长安镇乌沙海滨路18号",
-                    Phone = "4001-666-888",
-                    ContactMan = "刘波",
-                    ResponseMan= new entity.Staff(){Name ="钟子敏",Id =1},
-                    ResponseManId= 1
-                },
-                new entity.Customer()
-                {
-                    Id = 6,
-                    Name = "OPPO广东移动通信有限公司",
-                    Address = "广东省东莞市长安镇乌沙海滨路18号",
-                    Phone = "4001-666-888",
-                    ContactMan = "刘波",
-                    ResponseMan= new entity.Staff(){Name ="钟子敏",Id =1},
-                    ResponseManId= 1
-                },
-                new entity.Customer()
-                {
-                    Id = 7,
-                    Name = "OPPO广东移动通信有限公司",
-                    Address = "广东省东莞市长安镇乌沙海滨路18号",
-                    Phone = "4001-666-888",
-                    ContactMan = "刘波",
-                    ResponseMan= new entity.Staff(){Name ="钟子敏",Id =1},
-                    ResponseManId= 1
-                },
-                new entity.Customer()
-                {
-                    Id = 8,
-                    Name = "OPPO广东移动通信有限公司",
-                    Address = "广东省东莞市长安镇乌沙海滨路18号",
-                    Phone = "4001-666-888",
-                    ContactMan = "刘波",
-                    ResponseMan= new entity.Staff(){Name ="钟子敏",Id =1},
-                    ResponseManId= 1
-                },
-                new entity.Customer()
-                {
-                    Id = 9,
-                    Name = "OPPO广东移动通信有限公司",
-                    Address = "广东省东莞市长安镇乌沙海滨路18号",
-                    Phone = "4001-666-888",
-                    ContactMan = "刘波",
-                    ResponseMan= new entity.Staff(){Name ="钟子敏",Id =1},
-                    ResponseManId= 1
-                },
-                new entity.Customer()
-                {
-                    Id = 10,
-                    Name = "OPPO广东移动通信有限公司",
-                    Address = "广东省东莞市长安镇乌沙海滨路18号",
-                    Phone = "4001-666-888",
-                    ContactMan = "刘波",
-                    ResponseMan= new entity.Staff(){Name ="钟子敏",Id =1},
-                    ResponseManId= 1
-                },
-                new entity.Customer()
-                {
-                    Id = 11,
-                    Name = "OPPO广东移动通信有限公司",
-                    Address = "广东省东莞市长安镇乌沙海滨路18号",
-                    Phone = "4001-666-888",
-                    ContactMan = "刘波",
-                    ResponseMan= new entity.Staff(){Name ="钟子敏",Id =1},
-                    ResponseManId= 1
-                },
-                new entity.Customer()
-                {
-                    Id = 12,
-                    Name = "OPPO广东移动通信有限公司",
-                    Address = "广东省东莞市长安镇乌沙海滨路18号",
-                    Phone = "4001-666-888",
-                    ContactMan = "刘波",
-                    ResponseMan= new entity.Staff(){Name ="钟子敏",Id =1},
-                    ResponseManId= 1
-                },
-                new entity.Customer()
-                {
-                    Id = 13,
-                    Name = "OPPO广东移动通信有限公司",
-                    Address = "广东省东莞市长安镇乌沙海滨路18号",
-                    Phone = "4001-666-888",
-                    ContactMan = "刘波",
-                    ResponseMan= new entity.Staff(){Name ="钟子敏",Id =1},
-                    ResponseManId= 1
-                },
-                new entity.Customer()
-                {
-                    Id = 14,
-                    Name = "OPPO广东移动通信有限公司",
-                    Address = "广东省东莞市长安镇乌沙海滨路18号",
-                    Phone = "4001-666-888",
-                    ContactMan = "刘波",
-                    ResponseMan= new entity.Staff(){Name ="钟子敏",Id =1},
-                    ResponseManId= 1
-                },
-                new entity.Customer()
-                {
-                    Id = 15,
-                    Name = "OPPO广东移动通信有限公司",
-                    Address = "广东省东莞市长安镇乌沙海滨路18号",
-                    Phone = "4001-666-888",
-                    ContactMan = "刘波",
-                    ResponseMan= new entity.Staff(){Name ="钟子敏",Id =1},
-                    ResponseManId= 1
-                },
-                new entity.Customer()
-                {
-                    Id = 16,
-                    Name = "OPPO广东移动通信有限公司",
-                    Address = "广东省东莞市长安镇乌沙海滨路18号",
-                    Phone = "4001-666-888",
-                    ContactMan = "刘波",
-                    ResponseMan= new entity.Staff(){Name ="钟子敏",Id =1},
-                    ResponseManId= 1
-                },
-                new entity.Customer()
-                {
-                    Id = 17,
-                    Name = "OPPO广东移动通信有限公司",
-                    Address = "广东省东莞市长安镇乌沙海滨路18号",
-                    Phone = "4001-666-888",
-                    ContactMan = "刘波",
-                   ResponseMan= new entity.Staff(){Name ="钟子敏",Id =1},
-                    ResponseManId= 1
-                },
-                new entity.Customer()
-                {
-                    Id = 18,
-                    Name = "OPPO广东移动通信有限公司",
-                    Address = "广东省东莞市长安镇乌沙海滨路18号",
-                    Phone = "4001-666-888",
-                    ContactMan = "刘波",
-                    ResponseMan= new entity.Staff(){Name ="钟子敏",Id =1},
-                    ResponseManId= 1
-                }
-            };
+        private List<entity.Customer> _Customers =new List<entity.Customer>();
 
         IEnumerable<entity.Customer> selectedRows;
         ITable table;
@@ -206,13 +26,13 @@ namespace wispro.sp.web.Pages
         bool _visible = false;
         bool _isAdd = false;
 
+        [Inject]OrganizationService  orgService { get; set; }
 
-
-        protected override void OnInitialized()
+        protected override async System.Threading.Tasks.Task OnInitializedAsync()
         {
 
             _loading = true;
-
+            _Customers = await  orgService.GetAllCustomer();
             //await System.Threading.Thread.Sleep();
             //List<wispro.sp.entity.StaffGrade> data = await Http.GetFromJsonAsync<List<wispro.sp.entity.StaffGrade>>($"http://localhost:39476/api/StaffGrade/GetAll");
 

+ 155 - 34
wispro.sp.web/Pages/Organization/Department.razor

@@ -15,55 +15,99 @@
         </Breadcrumb>
     </Breadcrumb>
     <Content>
-        <Button Type="primary" Icon="plus" OnClick="()=>AddNew(null)" Style="float:right">添加</Button>
+        @*<Button Type="primary" Icon="folder-add" OnClick="()=>AddNew(null)" Style="float:right">添加</Button>*@
+
     </Content>
     <ChildContent>
         <AntDesign.Layout>
-            <Sider Style="background-color:white" Width="260">
+            <Sider Style="background-color:white" Width="300">
                 <div style="width:fit-content">
                     @if (departments != null)
                     {
-                    <Tree @ref="tree" DefaultExpandAll Draggable BlockNode ShowLine="true" ShowLeafIcon="true"
-                          ShowIcon DataSource="GetChildren(null)"
-                          TitleExpression="x => x.DataItem.Name"
-                          ChildrenExpression="x => GetChildren(x.DataItem)"
-                          IsLeafExpression="x => GetChildren(x.DataItem)?.Count == 0"
-                          KeyExpression="x => x.DataItem.Id.ToString()"
-                          TItem="wispro.sp.entity.Department" OnDragEnd="e => { }"
-                          OnClick="OnSelect"
-                          Style="width:250px;">
-                        <TitleTemplate>
-                            <wispro.sp.web.Components.RightMenuTreeNode Department="@context.DataItem"/>
-
-                            @*<Menu Mode=MenuMode.Horizontal Style="float:right;font-size: small;">
-                            <SubMenu>
-                                <TitleTemplate>
-                                    <Icon Type="plus" />
-                                </TitleTemplate>
-                                <ChildContent>
-                                    <MenuItem Icon="folder-add" OnClick="() => AddNew(context.DataItem)">添加</MenuItem>
-                                    <MenuItem Icon="edit" OnClick="() => EditDept(context.DataItem)">编辑</MenuItem>
-                                    <MenuItem Icon="delete" OnClick="() => DeleteDept(context.DataItem)">删除</MenuItem>
-                                </ChildContent>
-                            </SubMenu>
-                        </Menu>*@
-                        </TitleTemplate>
-                    </Tree>
+                        <Tree @ref="tree" Draggable BlockNode DefaultExpandParent AutoExpandParent
+                              DataSource="GetChildren(null)"
+                              TitleExpression="x => x.DataItem.Name"
+                              ChildrenExpression="x => GetChildren(x.DataItem)"
+                              IsLeafExpression="x => GetChildren(x.DataItem)?.Count == 0"
+                              KeyExpression="x => x.DataItem.Id.ToString()"
+                              TItem="wispro.sp.entity.Department" 
+                              OnClick="OnSelect"
+                              Style="width:250px;">
+                            <TitleTemplate>
+                                <wispro.sp.web.Components.RightMenuTreeNode 
+                                                Department="@context.DataItem"
+                                                OnCreate="()=>AddNew(context.DataItem)"
+                                                OnEdit="()=>EditDept(context.DataItem)"
+                                                OnDelete="() => DeleteDept(context.DataItem)" />
+
+                            </TitleTemplate>
+                        </Tree>
+                    }
+                    else
+                    {
+                        <Spin />
                     }
-                        else
-                        {
-                            <Spin/>
-                        }
                 </div>
             </Sider>
             <Content>
+                <AntDesign.Layout Style=" padding: 0 24px 24px;">
+                    <Content>
+                        <div><Button Type="primary" Icon="user-add" OnClick="()=>AddNewUser()" Style="float:right">添加人员</Button></div>
+                        @if (_loading)
+                        {
+                            <center><Spin /></center>
+                        }
+                        else
+                        {
+
+                            <AntDesign.Table @ref="table" @bind-PageIndex="_pageIndex" @bind-PageSize="_pageSize"
+                                             TItem="Staff"
+                                             Loading="_loading"
+                                             DataSource="@forecasts"
+                                             Total="_total"
+                                             @bind-SelectedRows="selectedRows"
+                                             OnRow="OnRow"
+                                             Bordered=@true
+                                             Size=@TableSize.Middle>
+                                <ChildContent>
+                                    <Selection Key="@(context.Name)" />
+                                    <AntDesign.Column Title="序号" TData="int">
+                                        @serialNumber(_pageIndex, _pageSize, context.Name)
+                                    </AntDesign.Column>
+                                    <AntDesign.Column Title="姓名" @bind-Field="@context.Name" Sortable Filterable />
+                                    <AntDesign.Column Title="入职日期" @bind-Field="@context.EntyDate" Format="yyyy-MM-dd" Sortable Filterable />
+                                    <AntDesign.Column Title="部门" @bind-Field="@context.Department" Sortable Filterable />
+                                    <AntDesign.Column Title="工作地" Field="@context.WorkPlace" Sortable Filterable />
+
+                                    <AntDesign.Column Title="备注" @bind-Field="@context.Memo" Sortable Filterable />
+                                    <ActionColumn>
+                                        <Space>
+                                            <SpaceItem><Button Type="@ButtonType.Text" OnClick="()=>Edit(context)">编辑</Button></SpaceItem>
+                                            <SpaceItem><Button Danger Type="@ButtonType.Text" OnClick="()=>Delete(context)">删除</Button></SpaceItem>
+                                        </Space>
+                                    </ActionColumn>
+                                </ChildContent>
+                                <PaginationTemplate>
+                                    <div style="display: flex; align-items: center">
+                                        <Pagination Class="my-custom-pagination"
+                                                    Total="@_total"
+                                                    PageSize="@_pageSize"
+                                                    Current="@_pageIndex"
+                                                    ShowSizeChanger="@true"
+                                                    OnChange="HandlePageChange" />
+                                    </div>
+                                </PaginationTemplate>
+                            </AntDesign.Table>
 
+                        }
+                    </Content>
+                </AntDesign.Layout>
             </Content>
         </AntDesign.Layout>
     </ChildContent>
 </PageContainer>
 
-<Modal Title="新建"
+<Modal Title="部门添加/修改"
        Visible="@newModal"
        OnOk="@NewOk"
        OnCancel="@NewCancel">
@@ -77,4 +121,81 @@
             <TextArea @bind-Value="@context.Memo" MinRows="4" />
         </FormItem>
     </Form>
-</Modal>
+</Modal>
+
+<Modal Title="职员添加/修改"
+       Visible="@_newUserModal"
+       OnOk="@HandleOk"
+       OnCancel="@HandleCancel">
+    
+    <Form Model="EditingStaff" LabelColSpan="6"
+          WrapperColSpan="16">
+        <FormItem Label="姓名">
+            <Input @bind-Value="@context.Name" />
+        </FormItem>
+        <FormItem Label="岗位状态">
+            <Input @bind-Value="@context.Status" />
+        </FormItem>
+
+        <FormItem Label="是否计算绩效">
+            <Switch @bind-Value="@context.IsCalPerformsnce" />
+        </FormItem>
+
+        <FormItem Label="工程师等级">
+            <wispro.sp.web.Components.UserGradeSelect @bind-StaffGradeId="@EditingStaff.StaffGradeId" />
+        </FormItem>
+
+        <FormItem Label="职位">
+            <Select DataSource="@_allPositions"
+                    DefaultValue="@PositionId"
+                    LabelName="@nameof(wispro.sp.entity.Position.Name)"
+                    ValueName="@nameof(wispro.sp.entity.Position.Id)"
+                    Style="width: 200px"
+                    Placeholder="请选择一个职位"
+                    IgnoreItemChanges="false"
+                    AllowClear
+                    OnClearSelected="()=>OnSelectedItemChangedHandler(null)"
+                    OnSelectedItemChanged="OnSelectedItemChangedHandler">
+            </Select>
+        </FormItem>
+
+        <FormItem Label="工作地">
+            <Select Mode="default"
+                    DataSource="@_places"
+                    @bind-Value="@context.WorkPlace">
+            </Select>
+        </FormItem>
+
+        <FormItem Label="入职时间">
+            <DatePicker @bind-Value="@context.EntyDate" />
+        </FormItem>
+
+        <FormItem Label="备注">
+            <TextArea @bind-Value="@context.Memo" MinRows="4" />
+        </FormItem>
+
+        @if (_isAdd)
+        {
+            <FormItem Label="账号">
+                <Input @bind-Value="@context.Account" />
+            </FormItem>
+
+            <FormItem Label="账号">
+                <Input @bind-Value="@context.Password" Type="password" />
+            </FormItem>
+        }
+
+    </Form>
+
+</Modal>
+
+<style>
+    .my-custom-pagination {
+        margin: 15px 0;
+    }
+
+        .my-custom-pagination .ant-pagination-item,
+        .my-custom-pagination .ant-pagination-item-link {
+            border-radius: 100%;
+        }
+</style>

+ 183 - 9
wispro.sp.web/Pages/Organization/Department.razor.cs

@@ -1,4 +1,5 @@
 using AntDesign;
+using AntDesign.TableModels;
 using Microsoft.AspNetCore.Components;
 using Microsoft.AspNetCore.Components.Web;
 using System;
@@ -6,6 +7,8 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Text.Json;
 using System.Threading.Tasks;
+using wispro.sp.entity;
+using wispro.sp.share;
 using wispro.sp.web.Services;
 
 namespace wispro.sp.web.Pages.Organization
@@ -14,24 +17,33 @@ namespace wispro.sp.web.Pages.Organization
     {
         private List<wispro.sp.entity.Department> departments;
         Tree<wispro.sp.entity.Department> tree;
-        string searchKey;
         bool _loading = false;
 
         entity.Department _editDepartment;
-       [Inject] OrganizationService orgService { get; set; }
+        [Inject] OrganizationService orgService { get; set; }
+
+        [Inject] MessageService _message { get; set; }
 
         protected override async System.Threading.Tasks.Task OnInitializedAsync()
         {
-
+            //await orgService.Init();
             _loading = true;
 
-            departments =await orgService.GetDepartments(); 
-                
+            departments =await orgService.GetDepartments();
+
+            var data = await orgService.GetStaffs(null, 1, 10);
+            _loading = false;
+            forecasts = data.Results;
+            _total = data.TotalCount;
+
+            _StaffGrade = await orgService.GetStaffGrades();
+            _allPositions = await orgService.getPositions();
             _loading = false;
         }
 
         #region 部门操作
         bool newModal = false;
+        
         private void AddNew(entity.Department parentDept)
         {
             _editDepartment = new entity.Department();
@@ -53,8 +65,11 @@ namespace wispro.sp.web.Pages.Organization
             
             newModal = true; 
         }
+
         
 
+
+
         private void EditDept(entity.Department department)
         {
             _editDepartment = department;
@@ -71,9 +86,9 @@ namespace wispro.sp.web.Pages.Organization
         private async System.Threading.Tasks.Task NewOk(MouseEventArgs e)
         {
             newModal = false;
-            Console.WriteLine(JsonSerializer.Serialize(_editDepartment)); 
+            //Console.WriteLine(JsonSerializer.Serialize(_editDepartment)); 
             var retObj = await orgService.SaveDept(_editDepartment);
-            Console.WriteLine(JsonSerializer.Serialize(retObj)); 
+            //Console.WriteLine(JsonSerializer.Serialize(retObj)); 
             departments = await orgService.GetDepartments();
             StateHasChanged();
         }
@@ -84,12 +99,20 @@ namespace wispro.sp.web.Pages.Organization
         }
         #endregion
 
-        void OnSelect(TreeEventArgs<entity.Department> e)
+        async Task OnSelect(TreeEventArgs<entity.Department> e)
         {
             _editDepartment = e.Node.DataItem;
-            //Console.WriteLine(JsonSerializer.Serialize(e));
+            //Console.WriteLine($"OnSelect:{JsonSerializer.Serialize(_editDepartment)}" );
+            _loading = true;
+            var data = await orgService.GetStaffs(_editDepartment, 1, 1000);
+            forecasts = data.Results;
+            _total = data.TotalCount;
+            _loading = false;
+
         }
 
+        
+
         private List<wispro.sp.entity.Department> GetChildren(wispro.sp.entity.Department dept)
         {
             if(dept == null)
@@ -112,5 +135,156 @@ namespace wispro.sp.web.Pages.Organization
             if (args.Button == 2)
                 Console.WriteLine("This is a right click");
         }
+
+        #region 职员操作
+        private List<Staff> forecasts;
+        IEnumerable<Staff> selectedRows;
+        ITable table;
+
+        int _pageIndex = 1;
+        int _pageSize = 10;
+        int _total = 0;
+        
+
+        Staff EditingStaff = null;
+        bool _visible = false;
+
+        bool _isAdd = false;
+
+        List<wispro.sp.entity.StaffGrade> _StaffGrade;
+
+        string[] _places = new string[] { "深圳", "苏州", "南通", "西安", "北京", "杭州", "武汉" };
+
+        int _SelectGradeId;
+
+        bool _newUserModal = false;
+        private void AddNewUser()
+        {
+            if (_editDepartment == null)
+            {
+
+            }
+            else
+            {
+                EditingStaff = new Staff();
+                _isAdd = true;
+                _newUserModal = true;
+            }
+        }
+
+        private int serialNumber(int pageIndex, int pageSize, string name)
+        {
+            int iIndex = 0;
+            foreach (Staff sf in forecasts)
+            {
+                iIndex++;
+
+                if (sf.Name == name)
+                {
+                    break;
+                }
+            }
+            return (pageIndex - 1) * pageSize + iIndex;
+        }
+
+        private async Task Edit(Staff staff)
+        {
+            EditingStaff = staff;
+            selectPosition = await orgService.getPosition(staff, _editDepartment);
+            if(selectPosition == null)
+            {
+                selectPosition = new Position();
+            }
+            PositionId = selectPosition.Id;
+            _isAdd = false;
+            _newUserModal  = true;
+        }
+
+        private void Delete(Staff staff)
+        {
+
+        }
+
+        Dictionary<string, object> OnRow(RowData<Staff> row)
+        {
+            Dictionary<string, object> ret = new Dictionary<string, object>();
+
+            ret.Add("id", row.RowIndex);
+            ret.Add("onclick", ((Action)delegate
+            {
+                //_message.Info($"row {row.Data.Name} was clicked");
+            }));
+
+
+            return ret;
+        }
+
+        public async System.Threading.Tasks.Task OnChange(QueryModel<Staff> queryModel)
+        {
+            if (!_loading)
+            {
+                Console.WriteLine($"OnChange:{JsonSerializer.Serialize(queryModel)}");
+                _loading = true;
+                ListApiResponse<Staff> data = await orgService.GetStaffs(_editDepartment, queryModel); //Http.GetFromJsonAsync<ListApiResponse<Staff>>("http://localhost:39476/api/Staff/Query?" + GetRandomuserParams(queryModel));
+
+
+                forecasts = data.Results;
+                _total = data.TotalCount;
+
+                _loading = false;
+            }
+
+        }
+        private void HandlePageChange(PaginationEventArgs args)
+        {
+            if (_pageIndex != args.Page)
+            {
+                _pageIndex = args.Page;
+            }
+
+            if (_pageSize != args.PageSize)
+            {
+                _pageSize = args.PageSize;
+            }
+        }
+
+        private List<Position> _allPositions;
+        Position selectPosition= new Position();
+        int PositionId;
+        private async System.Threading.Tasks.Task HandleOk(MouseEventArgs e)
+        {
+            //selectPosition = new Position() { Id = PositionId };
+
+            var data = await orgService.SaveUser(_editDepartment, selectPosition, EditingStaff); // Http.PostAsJsonAsync<wispro.sp.entity.Staff>($"http://localhost:39476/api/Staff/Save", EditingStaff);
+
+            if (data.Success)
+            {
+                await _message.Success("数据已保存!");
+                _newUserModal = false;
+                _loading = true;
+                var data1 = await orgService.GetStaffs(_editDepartment, 1, 1000);
+                forecasts = data1.Results;
+                _total = data1.TotalCount;
+                _loading = false;
+            }
+            else
+            {
+                await _message.Error($"{data.ErrorMessage}");
+            }
+
+            //_newUserModal = false;
+        }
+
+        private void HandleCancel(MouseEventArgs e)
+        {
+            _newUserModal = false;
+        }
+
+        private void OnSelectedItemChangedHandler(Position value)
+        {
+            selectPosition  = value;
+            //PositionIdChanged.InvokeAsync(_SelectedItem.Id);
+        }
+        #endregion
     }
 }

+ 103 - 1
wispro.sp.web/Services/OrganizationService.cs

@@ -1,8 +1,11 @@
-using System;
+using AntDesign;
+using AntDesign.TableModels;
+using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Threading.Tasks;
 using wispro.sp.entity;
+using wispro.sp.share;
 
 namespace wispro.sp.web.Services
 {
@@ -28,11 +31,110 @@ namespace wispro.sp.web.Services
             return data;
         }
 
+        public async Task<List<Position>> getPositions()
+        {
+            var ret = await _httpClient.Get<List<Position>>($"Organization/GetPositions");
+            return ret;
+        }
+
+        public async Task<List<Customer>> GetAllCustomer()
+        {
+            var ret = await _httpClient.Get<List<Customer>>($"Organization/GetCustomers");
+            return ret;
+        }
+
         public async  Task<bool> DeleteDept(int deptId)
         {
             var ret =  await _httpClient.Get<bool>($"Organization/DeleteDept?Id={deptId}");
             return ret;
            
         }
+
+        public async Task<ListApiResponse<Staff>> GetStaffs(Department dept,int _pageIndex,int _pageSize)
+        {
+
+            if (dept == null || dept.Id <= 0)
+            {
+                ListApiResponse<Staff> data = await _httpClient.Get<ListApiResponse<Staff>>($"Staff/Query?pageIndex={_pageIndex}&pageSize={_pageSize}");
+                return data;
+            }
+            else
+            {
+                ListApiResponse<Staff> data = await _httpClient.Get<ListApiResponse<Staff>>($"Staff/QueryInDepartment?deptId={dept.Id}&pageIndex={_pageIndex}&pageSize={_pageSize}");
+                return data;
+            }
+
+        }
+
+        string GetRandomuserParams(QueryModel<Staff> queryModel)
+        {
+            List<string> query = new List<string>()
+        {
+                $"pageSize={queryModel.PageSize}",
+                $"pageIndex={queryModel.PageIndex}",
+            };
+
+            queryModel.SortModel.ForEach(x =>
+            {
+                if (x.Sort != null)
+                {
+                    query.Add($"sortField={x.FieldName.ToLower()}");
+                    query.Add($"sortOrder={x.Sort}");
+                }
+            });
+
+            queryModel.FilterModel.ForEach(filter =>
+            {
+                filter.SelectedValues.ForEach(value =>
+                {
+                    query.Add($"{filter.FieldName.ToLower()}={value}");
+                });
+            });
+
+            return string.Join('&', query);
+        }
+
+        public async Task<ListApiResponse<Staff>> GetStaffs(Department dept, QueryModel<Staff> queryModel)
+        {
+            ListApiResponse<Staff> data = await _httpClient.Get<ListApiResponse<Staff>>($"Staff/Query?DeptId={dept.Id}&" + GetRandomuserParams(queryModel));
+            return data;
+
+        }
+
+        public async Task<List<wispro.sp.entity.StaffGrade>> GetStaffGrades()
+        {
+            var data = await _httpClient.Get<List<wispro.sp.entity.StaffGrade>>($"StaffGrade/GetAll");
+            return data;
+        }
+
+        public async Task<ApiSaveResponse> SaveUser(Department dept,Position position,Staff staff)
+        {
+            SaveUserObject saveUser = new SaveUserObject();
+            saveUser.deptId = dept.Id;
+            saveUser.positionId = position.Id;
+            saveUser.staff = staff;
+            var data =await _httpClient.Post<ApiSaveResponse>("Staff/SaveUser", saveUser);
+
+            return data;
+        }
+
+        public async Task Init()
+        {
+             await _httpClient.Get<ApiSaveResponse>("Staff/Init");
+        }
+
+        public async Task<Position> getPosition(Staff staff, Department editDepartment)
+        {
+            try
+            {
+                var data = await _httpClient.Get<Position>($"Organization/GetPosition?deptId={editDepartment.Id}&staffId={staff.Id}");
+                return data;
+            }
+            catch
+            {
+                return null;
+            }
+        }
     }
+
 }