19626
2023-10-07 988f9735377909b6310301e582c15804e004783f
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;
                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;
                    }
                }
                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,6 +273,8 @@
            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);
@@ -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;
                    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;