瀏覽代碼

【物料档案】分类基本完成 欠右击加当前分类下产品

liangyan0105 3 年之前
父節點
當前提交
630fe08e82

+ 1 - 4
src/app/routes/basedata/material-file/add/add.component.html

@@ -1,12 +1,9 @@
 <!-- 新增物料分类 -->
 <form nz-form [formGroup]="validateForm" (ngSubmit)="submitForm()">
-  <!-- <table>
-    <th style="width: 600px;"></th>
-  </table> -->
   <!-- 物料分类编码 -->
   <nz-form-item>
     <nz-form-label nzRequired [nzSm]="6" [nzXs]="24" nzRequired nzFor="code">
-      {{ 'material.classification.name' | translate }}
+      {{ 'material.classification' | translate }}{{ 'table.thead.code' | translate }}
     </nz-form-label>
     <nz-form-control [nzSm]="14" [nzXs]="24">
       <input

+ 66 - 50
src/app/routes/basedata/material-file/add/add.component.ts

@@ -16,17 +16,18 @@ import { FormBuilder, Validators, FormGroup } from '@angular/forms';
 export class BasedataMaterialFileAddComponent implements OnInit {
   @Input() isOne = 0; //标题
   @Input() materialId = ''; //分类id
-  validateForm!: FormGroup;
-  parentId = ''; //父级id
+
   //初始化 物料分类对象
   baseMaterialFileClassification: BaseMaterialFileClassification = {
-    // id: '',
-    // code: '',
-    // name: '',
-    // parentId: '',
-    // sort:,
+    id: '',
+    code: '',
+    name: '',
+    parentId: '',
+    // sort:'number',
   };
 
+  validateForm!: FormGroup;
+  sort: '';
   constructor(
     private baseMaterialFileClassificationService: BaseMaterialFileClassificationService,
     private notification: NzNotificationService,
@@ -36,58 +37,73 @@ export class BasedataMaterialFileAddComponent implements OnInit {
     private modal: NzModalRef,
   ) {}
 
-  ngOnInit() {
+  ngOnInit(): void {
     //初始化表单
     this.validateForm = this.fb.group({
       code: [null, [Validators.required]], //物料分类编码
       name: [null, [Validators.required]],
       sort: ['number', [Validators.required]], //数字输入框 客商名称排序
     });
-    //新增子集获取父节点id
-    this.baseMaterialFileClassification.parentId = this.parentId;
+    //修改
+    if (this.isOne == 2) {
+      this.getById(); //拿到修改的数据
+    } else {
+      this.baseMaterialFileClassification.parentId = this.materialId;
+      // console.log(this.baseMaterialFileClassification.parentId);
+    }
+    // this.getAllDepart();
+    // this.getProductList();
+  }
+
+  //根据id查询
+  getById() {
+    this.baseMaterialFileClassificationService.getById(this.materialId).then(res => {
+      console.log('点击的物料分类对象', res);
+      this.baseMaterialFileClassification = res.result;
+    });
   }
   //弹框 确定按钮
   submitForm() {
-    // if (this.isOne == 2) {
-    //   //修改
-    //   this.baseMaterialFileClassificationService.update(this.baseMaterialFileClassification).then(respon => {
-    //     if (respon.success) {
-    //       this.notification.success(this.i18NService.fanyi('successful.revision'), '');
-    //       // this.nzDrawerRef.close(true); //参数用于判断关闭抽屉是否刷新树列表
-    //     } else {
-    //       this.notification.error(
-    //         this.i18NService.fanyi('modification.failed'),
-    //         messageShared(this.i18NService, respon.message),
-    //       );
-    //     }
-    //   });
-    // } else {
-    //新增
-    return new Promise(resolve => {
-      for (const i in this.validateForm.controls) {
-        this.validateForm.controls[i].markAsDirty();
-        this.validateForm.controls[i].updateValueAndValidity();
-      }
-      let valid = this.validateForm.valid;
-      if (valid) {
-        console.log('valid有效--->', valid);
-        this.baseMaterialFileClassification.pkOrg = sessionStorage.getItem('pkOrg'); //组织
-        this.baseMaterialFileClassificationService.add(this.baseMaterialFileClassification).then(res => {
-          if (res.success) {
-            //保存成功
-            this.nzNotificationService.success(this.i18NService.fanyi('save.ok'), '');
-            console.log('>>>>', this.baseMaterialFileClassification);
-            // this.validateForm.controls = {}; //清空
-            this.modal.destroy();
-            resolve();
-          } else {
-            //保存失败
-            this.nzNotificationService.error(this.i18NService.fanyi('save.not'), '');
-          }
-        });
-      }
-    });
-    // }
+    //根据标题判断 新增 or 修改
+    if (this.isOne == 2) {
+      //修改
+      this.baseMaterialFileClassificationService.update(this.baseMaterialFileClassification).then(res => {
+        if (res.success) {
+          this.notification.success(this.i18NService.fanyi('successful.revision'), '');
+          this.modal.destroy();
+        } else {
+          this.notification.error(
+            this.i18NService.fanyi('modification.failed'),
+            messageShared(this.i18NService, res.message),
+          );
+        }
+      });
+    } else {
+      //新增
+      return new Promise(resolve => {
+        for (const i in this.validateForm.controls) {
+          this.validateForm.controls[i].markAsDirty();
+          this.validateForm.controls[i].updateValueAndValidity();
+        }
+        let valid = this.validateForm.valid;
+        if (valid) {
+          console.log('valid有效--->', valid);
+          this.baseMaterialFileClassification.pkOrg = sessionStorage.getItem('pkOrg'); //组织
+          this.baseMaterialFileClassificationService.add(this.baseMaterialFileClassification).then(res => {
+            if (res.success) {
+              //保存成功
+              this.nzNotificationService.success(this.i18NService.fanyi('save.ok'), '');
+              console.log('>>>>', this.baseMaterialFileClassification);
+              this.modal.destroy();
+              resolve();
+            } else {
+              //保存失败
+              this.nzNotificationService.error(this.i18NService.fanyi('save.not'), '');
+            }
+          });
+        }
+      });
+    }
   }
   // 关闭
   close() {

+ 8 - 4
src/app/routes/basedata/material-file/material-file.component.html

@@ -1,10 +1,14 @@
 <!-- 头部导航 -->
 <page-header [action]="phActionTpl">
   <ng-template #phActionTpl>
+    <!-- 新增物料分类弹框 标题 -->
     <span id="materialTitAdd" hidden="true">
       {{ 'button.add' | translate }}{{ 'material.classification' | translate }}
     </span>
-    <span id="materialTitUpdate" hidden="true">{{ 'table.update' | translate }}{{ 'personnel' | translate }}</span>
+    <!-- 修改物料分类 标题 -->
+    <span id="materialTitUpdate" hidden="true">
+      {{ 'table.update' | translate }}{{ 'material.classification' | translate }}
+    </span>
     <button nz-button nzType="primary" (click)="editProduct('')">
       {{ 'button.add' | translate }}{{ 'product' | translate }}
     </button>
@@ -44,7 +48,7 @@
             [nzData]="materialNodes"
             [nzSearchValue]="searchValue"
             (nzClick)="treeClick($event)"
-            (nzDblClick)="(openFolder)"
+            (nzDblClick)="openFolder($event)"
           >
             <!-- 树 动态数据 -->
 
@@ -61,10 +65,10 @@
             <ng-template #nzTreeTemplate let-node>
               <span class="custom-node">
                 <span *ngIf="!node.isLeaf" (contextmenu)="contextMenu(node.key, $event, contextTemplate)">
-                  <span class="folder-name">{{ node.name }}</span>
+                  <span class="folder-name">{{ node.title }}</span>
                 </span>
                 <span *ngIf="node.isLeaf" (contextmenu)="contextMenu(node.key, $event, contextTemplate)">
-                  <span class="file-name">{{ node.name }}</span>
+                  <span class="file-name">{{ node.title }}</span>
                 </span>
               </span>
             </ng-template>

+ 83 - 123
src/app/routes/basedata/material-file/material-file.component.ts

@@ -1,4 +1,4 @@
-import { Component, OnInit, ViewChild } from '@angular/core';
+import { Component, OnInit, TemplateRef, ViewChild } from '@angular/core';
 import { _HttpClient, ModalHelper } from '@delon/theme';
 import {
   NzDrawerService,
@@ -44,25 +44,34 @@ export class BasedataMaterialFileComponent implements OnInit {
     private message: NzMessageService,
     private i18NService: I18NService,
     private modalService: NzModalService,
+    private nzDropdownService: NzDropdownService,
   ) {}
 
   ngOnInit() {
-    this.getMaterialTree();
+    this.getProductList(); // 产品生育金
+    //客商行业数 树
+    this.getMaterialTree(); //物料分类树
+
+    // 物料分类
     this.baseMaterialFileClassification = {
-      id: '', //编码
-      code: '', //名称
-      name: '', // 父级id
+      id: '',
+      code: '',
+      name: '',
       parentId: '',
-      sort: 0, //排序
+      sort: 0,
       key: '', //用于tree id
       title: '', //name
       isLeaf: false, //是否尾端true/false
       children: [], //子集
     };
+
+    // 页码
     this.page = {
       pageNo: 0, //当前页码
       pageSize: 6, //当前页显示的条数
     };
+
+    //产品
     this.product = {
       code: '',
       name: '',
@@ -92,10 +101,55 @@ export class BasedataMaterialFileComponent implements OnInit {
     this.baseMaterialFileProductService.list(this.product).then(reponse => {
       this.proListData = reponse.result.records;
       this.productPage = reponse.result;
-      console.log(' this.productPage:', this.productPage);
+      // console.log(' this.productPage:', this.productPage);
       this.isSpinning = false;
     });
   }
+
+  //添加一级、右键添加分类分类、修改
+  addMaterial(isOne: number) {
+    var title = '';
+    if (isOne == 0) {
+      //新增一级
+      this.materialId = '';
+      title = document.getElementById('materialTitAdd').textContent;
+    } else if (isOne == 1) {
+      //新增 某分级 下的产品
+      title = document.getElementById('materialTitAdd').textContent;
+    } else {
+      //修改
+      title = document.getElementById('materialTitUpdate').textContent;
+    }
+    //打开弹框
+    const modalRef = this.modalService.create({
+      nzTitle: title,
+      nzContent: BasedataMaterialFileAddComponent,
+      nzWidth: 800,
+      //对话框传参
+      nzComponentParams: {
+        isOne: isOne,
+        materialId: this.materialId, //物料分类id
+      },
+      nzFooter: [
+        {
+          label: '关闭',
+          type: 'default',
+          onClick: addModel => {
+            addModel.close();
+          },
+        },
+        {
+          label: '确定',
+          type: 'primary',
+          onClick: addModel => {
+            addModel.submitForm();
+            this.getMaterialTree();
+            this.getProductList();
+          },
+        },
+      ],
+    });
+  }
   //按页码查询
   pageIndexChange(event) {
     // var page = new Page();
@@ -114,19 +168,16 @@ export class BasedataMaterialFileComponent implements OnInit {
   }
   //树节点点击事件
   treeClick(event) {
-    console.log('点击节点的内容', event);
-    var getMaterialId = event.node.origin; //当前点击的物料对象
-    console.log(getMaterialId.parentId);
-
+    // console.log('点击节点的内容', event);
+    var materialObj = event.node.origin; //当前点击的物料对象
+    // console.log(materialObj.parentId);
     //赋值给修改表单
     this.baseMaterialFileClassification = {
-      code: getMaterialId.code,
-      name: getMaterialId.name,
-      // id: getMaterialId.key,
-      parentId: getMaterialId.parentId,
-      sort: getMaterialId.sort,
+      code: materialObj.code,
+      name: materialObj.name,
+      parentId: materialObj.parentId,
+      sort: materialObj.sort,
     };
-    
   }
 
   //双击节点自动打开树分支
@@ -140,128 +191,37 @@ export class BasedataMaterialFileComponent implements OnInit {
       const node = data.node;
       if (node) {
         node.isExpanded = !node.isExpanded;
-        console.log('11', node);
-        console.log('22', node.isExpanded);
+        // console.log('11', node);
+        // console.log('22', node.isExpanded);
       }
     }
   }
 
-  //添加一级 弹框
-  addMaterial() {
-    const modalRef = this.modalService.create({
-      nzTitle: '新增物料分类',
-      nzContent: BasedataMaterialFileAddComponent,
-      nzWidth: 800,
-      nzFooter: [
-        {
-          label: '关闭',
-          type: 'default',
-          onClick: addModel => {
-            addModel.close();
-          },
-        },
-        {
-          label: '确定',
-          type: 'primary',
-          onClick: addModel => {
-            addModel.submitForm().then(() => {
-              console.log('000');
-              this.getMaterialTree(); //新增后刷新 树
-              console.log('1111');
-            });
-          },
-        },
-      ],
-    });
+  //右键树节点
+  contextMenu(Fid, $event: MouseEvent, template: TemplateRef<void>): void {
+    this.materialId = Fid;
+    this.dropdown = this.nzDropdownService.create($event, template);
+    // console.log('右击对象', this.dropdown);
   }
-  //添加一级、右键添加分类分类、修改
-  // addMaterial(isOne: number) {
-  //   var title = '';
-  //   if (isOne == 0) {
-  //     //新增一级
-  //     this.materialId = '';
-  //     title = document.getElementById('materialTitAdd').textContent;
-  //   } else if (isOne == 1) {
-  //     //新增 某分级 下的产品
-  //     title = document.getElementById('materialTitAdd').textContent;
-  //   } else {
-  //     //修改
-  //     title = document.getElementById('materialTitUpdate').textContent;
-  //   }
 
-  //   //打开抽屉
-  //   const drawerAddMaterialy = this.drawerService.create<
-  //     BasedataMaterialFileAddComponent,
-  //     { isOne: number; materialId: string },
-  //     string
-  //   >({
-  //     nzTitle: title,
-  //     nzWidth: '800',
-  //     nzContent: BasedataMaterialFileAddComponent,
-  //     nzContentParams: {
-  //       isOne: isOne,
-  //       materialId: this.materialId, //产品id
-  //     },
-  //   });
-  //   //回调 添加完关闭抽屉
-  //   drawerAddMaterialy.afterClose.subscribe(clo => {
-  //     if (clo) {
-  //       //判断是否刷新树列表数据
-  //       this.getMaterialTree()
-  //       this.getProductList();
-  //     }
-  //   });
-  //   // this.dropdown.close();
-  // }
-  //右键删除
-  deleteDepart() {
-    this.baseMaterialFileClassificationService.delete(this.materialId).then(res => {
-      if (res.success) {
+  //修改产品
+  editProduct() {}
+  //右击删除
+  delMaterial() {
+    this.baseMaterialFileClassificationService.delete(this.materialId).then(response => {
+      if (response.success) {
         this.message.success(this.i18NService.fanyi('successful.deletion'));
         this.getMaterialTree();
         this.getProductList();
+        this.dropdown.close();
+        //弹框消失
       } else {
         this.message.error(this.i18NService.fanyi('delete.failed'));
       }
     });
-    // this.dropdown.close();
   }
-  editProduct() {
-    //抽屉title
-    // var title = '';
-    // if (id == '') {
-    //   title = document.getElementById('titleAdd').textContent;
-    // } else {
-    //   title = document.getElementById('titleUpdate').textContent;
-    // }
-    // //打开抽屉
-    // const drawerAddMaterialy = this.drawerService.create<BasedataMaterialFileAddComponent, { id: string }, string>({
-    //   nzTitle: title,
-    //   nzWidth: 1200,
-    //   nzContent: BasedataMaterialFileAddComponent,
-    //   nzContentParams: {
-    //     id: id,
-    //   },
-    // });
-    // //回调 添加完关闭抽屉
-    // drawerAddMaterialy.afterClose.subscribe(clo => {
-    //   if (clo) {
-    //     //判断是否刷新树列表数据
-    //     this.getProductList();
-    //   }
-    // });
-  }
-  //右击修改
-  updateMaterial() {}
-  //右击删除
-  delMaterial() {}
   //右键取消
   cancel() {
     this.dropdown.close();
   }
-  add() {
-    // this.modal
-    //   .createStatic(FormEditComponent, { i: { id: 0 } })
-    //   .subscribe(() => this.st.reload());
-  }
 }