From 988f9735377909b6310301e582c15804e004783f Mon Sep 17 00:00:00 2001
From: 19626 <1962676589@qq.com>
Date: 星期六, 07 十月 2023 10:36:13 +0800
Subject: [PATCH] 近期修改cjw

---
 force-app/main/default/lwc/lexPCLLostReportPage/lexPCLLostReportPage.js |  312 ++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 281 insertions(+), 31 deletions(-)

diff --git a/force-app/main/default/lwc/lexPCLLostReportPage/lexPCLLostReportPage.js b/force-app/main/default/lwc/lexPCLLostReportPage/lexPCLLostReportPage.js
index 447299b..b733ee0 100644
--- a/force-app/main/default/lwc/lexPCLLostReportPage/lexPCLLostReportPage.js
+++ b/force-app/main/default/lwc/lexPCLLostReportPage/lexPCLLostReportPage.js
@@ -4,7 +4,7 @@
  * @Author: chen jing wu
  * @Date: 2023-04-20 15:04:03
  * @LastEditors: chen jing wu
- * @LastEditTime: 2023-09-13 13:45:33
+ * @LastEditTime: 2023-10-03 11:54:18
  */
 let columns2=[
     { label: '--鏃�--', value: '' },
@@ -33,8 +33,10 @@
     { label: '--鏃�--', value: '' },
     { label: '涓绘満', value: '涓绘満' },
     { label: '闀滃瓙', value: '闀滃瓙' },
+    { label: '娲楁秷鏈�', value: '娲楁秷鏈�' },
     { label: '灏忛暅绉�', value: '灏忛暅绉�' },
     { label: '鑳介噺', value: '鑳介噺' },
+    { label: '鍏夋簮', value: '鍏夋簮' },
     { label: '鍏朵粬', value: '鍏朵粬' }
 ];
 const productCategoryOptions = [
@@ -79,7 +81,12 @@
 import {CloseActionScreenEvent} from 'lightning/actions'; 
 import lexLookupLwc from 'c/lexLookupLwc';
 import searchProduct from '@salesforce/apex/lexPCLLostReportLwcController.searchProduct';
-import { updateRecord } from 'lightning/uiRecordApi';
+import { updateRecord,getRecord } from 'lightning/uiRecordApi';
+import { refreshApex } from '@salesforce/apex';
+import submitForApproval from '@salesforce/apex/lexPCLLostReportLwcController.submitForApproval';
+import reassignStep from '@salesforce/apex/lexPCLLostReportLwcController.reassignStep';
+import getUserProfileId from '@salesforce/apex/lexPCLLostReportLwcController.getUserProfileId';
+import PCLReportProfileId from '@salesforce/label/c.PCLReportProfileId';
 export default class LexPCLLostReportPage extends NavigationMixin(LightningElement) {
     @track visible = false;
     @wire(CurrentPageReference) pageRef;
@@ -88,6 +95,12 @@
     @track status = {
         pageStatus: 'Create'
       }
+    newActorId = null;
+    newReport;
+    action;
+    isLookup;
+    modalsubmitLabel;
+    @track isPop;
     @track message;
     @track isSuccess;
     @track LostReport = {
@@ -95,6 +108,8 @@
         ],
         lostReport: {}
     }
+    editStatus;
+    reasonOptions = reasonOptions;
     @track brandOptions = [];
     @track isInit = false;
     lostType = '澶卞崟';
@@ -115,6 +130,16 @@
     deleteProductIdList = [];
     IsLoading;
     newApprovalHistorys;
+    userProfileId;
+    @wire(getUserProfileId)
+    wiredUserProfileId({ error, data }) {
+        if (data) {
+            this.userProfileId = data;
+            console.log(this.userProfileId + 'user');
+        } else if (error) {
+            // 澶勭悊閿欒
+        }
+    }
     handleCustomButtonClick(event) {
         try {
             var index1 = event.target.title;
@@ -148,14 +173,40 @@
                     this.LostReport = result.LostReport;
                 }else{
                     this.showToast(result.message,"error");
+                    setTimeout(() => {
+                        window.location = '/lightning/r/Opportunity/' + this.oppId + '/view';
+                    }, 2000);
                 }  
             }else{
+                if(result.LostReport.lostReport.Report_Status__c == '鐢宠涓�'){
+                    this.editStatus = '鐢宠涓�';
+                    console.log('shenqingzhong');
+                }else if(result.LostReport.lostReport.Report_Status__c == '鎵瑰噯'){
+                    this.editStatus = '鎵瑰噯';
+                    console.log('pizhun');
+                }
+                
                 var report = result.LostReport;
                 this.LostReport = report;
-                this.LostReport.lostReport.LostTotalAmount__c = 0.0;
-                this.LostReport.lostReport.InclusionUltrasound__c = '0';
+                
+                if(!this.LostReport.lostReport.LostTotalAmount__c){
+                    this.LostReport.lostReport.LostTotalAmount__c = 0.0;
+                }
+                if(!this.LostReport.lostReport.InclusionUltrasound__c){
+                    this.LostReport.lostReport.InclusionUltrasound__c = '0';
+                }
 
                 this.newProduct = JSON.parse(JSON.stringify(this.LostReport.LostBrands[0].LostProducts[0]));
+                if(this.newProduct.LostProductss.Id){
+                    delete this.newProduct.LostProductss.Id;
+                }
+                this.newProduct.LostProductss.LostBrandName__c = '';
+                this.newProduct.LostProductss.LostProduct__r = '';
+                this.newProduct.LostProductss.Quantity__c = '';
+                this.newProduct.LostProductss.LostProductMannual__c = '';
+                this.newProduct.LostProductss.ProductClass__c = '';
+                this.newProduct.LostProductss.ProductCategory__c = '';
+                // this.newProduct.LostProductss.Id = '';
                 this.newApprovalHistorys = JSON.parse(JSON.stringify(this.LostReport.approvalHistorys));
                 console.log(this.LostReport);
                 console.log(this.LostReport.approvalHistorys.length);
@@ -177,7 +228,7 @@
                         }else if(this.LostReport.approvalHistorys[i].StepStatus == 'Reassigned'){
     
                         }else if(this.LostReport.approvalHistorys[i].StepStatus == 'Rejected'){
-                            resthis.LostReportult.approvalHistorys[i].StepStatus = '宸叉嫆缁�';
+                                this.LostReport.approvalHistorys[i].StepStatus = '宸叉嫆缁�';
                         }else if(this.LostReport.approvalHistorys[i].StepStatus == 'Removed'){
     
                         }else if(this.LostReport.approvalHistorys[i].StepStatus == 'Started'){
@@ -187,8 +238,21 @@
                         console.log('321');
                     }
                     this.submitFlag = true;
+                    if(this.LostReport.lostReport.Report_Status__c == '鎵瑰噯'){
+                        this.submitFlag = false;
+                    }
                 }
