Browse Source

【物料档案】 基本完成

liangyan0105 3 years ago
parent
commit
ceaa24c207

+ 3 - 0
src/app/routes/basedata/material-file/add/add.component.ts

@@ -102,6 +102,9 @@ export class BasedataMaterialFileAddComponent implements OnInit {
       });
     }
   }
+
+  // 产品 详情
+  detailsPro() {}
   // 关闭
   close() {
     this.modal.destroy();

+ 28 - 30
src/app/routes/basedata/material-file/material-file.component.html

@@ -66,9 +66,7 @@
                 <li nz-menu-item (click)="delMaterial()">
                   {{ 'table.delete' | translate }}
                 </li>
-                <li nz-menu-item (click)="addProduct(e)">
-                  {{ 'button.add' | translate }}{{ 'product' | translate }}
-                </li>
+                <li nz-menu-item (click)="addProduct()">{{ 'button.add' | translate }}{{ 'product' | translate }}</li>
                 <li nz-menu-item (click)="cancel()">{{ 'button.cancel' | translate }}</li>
               </ul>
             </ng-template>
@@ -143,15 +141,18 @@
                 <!-- 属性 -->
                 <th nzAlign="center">{{ 'property' | translate }}</th>
                 <!-- 操作 -->
-                <th nzAlign="center" nzRight="0px">{{ 'table.operation' | translate }}</th>
+                <th nzAlign="center" nzRight="0px">
+                  {{ 'table.operation' | translate }}
+                </th>
               </tr>
             </thead>
+
             <tbody>
               <tr *ngFor="let data of basicTable.data">
                 <td style="width: 8vw" nzAlign="center" nzLeft="0px">{{ data.code }}</td>
                 <td nzAlign="center" nzLeft="8vw">{{ data.name }}</td>
                 <td nzAlign="center">{{ data.sort }}</td>
-                <!-- 状态 0未启用    1启用-->
+                <!-- 状态  0未启用    1启用-->
                 <td nzAlign="center">
                   <ng-container *ngIf="data.status == 0">
                     {{ 'enabled.not' | translate }}
@@ -160,6 +161,7 @@
                     {{ 'enabled' | translate }}
                   </ng-container>
                 </td>
+
                 <!-- 属性  1采购   2销售 -->
                 <td nzAlign="center">
                   <ng-container *ngIf="data.attribute == 1">
@@ -170,32 +172,28 @@
                   </ng-container>
                 </td>
 
-                <!-- 列表操作按钮内 -->
-                <td nzAlign="center" nzRight="0px" style="width: 10%;">
-                  <a href="javascript:void(0);" (click)="openDetailsComponent(data.id)">
-                    {{ 'table.view' | translate }}</a
-                  >
+                <!-- 操作按钮 -->
+                <td nzAlign="center" nzRight="0px" style="width: 20%;">
+                  <!-- 详情 -->
+                  <!-- <a href="javascript:void(0);" (click)="detailsPro(data.id)">
+                    {{ 'table.view' | translate }}
+                  </a>
+                  <nz-divider nzType="vertical"></nz-divider> -->
+                  <!-- 修改 跟新增同一个抽屉-->
+                  <a href="javascript:void(0);" (click)="addProduct(data.id)">
+                    {{ 'table.update' | translate }}
+                  </a>
                   <nz-divider nzType="vertical"></nz-divider>
-                  <nz-dropdown>
-                    <a nz-dropdown>&nbsp;{{ 'hospital.operation.more' | translate }}<i nz-icon type="down"></i> </a>
-                    <ul nz-menu nzSelectable>
-                      <li nz-menu-item>
-                        <a href="javascript:void(0);" (click)="editPersonnel(data.id)">
-                          {{ 'table.update' | translate }}</a
-                        >
-                      </li>
-                      <li nz-menu-item>
-                        <a
-                          nz-popconfirm
-                          nzTitle="{{ 'isdelete' | translate }}"
-                          nzOkText="{{ 'yes' | translate }}"
-                          nzCancelText="{{ 'no' | translate }}"
-                          (nzOnConfirm)="deletePersonnel(data.id)"
-                          >{{ 'table.delete' | translate }}</a
-                        >
-                      </li>
-                    </ul>
-                  </nz-dropdown>
+                  <!-- 删除 -->
+                  <a
+                    nz-popconfirm
+                    nzTitle="{{ 'isdelete' | translate }}"
+                    nzOkText="{{ 'yes' | translate }}"
+                    nzCancelText="{{ 'no' | translate }}"
+                    (nzOnConfirm)="delPro(data.id)"
+                  >
+                    {{ 'table.delete' | translate }}
+                  </a>
                 </td>
               </tr>
             </tbody>

+ 22 - 23
src/app/routes/basedata/material-file/material-file.component.ts

@@ -39,7 +39,7 @@ export class BasedataMaterialFileComponent implements OnInit {
 
   proTable = []; //产品数据
 
-  proId = ''; //点击产品id
+  clickProId = ''; //点击产品id
 
   constructor(
     private drawerService: NzDrawerService,
@@ -52,10 +52,10 @@ export class BasedataMaterialFileComponent implements OnInit {
   ) {}
 
   ngOnInit() {
-    // 初始化显示
+    // 修改初始化的信息
     this.page = {
       pageNo: 1, //当前页码
-      pageSize: 10, //当前页显示的条数
+      pageSize: 6, //当前页显示的条数
     };
     this.getMaterialTree(); //物料分类树
     this.getProductList(); // 产品数据
@@ -82,7 +82,6 @@ export class BasedataMaterialFileComponent implements OnInit {
       this.baseMaterialFileProduct.pkOrg = sessionStorage.getItem('pkOrg'); //组织
       // 根据页面绑定的查询条件进行查询
       this.baseMaterialFileProductService.list(this.baseMaterialFileProduct).then(res => {
-        // console.log(res);
         this.proTable = res.result.records;
         console.log('产品列表', this.proTable);
         resolve();
@@ -141,29 +140,27 @@ export class BasedataMaterialFileComponent implements OnInit {
     });
   }
   //产品 新增、修改 (抽屉)
-  addProduct(id, materialId) {
+  addProduct(id) {
     var title = '';
     //判断是抽屉标题是 新增 还是 修改
     if (id) {
+      //修改
       title = document.getElementById('proTitUpdate').textContent;
-    }
-    if (materialId) {
-      title = document.getElementById('proTitAdd').textContent;
     } else {
-      this.proId = '';
+      //新增
       title = document.getElementById('proTitAdd').textContent;
     }
-
+    // =============================================================
     const drawerAddPro = this.drawerService.create<
       BasedataMaterialFileProductAddComponent,
-      { proId: string; materialId: string },
+      { id: string; materialId: string },
       string
     >({
       nzTitle: title,
       nzWidth: 1200,
       nzContent: BasedataMaterialFileProductAddComponent,
       nzContentParams: {
-        proId: this.proId, //产品id
+        id: id, //页面点击的产品ID 传参给抽屉 修改id
         materialId: this.materialId, //物料分类id (给抽屉的回显树)
       },
     });
@@ -175,19 +172,13 @@ export class BasedataMaterialFileComponent implements OnInit {
         this.getProductList();
       }
     });
+    // ============================================================
   }
   //树节点点击事件
-  treeClick(event) {
-    // console.log('点击节点的内容', event);
-    // var materialObj = event.node.origin; //当前点击的物料对象
-    // console.log(materialObj.parentId);
-    //赋值给修改表单   不用接口回显数据
-    // this.baseMaterialFileClassification = {
-    //   code: materialObj.code,
-    //   name: materialObj.name,
-    //   parentId: materialObj.parentId,
-    //   sort: materialObj.sort,
-    // };
+  treeClick(data) {
+    console.log('点击节点id', data.node.key);
+    this.baseMaterialFileProduct.baseMaterialFileClassificationId = data.node.key;
+    this.getProductList(); // 查询对应产品数据
   }
 
   //按页码查询
@@ -236,6 +227,14 @@ export class BasedataMaterialFileComponent implements OnInit {
       }
     });
   }
+  //删除产品
+  delPro(id) {
+    this.baseMaterialFileProduct.pkOrg = sessionStorage.getItem('pkOrg'); //组织
+    this.baseMaterialFileProductService.deleteMainAndChild(id).then(res => {
+      console.log(res);
+      this.getProductList();
+    });
+  }
   //右键取消
   cancel() {
     this.dropdown.close();

+ 16 - 27
src/app/routes/basedata/material-file/product-add/product-add.component.html

@@ -47,19 +47,16 @@
           [(ngModel)]="baseMaterialFileProduct.status"
           formControlName="status"
         >
-          <!-- 第一条请选择       *ngIf="baseMaterialFileProduct.status == ''"-->
+          <!-- 第一条请选择 -->
           <nz-option nzLabel="{{ 'select.please.choose' | translate }}" nzValue="" selected="selected"></nz-option>
-          <!-- 0未启用, 1 启用 --------------------------------
-              *ngIf="baseMaterialFileProduct.status == '0" 
-              *ngIf="baseMaterialFileProduct.status == '1'"
-            ---------------------------------------------------->
+          <!-- 0 未启用    1启用 --->
           <nz-option nzLabel="{{ 'enabled.not' | translate }}" nzValue="0"></nz-option>
           <nz-option nzLabel="{{ 'enabled' | translate }}" nzValue="1"></nz-option>
         </nz-select>
       </nz-form-control>
     </nz-form-item>
 
-    <!-- 产品属性 分类树-->
+    <!-- 产品属性 分类树 -->
     <nz-form-item>
       <nz-form-label nzRequired [nzSm]="3" [nzXs]="24">{{ 'property' | translate }}</nz-form-label>
       <nz-form-control [nzSm]="8" [nzXs]="12">
@@ -70,18 +67,10 @@
           [(ngModel)]="baseMaterialFileProduct.attribute"
           formControlName="attribute"
         >
-          <nz-option
-            *ngIf="baseMaterialFileProduct.attribute == ''"
-            nzLabel="{{ 'select.please.choose' | translate }}"
-            nzValue=""
-            selected="selected"
-          ></nz-option>
-          <!-- 1采购    2销售----------------------------------
-         *ngIf="baseMaterialFileProduct.attribute == '1"
-         *ngIf="baseMaterialFileProduct.attribute == '2'"
-        ---------------------------------------------------->
-          <nz-option nzLabel="{{ 'procurement' | translate }}" nzValue="0"></nz-option>
-          <nz-option nzLabel="{{ 'sales' | translate }}" nzValue="1"></nz-option>
+          <!-- 1采购    2销售 --->
+          <nz-option nzLabel="{{ 'select.please.choose' | translate }}" nzValue="" selected="selected"></nz-option>
+          <nz-option nzLabel="{{ 'procurement' | translate }}" nzValue="1"></nz-option>
+          <nz-option nzLabel="{{ 'sales' | translate }}" nzValue="2"></nz-option>
         </nz-select>
       </nz-form-control>
 
@@ -142,16 +131,15 @@
               </td>
               <!-- 标准报价 -->
               <td>
-                <!-- <input type="text" [(ngModel)]="data.standardQuotation" nz-input maxlength="20" /> -->
                 <!-- 金额格式 -->
                 <nz-input-number
-                    [(ngModel)]="data.standardQuotation"
-                    [nzMin]="0"
-                    [nzParser]="parserDollar"
-                    [nzFormatter]="formatterDollar"
-                    [nzMax]="100000000000000000"
-                    [nzStep]="10"
-                  ></nz-input-number>
+                  [(ngModel)]="data.standardQuotation"
+                  [nzMin]="0"
+                  [nzParser]="parserDollar"
+                  [nzFormatter]="formatterDollar"
+                  [nzMax]="100000000000000000"
+                  [nzStep]="10"
+                ></nz-input-number>
               </td>
               <td nzAlign="center">
                 <a
@@ -159,7 +147,8 @@
                   nzTitle="{{ 'confirm.to.delete' | translate }}?"
                   nzOkText="{{ 'yes' | translate }}"
                   nzCancelText="{{ 'no' | translate }}"
-                  (nzOnConfirm)="deleteMod(data)">
+                  (nzOnConfirm)="deleteMod(data)"
+                >
                   {{ 'table.delete' | translate }}
                 </a>
               </td>

+ 77 - 83
src/app/routes/basedata/material-file/product-add/product-add.component.ts

@@ -12,7 +12,6 @@ import { messageShared } from '@shared/utils/message';
 import { resolveComponentResources } from '@angular/core/src/metadata/resource_loading';
 import { BaseMaterialFileModularService } from 'app/services/basedata/base-material-file-modular.service';
 import { BaseMaterialFileModular } from 'app/entity/basedata/base-material-file-modular';
-import { log } from 'console';
 
 @Component({
   selector: 'app-basedata-material-file-product-add',
@@ -36,9 +35,10 @@ export class BasedataMaterialFileProductAddComponent implements OnInit {
   materialTree: any = []; //物料分类 (树)
   validateForm!: FormGroup;
   modData: any = []; // 模块列表数据
-  aa: [];
-  id: string; // 模块名称
-
+  // id: string; // 模块名称
+  id: string = ''; //接收抽屉产品 id
+  clickProObj: {}; //点击的产品对象
+  sort = 1; //默认
   //金额格式化 (标准报价)
   formatterDollar = (value: number) => {
     if (value) {
@@ -71,13 +71,35 @@ export class BasedataMaterialFileProductAddComponent implements OnInit {
       attribute: [null, [Validators.required]],
       baseMaterialFileClassificationId: [null, [Validators.required]], //物料分类id
     });
-    // 修改 对象中某属性的值,在此处赋值,接收 抽屉的值
+    // 修改 对象中某属性的值,在此处赋值 (接收 抽屉的值 物料ID)
     this.baseMaterialFileProduct.baseMaterialFileClassificationId = this.materialId;
     this.getMaterialTree(); //物料分类  树
     this.getProductList(); //产品 列表
-    this.getmodList(); //模块列表
-  }
 
+    this.baseMaterialFileProduct.id = this.id;
+    //不是修改
+    if (this.baseMaterialFileProduct.id == '') {
+    } else {
+      //修改 查询对应id 产品 回显
+      return new Promise(resolve => {
+        this.baseMaterialFileProduct.pkOrg = sessionStorage.getItem('pkOrg');
+        this.baseMaterialFileProductService.queryMainAndChildById(this.baseMaterialFileProduct.id).then(res => {
+          console.log('所有产品数据', res);
+          let clickProObj = res.result;
+          this.baseMaterialFileProduct = clickProObj;
+          this.baseMaterialFileProduct.status = this.baseMaterialFileProduct.status + '';
+          if (clickProObj.baseMaterialFileModularList) {
+            // 以下这种写法,只在该方法中赋值,其他地方相互不影响
+            // this.modData =JSON.parse(JSON.stringify(clickProObj.baseMaterialFileModularList))
+            this.modData = clickProObj.baseMaterialFileModularList;
+            this.sort = this.modData.length + 1;
+          }
+          console.log('点击的产品对象', this.baseMaterialFileProduct.baseMaterialFileModularList);
+        });
+        resolve();
+      });
+    }
+  }
   //查询 物料分类 树
   getMaterialTree() {
     return new Promise(resolve => {
@@ -101,79 +123,64 @@ export class BasedataMaterialFileProductAddComponent implements OnInit {
       });
     });
   }
-  //模块列表
-  getmodList() {
-    return new Promise(resolve => {
-      let baseMaterialFileModular = new BaseMaterialFileModular();
-      baseMaterialFileModular.pkOrg = sessionStorage.getItem('pkOrg');
-      this.baseMaterialFileModularService.list(baseMaterialFileModular).then(res => {
-        this.aa = res.result.records;
-        console.log('-->modList', this.aa);
-        resolve();
-      });
-    });
-  }
 
   // 产品 保存(新增/修改)
   proSubForm() {
     //根据标题判断 新增 or 修改
-    // if (this.isOne == 2) {
-    // console.log('000');
-
-    // return new Promise(resolve => {
-    //修改
-    //   this.baseMaterialFileProduct.pkOrg = sessionStorage.getItem('pkOrg'); //组织
-    //   this.baseMaterialFileClassificationService.update(this.baseMaterialFileClassification).then(res => {
-    //     if (res.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, res.message),
-    //       );
-    //     }
-    //   });
-    // });
-    // } else {
-    // 新增
-    // console.log('111');
-    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;
-      console.log('111');
-      if (valid) {
-        console.log('222');
-        console.log('valid有效--->', valid);
+    if (this.id == '') {
+      console.log('空', this.baseMaterialFileProduct);
+      // 新增
+      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.baseMaterialFileProduct.pkOrg = sessionStorage.getItem('pkOrg'); //组织
+          // 保存 模块 数据到对象中
+          this.baseMaterialFileProduct.baseMaterialFileModularList = this.modData;
+          console.log('----->', this.baseMaterialFileProduct.baseMaterialFileModularList);
+          this.baseMaterialFileProductService.saveMainAndChild(this.baseMaterialFileProduct).then(res => {
+            if (res.success) {
+              console.log('out', res);
+              this.baseMaterialFileProduct = res.result;
+              console.log('产品对象>>>>', this.baseMaterialFileProduct);
+              this.getProductList();
+              this.nzNotificationService.success(this.i18NService.fanyi('save.ok'), '');
+              this.nzDrawerRef.close(true); //关闭抽屉是否刷新列表
+            } else {
+              this.nzNotificationService.error(this.i18NService.fanyi('save.not'), '');
+            }
+          });
+          resolve();
+        }
+      });
+    } else {
+      // 修改
+      return new Promise(resolve => {
         this.baseMaterialFileProduct.pkOrg = sessionStorage.getItem('pkOrg'); //组织
-        // 保存 模块 数据到对象中
         this.baseMaterialFileProduct.baseMaterialFileModularList = this.modData;
-        console.log(this.baseMaterialFileProduct.baseMaterialFileModularList);
-        console.log('走这没');
-
-        this.baseMaterialFileProductService.saveMainAndChild(this.baseMaterialFileProduct).then(res => {
+        console.log('----->', this.baseMaterialFileProduct.baseMaterialFileModularList);
+        this.baseMaterialFileProductService.updateMainAndChild(this.baseMaterialFileProduct).then(res => {
           if (res.success) {
-            console.log('out', res);
-            this.baseMaterialFileProduct = res.result;
-            console.log('产品对象>>>>', this.baseMaterialFileProduct);
+            this.clickProObj = res.result;
+            this.notification.success(this.i18NService.fanyi('successful.revision'), '');
             this.getProductList();
-            this.nzNotificationService.success(this.i18NService.fanyi('save.ok'), '');
             this.nzDrawerRef.close(true); //关闭抽屉是否刷新列表
           } else {
-            this.nzNotificationService.error(this.i18NService.fanyi('save.not'), '');
+            this.notification.error(
+              this.i18NService.fanyi('modification.failed'),
+              messageShared(this.i18NService, res.message),
+            );
           }
         });
         resolve();
-      }
-    });
-    // }
+      });
+    }
   }
 
-  sort = 1;
-
   //模块 新增
   addRowMod() {
     this.modData = [
@@ -189,24 +196,11 @@ export class BasedataMaterialFileProductAddComponent implements OnInit {
     this.sort++;
   }
   // 模块 删除按钮
-  deleteMod(data): void {
-    if (data.id == '') {
-      //删除点击项 获取新的模块列表数据
-      this.modData = this.modData.filter(d => d.sort !== data.sort);
-    } else {
-      //修改客户档案时
-      this.baseMaterialFileModularService.delete(data.id).then(response => {
-        if (response.success) {
-          this.notification.success(this.i18NService.fanyi('successful.deletion'), '');
-          this.getmodList();
-        } else {
-          this.notification.error(
-            this.i18NService.fanyi('delete.failed'),
-            messageShared(this.i18NService, response.message),
-          );
-        }
-      });
-    }
+  deleteMod(data) {
+    console.log('模块数据', this.modData);
+
+    //删除点击项 获取新的模块列表数据
+    this.modData = this.modData.filter(d => d.sort !== data.sort);
   }
 
   //树自带方法