Browse Source

小东西

liangyan0105 3 years ago
parent
commit
6228c5edda

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

@@ -160,7 +160,7 @@ export class BasedataMaterialFileComponent implements OnInit {
       nzWidth: 1200,
       nzContent: BasedataMaterialFileProductAddComponent,
       nzContentParams: {
-        id: id, //页面点击的产品ID 传参给抽屉 修改id
+        id: id, //页面点击的产品ID 传参给抽屉 
         materialId: this.materialId, //物料分类id (给抽屉的回显树)
       },
     });

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

@@ -39,7 +39,7 @@
         />
       </nz-form-control>
 
-      <!--  状态0 未启用    1启用  -->
+      <!--  状态   0未启用    1启用  -->
       <nz-form-label nzRequired [nzSm]="3" [nzXs]="24">
        {{'depart.Whether.to.enable' | translate}}
       </nz-form-label>
@@ -54,21 +54,6 @@
         >
         </nz-switch>
       </nz-form-control>
-      <!-- <nz-form-label nzRequired [nzSm]="3" [nzXs]="24">{{ 'state' | translate }}</nz-form-label> -->
-      <!-- <nz-form-control [nzSm]="8" [nzXs]="12">
-        <nz-select
-          nzShowSearch
-          nzPlaceHolder="{{ 'select.please.choose' | translate }}"
-          [nzDisabled]="false"
-          [(ngModel)]="baseMaterialFileProduct.status"
-          formControlName="status"
-        > -->
-      <!-- 第一条请选择 -->
-      <!-- <nz-option nzLabel="{{ 'select.please.choose' | translate }}" nzValue="" selected="selected"></nz-option>
-          <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>
 
     <!-- 产品属性 分类树 -->

+ 53 - 54
src/app/routes/basedata/material-file/product-add/product-add.component.ts