-                this.isInit = true;
+                console.log(PCLReportProfileId.includes(this.userProfileId));
+                console.log(PCLReportProfileId);
+                console.log(this.userProfileId);
+                getUserProfileId().then(result1=>{
+                    this.userProfileId = result1;
+                    if(this.pageStatus == 'Edit' && !(this.LostReport.lostReport.Report_Status__c == '鑽夋' || this.userProfileId == '00e10000000Y3o5AAC' || (this.LostReport.lostReport.Report_Status__c == '鎵瑰噯' && PCLReportProfileId.includes(this.userProfileId)))){
+                        this.status.pageStatus = 'View';
+                    }
+                    this.isInit = true;
+                });
+                
             }
             }).catch(error=>{
                 console.log("error");
@@ -209,11 +273,13 @@
             fieldName: 'ProductCategory__c'
         }).then(result=>{
             this.productOptionsList = JSON.parse(result);
+            this.LostReport = JSON.parse(JSON.stringify(this.LostReport));
+            console.log(this.LostReport.approvalHistorys.length + 'size');
         }).catch(error=>{
             console.log('error');
             console.log(error);
         });
-
+        
     }
     renderedCallback(){
         const sections = this.template.querySelectorAll('lightning-accordion-section');
@@ -221,7 +287,12 @@
             console.log(section);
             section.active = true;    
         });
