Bläddra i källkod

修改优化8-6

cehn 7 månader sedan
förälder
incheckning
7b5fbb8d9a

+ 43 - 9
projects/textbook/src/modules/nav-admin/user-edit/user-edit.component.html

@@ -391,10 +391,13 @@
           [nzColor]="'#efefef'"
           >{{ userDataJson.companyType }}</nz-tag
         >
-        /
-        <nz-tag [nzBordered]="false" [nzColor]="'geekblue'">{{
-          userDataJson.department?.get("name")
-        }}</nz-tag>
+        @for (item of userDataJson.node; track $index) {
+          @if($index > 0){
+            /<nz-tag [nzBordered]="false" [nzColor]="'geekblue'">{{
+              item.title
+            }}</nz-tag>
+          }
+        }
         }@else { 待选择 }
       </div>
       <!-- <div class="title">所属组织部门</div>
@@ -462,8 +465,8 @@
           <div class="value">
             <input
               nz-input
-              [ngModel]="userDataJson.department?.get('name')"
-              (ngModelChange)="provinceChange(parent, $event)"
+              [ngModel]="depTitle"
+              (ngModelChange)="getDepart(userDataJson.department?.id, $event)"
               placeholder="搜索或选择一个下方部门"
               type="text"
             />
@@ -471,6 +474,20 @@
         </div>
         <div class="select">
           <div class="bar">
+            @if (this.tbookSer.profile.identity == '国家级管理员') {
+            <a style="color: #86909c" (click)="onPre()">所有部门</a>
+            }@else {
+            <a style="color: #86909c">所有部门</a>
+            } @for (data of parentMap; track data.title) {
+            <span style="margin: 0 10px">/</span>
+            @if (this.tbookSer.profile.identity == '国家级管理员' ||
+            data?.verify) {
+            <a (click)="onPre(data, $index)">{{ data.title }}</a>
+            }@else {
+            <a style="color: #86909c">{{ data.title }}</a>
+            } }
+          </div>
+          <!-- <div class="bar">
             <a style="color: #86909c">所有部门</a>
             @for (data of parentMap; track data.title) {
             <span style="margin: 0 10px">/</span>
@@ -482,9 +499,26 @@
             } }@else {
             <a style="color: #86909c">{{ data.title }}</a>
             } }
-          </div>
+          </div> -->
           <div class="tree">
-            @for (data of parentList; track $index) {
+            @if(parentList.length > 0){ @for (data of parentList; track $index)
+              {
+              <div class="li" (click)="onCheckedDepart(data)">
+                <label
+                  nz-radio
+                  [ngModel]="data.key == radio"
+                  [nzValue]="data.key"
+                  (click)="onCheckedDepart(data, true)"
+                  >{{ data.title }}</label
+                >
+                @if (!data.isLeaf) {
+                <span nz-icon nzType="right" nzTheme="outline"></span>
+                }
+              </div>
+              } }@else {
+              <nz-empty nzNotFoundContent="暂无下级部门"></nz-empty>
+              }
+            <!-- @for (data of parentList; track $index) {
             <div class="li" (click)="onCheckedDepart(data)">
               <label
                 nz-radio
@@ -497,7 +531,7 @@
               <span nz-icon nzType="right" nzTheme="outline"></span>
               }
             </div>
-            }
+            } -->
           </div>
         </div>
       </div>

+ 151 - 62
projects/textbook/src/modules/nav-admin/user-edit/user-edit.component.ts

@@ -83,6 +83,8 @@ export class UserEditComponent implements OnInit {
   };
   userType: Array<string> = ['教师', '评审专家', '高校联系人', '工作联系人'];
   provinces: Array<string> = provinces.options; //省份