@@ -23,9 +23,9 @@ export class BasedataMaterialFileProductAddComponent implements OnInit {
   baseMaterialFileProduct: BaseMaterialFileProduct = {}; //产品对象
   baseMaterialFileModular: BaseMaterialFileModular = {}; //模块 对象
 
-  isOne = 0; //标题
+  isOne = 0; //标题判断
   page: Page = {}; //分页对象
-  materialId: string = ''; //接收抽屉的物料id (在产品中回显所属物料分类)
+  materialId: string = ''; //接收抽屉的物料id (产品抽屉回显所属物料分类)
 
   proTable = []; //产品数据
   productPage = {
@@ -35,11 +35,11 @@ export class BasedataMaterialFileProductAddComponent implements OnInit {
   materialTree: any = []; //物料分类 (树)
   validateForm!: FormGroup;
   modData: any = []; // 模块列表数据
-  // id: string; // 模块名称
+
   id: string = ''; //接收抽屉产品 id
   clickProObj: {}; //点击的产品对象
   sort = 1; //默认
-  status = false; //未启用
+  status = true; //默认产品初始状态是启用
   //金额格式化 (标准报价)
   formatterDollar = (value: number) => {
     if (value) {
@@ -48,7 +48,6 @@ export class BasedataMaterialFileProductAddComponent implements OnInit {
       return `$ `;
     }
   };
-
   parserDollar = (value: string) => value.replace('$ ', '');
 
   constructor(
@@ -67,37 +66,35 @@ export class BasedataMaterialFileProductAddComponent implements OnInit {
     this.validateForm = this.fb.group({
       code: [null, [Validators.required]],
       name: [null, [Validators.required]],
-      sort: ['number', [Validators.required]], //排序
+      sort: ['number', [Validators.required]],
       status: [], //不验证
       attribute: [null, [Validators.required]],
-      baseMaterialFileClassificationId: [null, [Validators.required]], //物料分类id
+      baseMaterialFileClassificationId: [null, [Validators.required]],
     });
     // 修改 对象中某属性的值,在此处赋值 (接收 抽屉的值 物料ID)
     this.baseMaterialFileProduct.baseMaterialFileClassificationId = this.materialId;
-    this.getMaterialTree(); //物料分类  树
+    this.getMaterialTree(); //物料 分类  树
     this.getProductList(); //产品 列表
 
-    this.baseMaterialFileProduct.id = this.id;
-    //不是修改
-    if (!this.id) {
-    } else {
-      //修改 查询对应id 产品 回显
+    this.baseMaterialFileProduct.id = this.id; //全局变量点击产品项ID赋值给产品ID
+    //根据ID 查询产品
+    if (this.baseMaterialFileProduct.id) {
       return new Promise(resolve => {
         this.baseMaterialFileProduct.pkOrg = sessionStorage.getItem('pkOrg');
         this.baseMaterialFileProductService.queryMainAndChildById(this.baseMaterialFileProduct.id).then(res => {
           this.baseMaterialFileProduct = res.result;
           console.log('点击的产品数据', this.baseMaterialFileProduct);
+          //回显产品状态
           if (this.baseMaterialFileProduct.status == '0') {
             this.status = false; //未启用
           } else {
             this.status = true;
           }
-
           this.baseMaterialFileProduct.status = this.baseMaterialFileProduct.status + '';
           if (this.baseMaterialFileProduct.baseMaterialFileModularList) {
             // 以下这种写法,只在该方法中赋值,其他地方相互不影响
             // this.modData =JSON.parse(JSON.stringify(clickProObj.baseMaterialFileModularList))
-            this.modData = this.baseMaterialFileProduct.baseMaterialFileModularList;
+            this.modData = this.baseMaterialFileProduct.baseMaterialFileModularList; //模块列表
             this.sort = this.modData.length + 1;
           }
           console.log('模块列表', this.baseMaterialFileProduct.baseMaterialFileModularList);
@@ -106,41 +103,19 @@ export class BasedataMaterialFileProductAddComponent implements OnInit {
       });
     }
   }
-  //查询 物料分类 树
-  getMaterialTree() {
-    return new Promise(resolve => {
-      let baseMaterialFileClassification = new BaseMaterialFileClassification();
-      baseMaterialFileClassification.pkOrg = sessionStorage.getItem('pkOrg'); //组织
-      this.baseMaterialFileClassificationService.getTreeList(baseMaterialFileClassification).then(res => {
-        this.materialTree = res.result;
-        console.log('物料分类 树', this.materialTree);
-        resolve();
-      });
-    });
-  }
-  //查询产品 列表
-  getProductList() {
-    return new Promise(resolve => {
-      var page = new Page();
-      page.pageSize = 500;
-      this.baseMaterialFileProductService.list(page).then(response => {
-        this.proTable = response.result.records;
-        resolve();
-      });
-    });
-  }
 
   // 产品 保存(新增/修改)
   proSubForm() {
     if (this.status) {
-      this.baseMaterialFileProduct.status = '0';
-    } else {
+      //是否启用
       this.baseMaterialFileProduct.status = '1';
+      console.log('what');
+    } else {
+      this.baseMaterialFileProduct.status = '0';
     }
-    //根据标题判断 新增 or 修改
+    //无点击的 ID--->新增
     if (this.id == '') {
-      console.log('空', this.baseMaterialFileProduct);
-      // 新增
+      console.log('新增产品', this.baseMaterialFileProduct);
       return new Promise(resolve => {
         for (const i in this.validateForm.controls) {
           this.validateForm.controls[i].markAsDirty();
@@ -148,16 +123,16 @@ export class BasedataMaterialFileProductAddComponent implements OnInit {
         }
         let valid = this.validateForm.valid;
         if (valid) {
-          console.log('valid有效--->', valid);
-          this.baseMaterialFileProduct.pkOrg = sessionStorage.getItem('pkOrg'); //组织
+          // console.log('valid有效--->', valid);
+          this.baseMaterialFileProduct.pkOrg = sessionStorage.getItem('pkOrg');
           // 保存 模块 数据到对象中
           this.baseMaterialFileProduct.baseMaterialFileModularList = this.modData;
-          console.log('----->', this.baseMaterialFileProduct.baseMaterialFileModularList);
+          console.log('新增保存的模块列表', this.baseMaterialFileProduct.baseMaterialFileModularList);
           this.baseMaterialFileProductService.saveMainAndChild(this.baseMaterialFileProduct).then(res => {
             if (res.success) {
-              console.log('out', res);
+              // console.log('out', res);
               this.baseMaterialFileProduct = res.result;
-              console.log('产品对象>>>>', this.baseMaterialFileProduct);
+              console.log('新增的产品对象>>', this.baseMaterialFileProduct);
               this.getProductList();
               this.nzNotificationService.success(this.i18NService.fanyi('save.ok'), '');
               this.nzDrawerRef.close(true); //关闭抽屉是否刷新列表
@@ -170,14 +145,16 @@ export class BasedataMaterialFileProductAddComponent implements OnInit {
       });
     } else {
       // 修改
-      return new Promise(resolve => {
-        this.baseMaterialFileProduct.pkOrg = sessionStorage.getItem('pkOrg'); //组织
+      this.baseMaterialFileProduct.pkOrg = sessionStorage.getItem('pkOrg');
+      if (this.modData) {
         this.baseMaterialFileProduct.baseMaterialFileModularList = this.modData;
-        // console.log('点击项模块列表', this.baseMaterialFileProduct.baseMaterialFileModularList);
+      }
+      return new Promise(resolve => {
         this.baseMaterialFileProductService.updateMainAndChild(this.baseMaterialFileProduct).then(res => {
           if (res.success) {
-            // 修改返回数据赋值给 点击的产品对象
             this.clickProObj = res.result;
+            console.log('this.clickProObj', this.clickProObj);
+            console.log('this.baseMaterialFileProduct', this.baseMaterialFileProduct);
             this.notification.success(this.i18NService.fanyi('successful.revision'), '');
             this.getProductList();
             this.nzDrawerRef.close(true); //关闭抽屉是否刷新列表
@@ -192,6 +169,29 @@ export class BasedataMaterialFileProductAddComponent implements OnInit {
       });
     }
   }
+  //查询 物料分类 树
+  getMaterialTree() {
+    return new Promise(resolve => {
+      let baseMaterialFileClassification = new BaseMaterialFileClassification();
+      baseMaterialFileClassification.pkOrg = sessionStorage.getItem('pkOrg');
+      this.baseMaterialFileClassificationService.getTreeList(baseMaterialFileClassification).then(res => {
+        this.materialTree = res.result;
+        console.log('物料分类 树', this.materialTree);
+        resolve();
+      });
+    });
+  }
+  //查询产品 列表
+  getProductList() {
+    return new Promise(resolve => {
+      var page = new Page();
+      page.pageSize = 500;
+      this.baseMaterialFileProductService.list(page).then(response => {
+        this.proTable = response.result.records;
+        resolve();
+      });
+    });
+  }
 
   //模块 新增
   addRowMod() {
@@ -209,8 +209,7 @@ export class BasedataMaterialFileProductAddComponent implements OnInit {
   }
   // 模块 删除按钮
   deleteMod(data) {
-    console.log('模块数据', this.modData);
-
+    // console.log('模块数据', this.modData);
     //删除点击项 获取新的模块列表数据
     this.modData = this.modData.filter(d => d.sort !== data.sort);
   }