+        console.log('1');
+        console.log(this.LostReport.lostReport.LostTotalAmount__c);
+        this.LostReport.lostReport.LostTotalAmount__c = this.LostReport.lostReport.LostTotalAmount__c;
+        // this.LostReport = JSON.parse(JSON.stringify(this.LostReport));
     }
+    brandTitle = ['澶卞崟鍝佺墝1','澶卞崟鍝佺墝2','澶卞崟鍝佺墝3','澶卞崟鍝佺墝4','澶卞崟鍝佺墝5','澶卞崟鍝佺墝6'];
 
     @wire(CurrentPageReference)
     getStateParameters(currentPageReference) {
@@ -238,6 +309,33 @@
             }
         }
     }
+    closeAction(){
+        this.visible = false;
+    }
+
+    get haveApprovalHistorys(){
+        console.log(this.LostReport.approvalHistorys.length + 'size');
+        if(this.LostReport.approvalHistorys.length > 1){
+            return true;
+        }else{
+            return false;
+        }
+    }
+    get isCanSubmit(){
+        if(this.LostReport.lostReport.Report_Status__c == '鑽夋' || this.LostReport.lostReport.Report_Status__c == '鎵瑰噯'){
+            return true;
+        }else{
+            return false;
+        }
+    }
+
+    get isCanEdit(){
+        if(this.LostReport.lostReport.Report_Status__c == '鑽夋' || this.userProfileId == '00e10000000Y3o5AAC' || (this.LostReport.lostReport.Report_Status__c == '鎵瑰噯' && PCLReportProfileId.includes(this.userProfileId))){
+            return true;
+        }else{
+            return false;
+        }
+    }
 
     showToast(msg,type) {
         try {
@@ -251,9 +349,9 @@
             let delay = 5000;
             console.log(this.message);
             console.log('1');
-            setTimeout(() => {
-                this.visible = false;
-            }, delay ); 
+            // setTimeout(() => {
+            //     this.visible = false;
+            // }, delay ); 
         } catch (error) {
             console.log(error);
         }
@@ -311,6 +409,13 @@
         }
         return false;
     }
+    get isCaoAn(){
+        if(this.LostReport.lostReport.Report_Status__c == '鑽夋'){
+            return true;
+        }else{
+            return false;
+        }
+    }
 
     get isEdit(){
         if(this.status.pageStatus == 'Edit'){
@@ -318,6 +423,7 @@
         }
         return false;
     }