+  depTitle:string = '' //关联部门标题
+  radio:string = ''
 
   constructor(
     public tbookSer: textbookServer,
@@ -116,10 +118,15 @@ export class UserEditComponent implements OnInit {
         queryProfile.equalTo('user', id);
         this.profile = await queryProfile.first();
         this.profileJson = this.profile.toJSON();
-        this.userJson.email = this.profileJson.email
+        this.userJson.email = this.profileJson.email;
         this.userDataJson = {
           companyType: this.profile?.get('companyType'),
-          department: this.user.get('department'),
+          department: {
+            id: this.user.get('department')?.id,
+            name: this.user.get('department')?.get('name'),
+            branch: this.user.get('department')?.get('branch'),
+          },
+          node: await this.tbookSer.formatNode(this.user.get('department')?.id),
         };
       }
       await this.getUnitTypes();
@@ -130,9 +137,12 @@ export class UserEditComponent implements OnInit {
         this.tbookSer.profile.identity == '工作联系人' &&
         arr.includes(this.profile.get('identity'))
       ) {
-        if(this.tbookSer.profile.companyType == '省级教育行政部门' || this.tbookSer.profile.companyType == '有关部门(单位)教育司(局)'){
+        if (
+          this.tbookSer.profile.companyType == '省级教育行政部门' ||
+          this.tbookSer.profile.companyType == '有关部门(单位)教育司(局)'
+        ) {
           this.userType = ['教师', '评审专家', '高校联系人'];
-        }else{
+        } else {
           this.userType = ['教师', '评审专家'];
         }
         this.edit = true;
@@ -189,7 +199,7 @@ export class UserEditComponent implements OnInit {
           case '删除':
             await this.profile.destroy();
             await this.user.destroy();
-            this.goUserList()
+            this.goUserList();
             break;
         }
         this.ngOnInit();
@@ -220,6 +230,8 @@ export class UserEditComponent implements OnInit {
   //切换单位类型
   onChangeType() {
     this.userDataJson.department = null;
+    this.depTitle = ''
+    this.radio = ''
   }
   //选择部门
   async showModalDepart() {
@@ -227,16 +239,23 @@ export class UserEditComponent implements OnInit {
       this.message.warning('同级身份暂无权限操作');
       return;
     }
+    this.depTitle = this.userDataJson.department.name
+    this.radio = this.userDataJson.department.id
     if (this.unitTypes.length == 0) {
       await this.getUnitTypes();
     }
-    let parent = this.unitTypes.find(
-      (item) => item.name == this.userDataJson.companyType
+    this.parentMap = await this.tbookSer.formatNode(this.user?.get('department')?.id);
+    let index = this.parentMap.findIndex(
+      (item) => this.tbookSer.profile.user.department?.objectId == item.key
     );
-    if (parent?.id) {
-      this.parentMap = await this.formatNode(parent.id);
+    if (index != -1) {
+      this.parentMap.forEach((item, i) => {
+        if (i >= index) {
+          this.parentMap[i].verify = true;
+        }
+      });
     }
-    this.provinceChange(this.parentMap[this.parentMap.length - 1]?.id);
+    this.getDepart(this.parentMap[this.parentMap.length - 1]?.id);
     this.isShowModal = true;
   }
   async getUnitTypes() {
@@ -251,81 +270,144 @@ export class UserEditComponent implements OnInit {
     });
   }
   //根据所选单位类型获取对应单位
-  async provinceChange(id?: string, val?: string) {
+  async getDepart(parent?: string, val?: string) {
     let query = new Parse.Query('Department');
-    query.select('name', 'branch', 'parent');
-    if (this.tbookSer.profile.identity != '国家级管理员') {
-      query.equalTo(
-        'objectId',
-        this.tbookSer.profile?.user.department?.objectId
-      );
-    }
-    if (this.tbookSer.profile.identity == '国家级管理员' || id) {
-      query.equalTo('parent', id ? id : null);
-    }
+    query.equalTo(
+      'parent',
+      val
+        ? this.parentMap[this.parentMap.length - 1]?.key
+        : parent
+        ? parent
+        : this.tbookSer.profile.identity != '国家级管理员'
+        ? this.tbookSer.profile.user.department?.objectId
+        : null
+    );
+    query.select('code', 'name', 'branch', 'parent', 'type', 'hasChildren');
     query.limit(100);
+    query.descending('createdAt');
+    query.notEqualTo('isDeleted', true);
     val && query.contains('name', val);
-    let r = await query.find();
-    this.parentList = r;
-  }
-
-  async formatNode(id: string): Promise<Array<any>> {
-    let arr = [];
-    if (id) {
-      let query = new Parse.Query('Department');
-      query.equalTo('objectId', id);
-      query.select('parent', 'name');
-      let r = await query.first();
-      arr.push({
-        title: r?.get('name'),
-        id: r?.id,
+    let res = await query.find();
+    let nodes: any = [];
+    res.forEach((item) => {
+      nodes.push({
+        title: item.get('name'),
+        key: item.id,
+        id: item.id,
+        branch: item.get('branch'),
+        parent: item.get('parent')?.id, //上级
+        isLeaf: !item.get('hasChildren'), //是否是最下级
+        type: item.get('type'),
       });
-      if (r?.get('parent')) {
-        arr.unshift(...(await this.formatNode(r?.get('parent')?.id)));
-      }
-    }
-    return arr;
+    });
+    this.parentList = nodes;
   }
-  onCheck(e: any) {
-    console.log(e);
+  async onPre(data?: any, index?: number) {
+    if (!data) {
+      this.userDataJson.department = undefined;
+      this.depTitle = ''
+      this.radio = ''
+      await this.getDepart();
+      this.parentMap = [];
+      return;
+    }
+    if (index == this.parentMap.length - 1) {
+      if (this.parentList.length == 0) await this.getDepart(data?.key);
+      return;
+    }
+    this.parentMap.splice((index || 0) + 1);
     this.userDataJson.department = undefined;
-    this.provinceChange();
+    this.depTitle = ''
+    this.radio = ''
+    await this.getDepart(data?.key);
   }
-  parent: string = ''; //搜索时传入的id
   //选择部门
-  async onCheckedDepart(e: any) {
-    console.log(e);
-    if (e?.get('parent')?.id) {
-      this.userDataJson.department = e;
-      this.parent = e?.get('parent')?.id;
-    } else {
-      this.provinceChange(e.id);
-      this.parent = e?.id;
+  async onCheckedDepart(e: any, checked?: boolean) {
+    console.log(e, checked);
+    this.userDataJson.department = null;
+    this.depTitle = ''
+    this.parentMap = await this.tbookSer.formatNode(e.id);
+    if (this.tbookSer.profile.identity != '国家级管理员') {
+      let index = this.parentMap.findIndex(
+        (item) => this.tbookSer.profile.user.department?.objectId == item.key
+      );
+      if (index != -1) {
+        this.parentMap.forEach((item, i) => {
+          if (i >= index) {
+            this.parentMap[i].verify = true;
+          }
+        });
+      }
+    }
+    if (checked && e.branch) {
+      this.pushValue(e);
+      return
+    }
+    if (e.isLeaf) {
+      return;
+    }
+    this.radio = ''
+    await this.getDepart(e?.key);
+  }
+  pushValue(e: any) {
+    this.userDataJson.department = {
+      name: e.title,
+      branch: e.branch,
+      title: e.title,
+      id: e.key,
+    };
+    this.depTitle = e.title
+    console.log(this.depTitle);
+    this.radio = e.key
+    if (this.tbookSer.profile.identity == '国家级管理员') {
+      this.userType = this.unitTypes.some((item) => e.parent == item.id)
+        ? !e.type
+          ? ['工作联系人']
+          : ['评审专家', '工作联系人', '教师']
+        : e.type == '单位'
+        ? ['评审专家', '高校联系人', '教师']
+        : ['评审专家', '教师'];
+    } else if (this.tbookSer.profile.identity == '工作联系人') {
+      this.userType = this.unitTypes.some((item) => e.parent == item.id)
+        ? !e.type
+          ? ['评审专家', '教师', '高校联系人']
+          : ['评审专家', '教师']
+        : e.type == '单位'
+        ? ['评审专家', '高校联系人', '教师']
+        : ['评审专家', '教师'];
     }
-    this.parentMap = await this.formatNode(e.id);
   }
-  handleCancel(): void {
-    console.log('Button cancel clicked!');
+
+  async handleCancel() {
     this.userDataJson = {
       companyType: this.profile?.get('companyType'),
-      department: this.user.get('department'),
+      department: {
+        id: this.user.get('department')?.id,
+        name: this.user.get('department')?.get('name'),
+        branch: this.user.get('department')?.get('branch'),
+      },
+      node: await this.tbookSer.formatNode(this.user.get('department')?.id),
     };
+    this.depTitle = ''
+    this.radio = ''
     this.isShowModal = false;
-    this.parent = '';
   }
   async completeChange(): Promise<void> {
     if (!this.userDataJson.department?.id) {
       this.message.warning('请选择部门');
       return;
     }
-    this.userDataJson.companyType = this.userDataJson.department.get('branch');
+    this.userDataJson.companyType = this.userDataJson.department?.branch;
     this.profile?.set('companyType', this.userDataJson.companyType);
     await this.profile?.save();
-    this.user?.set('department', this.userDataJson.department?.toPointer());
+    this.user?.set('department', {
+      __type: 'Pointer',
+      className: 'Department',
+      objectId: this.userDataJson.department?.id,
+    });
     await this.user?.save();
     this.ngOnInit();
     this.isShowModal = false;
-    this.parent = '';
   }
   openUrl(url: string) {
     if (!/\.(jpg|jpeg|png|GIF|JPG|PNG)$/.test(url)) {
@@ -344,7 +426,7 @@ export class UserEditComponent implements OnInit {
   }
   /* 修改账号 */
   loading: boolean = false;
-  submitForm(type: string) {
+  async submitForm(type: string) {
     if (this.loading) return;
     this.loading = true;
     if (type == 'save') {
@@ -354,8 +436,15 @@ export class UserEditComponent implements OnInit {
       this.profileJson = this.profile.toJSON();
       this.userDataJson = {
         companyType: this.profile?.get('companyType'),
-        department: this.user.get('department'),
+        department: {
+          id: this.user.get('department')?.id,
+          name: this.user.get('department')?.get('name'),
+          branch: this.user.get('department')?.get('branch'),
+        },
+        node: await this.tbookSer.formatNode(this.user.get('department')?.id),
       };
+      this.depTitle = this.user.get('department')?.get('name')
+      this.radio = this.user.get('department')?.id
       this.loading = false;
     }
   }

+ 2 - 3
projects/textbook/src/modules/nav-author/components/create/basic/basic.component.ts

@@ -211,12 +211,12 @@ export class BasicComponent implements OnInit {
   async autoCompleteByISBN() {
     let isbn = this.validateForm.value?.ISBN;
     let result = await Parse.Cloud.run("tbookISBN", {
-      isbn: isbn
+      isbn: String(isbn)
     })
     if (!result?.isbn) {
       this.msg.warning('未找到该书号的图书信息,请手动填写')
     }
-
+    console.log(result)
     // 其他字段,需补充接口与数据库对应关系
     this.validateForm.get("author")?.setValue(result?.author_name)
     this.validateForm.get("authors")?.setValue(result?.author)
@@ -224,7 +224,6 @@ export class BasicComponent implements OnInit {
     this.validateForm.get("editionUnit")?.setValue(result?.publisher)
     this.validateForm.get("editionDate")?.setValue(new Date(result?.publish_time))
     this.validateForm.get("carrierShape")?.setValue(result?.publication_class)
-    console.log(result)
   }
   /**出版时间及版次不可选择时间 */
   disabledEditionDate = (current: Date): boolean => {

+ 1 - 0
projects/textbook/src/services/textbook.ts

@@ -58,6 +58,7 @@ export class textbookServer {
   }
   //格式化链
   async formatNode(id: string): Promise<Array<any>> {
+    if(!id) return []
     let query = new Parse.Query('Department');
     query.select('name', 'parent', 'hasChildren', 'type', 'branch');
     let r = await query.get(id);