+
     get isSubmit(){
         if(this.submitFlag){
             return true;
@@ -330,6 +436,14 @@
             lineNo: this.LostReport.LostBrands.length
         }).then(result=>{
             this.LostReport.LostBrands.push(result);
+            // 鑾峰彇 lightning-accordion 鐨� DOM 鍏冪礌
+            setTimeout(() => {
+                const accordion = this.template.querySelector('.example-accordion');
+            console.log(accordion);
+            console.log('1');
+            accordion.activeSectionName = this.brandTitle;
+            }, 200);
+
         });
     }
     addRow(event){
@@ -345,8 +459,9 @@
         console.log('1');
         this.IsLoading = true;
         submit({
-            report1: JSON.stringify(this.LostReport),
-            reportId: this.reportId
+            reportStatus: this.LostReport.lostReport.Report_Status__c,
+            modifyAfterApproval: this.LostReport.lostReport.ModifyAfterApproval__c,
+            reportId: this.LostReport.lostReport.Id
         }).then(result=>{
             if(result.error){
                 this.showToast(result.error,"error");
@@ -381,8 +496,12 @@
                 }
                 this.submitFlag = JSON.parse(JSON.stringify(result.submitFlag));
                 console.log(this.LostReport);
-                this.updateRecordView(this.reportId);
-                this.LostReport.lostReport.Report_Status__c = '鐢宠涓�';
+                // this.updateRecordView(this.reportId);
+                this.showToast('鎻愪氦鎴愬姛锛�','success');
+                setTimeout(() => {
+                    
+                    window.location = '/' + this.LostReport.lostReport.Id;
+                }, 2000);
             }
             this.IsLoading = false;
         }).catch(error=>{
@@ -391,14 +510,19 @@
         });
     }
     onApproveChange(event){
-        window.open('/lightning/r/ProcessInstanceStep/'+ this.LostReport.approvalHistorys[0].Id + '/view?0.source=alohaHeader');
-        // this[NavigationMixin.Navigate]({
-        //     type: 'standard__recordPage',
-        //     attributes: {
-        //         recordId: this.LostReport.approvalHistorys[0].Id,
-        //         actionName: 'view'
-        //     }
-        // });
+        // var approvalId;
+        // for(var i=0;i < this.LostReport.approvalHistorys.length;i++){
+        //     if(this.LostReport.approvalHistorys[i].StepStatus == '寰呭鐞�'){
+        //         approvalId = this.LostReport.approvalHistorys[i].Id;
+        //     }  
+        // }
+        
+        // window.open('/lightning/r/ProcessInstanceStep/'+ approvalId + '/view?0.source=alohaHeader');
+        this.isPop = true;
+        
+    }
+    onApproveChange1(){
+        window.open('/lightning/r/' + this.LostReport.lostReport.Id + '/related/ProcessSteps/view?0.source=alohaHeader');
     }
     
 
@@ -439,6 +563,8 @@
         this.LostReport.LostBrands[index].lostBrand.Lost_By_Company__c = payload.value;
         this.LostReport.LostBrands[index].lostBrand.Lost_reason_main__c = '';
         this.LostReport.LostBrands[index].lostBrand.Lost_Reason_Sub__c = '';
+        this.LostReport.LostBrands[index].lostBrand.ChannelSpecificReasons__c = '';
+        this.LostReport.LostBrands[index].reasonFlag = false;
         searchBatchIfForProduct({
             productName: this.LostReport.LostBrands[index].lostBrand.Lost_By_Company__c
         }).then(result=>{
@@ -454,6 +580,7 @@
                 this.setDefaultBrand(payload.value,index);
                 this.clearBrandMannualName(payload.value,index);
             }
+            console.log('cnm:' + JSON.stringify(this.LostReport));
         });
         
     }
@@ -514,8 +641,30 @@
         //         actionName: 'view'
         //     }
         // });
-        window.location = '/' +this.oppId;
+        window.location = '/lightning/r/Opportunity/' + this.LostReport.lostReport.Opportunity__c + '/view';
     }
+    removeFieldsWithR(obj) {
+        if (Array.isArray(obj)) {
+            // 濡傛灉灞炴�ф槸鏁扮粍锛岄亶鍘嗘暟缁勫厓绱�
+            for (var i = 0; i < obj.length; i++) {
+                // 閫掑綊璋冪敤鍑芥暟澶勭悊鏁扮粍鍏冪礌
+                this.removeFieldsWithR(obj[i]);
+            }
+        } else if (typeof obj === 'object' && obj !== null) {
+            // 濡傛灉灞炴�ф槸瀵硅薄锛屽垯閬嶅巻瀵硅薄灞炴��
+            for (var key in obj) {
+                if (key.includes('__r') || key === 'approvalHistorys') {
+                    // 濡傛灉灞炴�у悕浠� '__r' 缁撳熬锛屽垹闄ゅ畠
+                    console.log(key);
+                    delete obj[key];
+                }else if (typeof obj[key] === 'object' && obj[key] !== null) {
+                    // 濡傛灉灞炴�ф槸瀵硅薄锛屽垯閫掑綊璋冪敤璇ュ嚱鏁�
+                    this.removeFieldsWithR(obj[key]);
+                }
+            }
+        }
+    }
+    
     
     saveBrandJs(event) {
         this.IsLoading = true;
@@ -525,10 +674,13 @@
             return;
         }
         console.log(this.LostReport);
-        var newLostReport = JSON.parse(JSON.stringify(this.LostReport));
-        newLostReport.approvalHistorys = this.newApprovalHistorys;
+        this.newReport = JSON.parse(JSON.stringify(this.LostReport));
+        this.newReport.approvalHistorys = this.newApprovalHistorys;
+        console.log(JSON.stringify(this.newReport));
+        this.removeFieldsWithR(this.newReport);
+        console.log(JSON.stringify(this.newReport));
         dataEntry({
-            report1 : JSON.stringify(newLostReport),
+            report1 : JSON.stringify(this.newReport),
             deleteBrandIdList: this.deleteBrandIdList,
             deleteProductIdList: this.deleteProductIdList
         }).then(result=>{
@@ -685,7 +837,8 @@
     removeRow(event){
         var index1 = event.target.name;
         var index2 = event.target.value;
-        var deleteButtons = this.template.querySelectorAll('.deleteButton[data-id="' + index1 + '"]');
+        var deleteButtons = this.template.querySelectorAll('.iconButton[data-id="' + index1 + '"]');
+        console.log(deleteButtons.length + ' chen1');
         if(deleteButtons.length == 1){
             return;
         }
@@ -720,7 +873,13 @@
                     elements1[secondNum].readOnly = false;
                     elements2[secondNum].readOnly = false;
                     this.LostReport.LostBrands[topNum].LostProducts[secondNum].LostProductss.ProductClass__c=prd.ProductClass__c;
-                    this.LostReport.LostBrands[topNum].LostProducts[secondNum].LostProductss.ProductCategory__c=prd.ProductCategory__c;
+                    console.log(prd.ProductClass__c + '  ' + prd.ProductCategory__c);
+                    if(prd.ProductClass__c == '鍏朵粬' && (prd.ProductCategory__c == '' || prd.ProductCategory__c == null || prd.ProductCategory__c == undefined)){
+                        this.LostReport.LostBrands[topNum].LostProducts[secondNum].LostProductss.ProductCategory__c = '鍏朵粬';
+                    }else{
+                        this.LostReport.LostBrands[topNum].LostProducts[secondNum].LostProductss.ProductCategory__c=prd.ProductCategory__c;
+                    }
+                    
                     elements1[secondNum].readOnly = true;
                     elements2[secondNum].readOnly = true;
                 }else {
@@ -728,7 +887,7 @@
                     elements2[secondNum].readOnly = false;
                     this.LostReport.LostBrands[topNum].LostProducts[secondNum].LostProductss.ProductClass__c=null;
                     this.LostReport.LostBrands[topNum].LostProducts[secondNum].LostProductss.ProductCategory__c=null;
-                    elements1[secondNum].readOnly = true;
+                    // elements1[secondNum].readOnly = true;
                     elements2[secondNum].readOnly = true;
                 }
             }).catch(error=>{
@@ -737,6 +896,84 @@
             });
 			
 		}
+    }
+    handleModalCancel(){
+        this.isPop = false;
+    }
+    handleModalSubmit(){
+        
+        this.IsLoading = true;
+        const comment = this.template.querySelector('.comment');
+        console.log(this.isLookup == true && this.newActorId == null);
+        if(this.isLookup == true && this.newActorId == null){
+            this.showToast('璇峰~鍏ユ柊鍒嗛厤浜�','error');
+            this.IsLoading = false;
+            return;
+        }
+        this.isPop = false;
+        if(this.newActorId){
+            reassignStep({
+                recordId: this.LostReport.lostReport.Id,
+                newActorId: this.newActorId
+            }).then(result=>{
+                if(result){
+                    this.showToast('鎮ㄦ棤鏉冮噸鏂板垎閰�','error');
+                    this.IsLoading = false;
+                }else{
+                    window.location = '/' + this.LostReport.lostReport.Id;
+                }
+                
+            });
+        }else{
+            submitForApproval({
+                recordId: this.LostReport.lostReport.Id,
+                comments: comment.value,
+                action: this.action
+            }).then(result=>{
+                if(result){
+                    if(this.action == 'Approve'){
+                        this.showToast('鎮ㄦ棤鏉冩壒鍑�','error');
+                    }else if(this.action == 'Reject'){
+                        this.showToast('鎮ㄦ棤鏉冩嫆缁�','error');
+                    }else if(this.action == 'Removed'){
+                        this.showToast('鎮ㄦ棤鏉冩挙鍥�','error');
+                    }
+                    
+                    this.IsLoading = false;
+                }else{
+                    window.location = '/' + this.LostReport.lostReport.Id;
+                } 
+            });
+        }
+        
+        
+    }
+    handleSubmitApp(){
+        this.modalsubmitLabel = '鎵瑰噯';
+        this.isPop = true;
+        this.action = 'Approve';
+        this.isLookup = false;
+        this.newActorId = null;
+    }
+    handleReStartApp(){
+        this.modalsubmitLabel = '閲嶆柊鍒嗛厤';
+        this.isPop = true;
+        this.isLookup = true;
+
+    }
+    handleNoApp(){
+        this.modalsubmitLabel = '鎷掔粷';
+        this.isPop = true;
+        this.action = 'Reject';
+        this.isLookup = false;
+        this.newActorId = null;
+    }
+    handleCancelApp(){
+        this.modalsubmitLabel = '鎾ゅ洖';
+        this.isPop = true;
+        this.action = 'Removed';
+        this.isLookup = false;
+        this.newActorId = null;
     }
 
     handleClear(event){
@@ -758,7 +995,8 @@
     }
     handleChannelSpecificReasonChange(event){
         var value = event.target.value;
-        this.LostReport.lostReport.LostType__c = value;
+        var index = event.target.name;
+        this.LostReport.LostBrands[index].lostBrand.ChannelSpecificReasons__c = value;
     }
     
     handleLostReasonMainChange(event){
@@ -766,7 +1004,10 @@
         var value = event.target.value;
         this.LostReport.LostBrands[index].lostBrand.Lost_reason_main__c = value;
         if(value == '娓犻亾鍥犵礌'){
-            
+            this.LostReport.LostBrands[index].reasonFlag = true;
+        }else if(this.LostReport.LostBrands[index].lostBrand.Lost_reason_main__c != '娓犻亾鍥犵礌' && this.LostReport.LostBrands[index].lostBrand.Lost_Reason_Sub__c != '娓犻亾鍥犵礌'){
+            this.LostReport.LostBrands[index].reasonFlag = false;
+            this.LostReport.LostBrands[index].lostBrand.ChannelSpecificReasons__c = ''; 
         }
     }
 
@@ -774,6 +1015,12 @@
         var index = event.target.name;
         var value = event.target.value;
         this.LostReport.LostBrands[index].lostBrand.Lost_Reason_Sub__c = value;
+        if(value == '娓犻亾鍥犵礌'){
+            this.LostReport.LostBrands[index].reasonFlag = true;
+        }else if(this.LostReport.LostBrands[index].lostBrand.Lost_reason_main__c != '娓犻亾鍥犵礌' && this.LostReport.LostBrands[index].lostBrand.Lost_Reason_Sub__c != '娓犻亾鍥犵礌'){
+            this.LostReport.LostBrands[index].reasonFlag = false;
+            this.LostReport.LostBrands[index].lostBrand.ChannelSpecificReasons__c = ''; 
+        }
     }
 
     handleLostByCompanyMannualChange(event){
@@ -845,6 +1092,9 @@
         }
        
     }
+    handleActorChange(event){
+        this.newActorId = event.target.value;
+    }
 
     handleProductCategoryChange(event){
         var index1 = event.target.title;

--
Gitblit v1.9.1