123
chenjingwu
2024-04-16 cc914d1a68f71cf0b8fe7f1c4bfac9fc1e54e3d8
force-app/main/default/lwc/lexAgencyAuthorize/lexAgencyAuthorize.js
@@ -4,7 +4,7 @@
 * @Author: chen jing wu
 * @Date: 2023-04-12 14:51:44
 * @LastEditors: chen jing wu
 * @LastEditTime: 2023-04-13 09:54:19
 * @LastEditTime: 2023-10-10 17:25:57
 */
import { api, wire,LightningElement } from 'lwc';
import { CurrentPageReference } from "lightning/navigation";
@@ -14,8 +14,15 @@
import { updateRecord } from 'lightning/uiRecordApi';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import checkDangerItem from '@salesforce/apex/OpportunityWebService.checkDangerItem';
import accSendEmail from '@salesforce/apex/OpportunityWebService.accSendEmail';
import oppCheck from '@salesforce/apex/OpportunityWebService.oppCheck';
import updReg from '@salesforce/apex/OpportunityWebService.updReg';
import TradeComplianceStatusFlag from '@salesforce/label/c.TradeComplianceStatusFlag';
import IFTradeComplianceAlert from '@salesforce/label/c.IFTradeComplianceAlert';
import LightningConfirm from 'lightning/confirm';
import lwcCSS from '@salesforce/resourceUrl/lwcCSS';
import {loadStyle} from 'lightning/platformResourceLoader';
import queryQuote from '@salesforce/apex/OpportunityLightingButtonController.queryQuote';
export default class LexAgencyAuthorize extends LightningElement {
    @api recordId;
@@ -37,6 +44,17 @@
    isCorrosion;
    profileId;
    ifAuthorizingLock;
    systemProfileId;
    j3ProfileId;
    s61ProfileId;
    s62ProfileId;
    m4ProfileId;
    AccDealerBlacklist;
    angency1;
    angency2;
    accname;
    ownerids;
    ddid;
    IsLoading = true;
    @wire(CurrentPageReference)
    getStateParameters(currentPageReference) {
@@ -54,6 +72,9 @@
        }
    }
    connectedCallback(){
        Promise.all([
            loadStyle(this, lwcCSS)
           ]);
        init({
            recordId: this.recordId
        }).then(result=>{
@@ -76,8 +97,23 @@
            this.isCorrosion = result.isCorrosion;
            this.profileId = result.profileId;
            this.ifAuthorizingLock = result.ifAuthorizingLock;
            this.systemProfileId = result.systemProfileId;
            this.j3ProfileId = result.j3ProfileId;
            this.s61ProfileId = result.s61ProfileId;
            this.s62ProfileId = result.s62ProfileId;
            this.m4ProfileId = result.m4ProfileId;
            this.AccDealerBlacklist = result.AccDealerBlacklist;
            this.angency1 = result.angency1;
            this.angency2 = result.angency2;
            this.accname = result.accname;
            this.ownerids = result.ownerids;
            this.ddid = result.ddid;
            console.log("w");
            this.AgencyAuthorize();
        })
        }).catch(error=>{
            console.log("error");
            console.log(error);
        });
    }
    AgencyAuthorize(){
        var btns = document.getElementsByName("agency_authorize");
@@ -89,32 +125,128 @@
        var oppid = this.recordId;
        var angency = this.agency1Id;
        var profileId = this.profileId;
        if (profileId != '00e10000000Y3o5' && profileId != '00e10000000Nab7' && profileId != '00e10000000xnpR' && profileId != '00e10000000xyK6' && profileId != '00e10000000NbCE'
        && profileId != '00e10000000xyK6' && profileId != '00e10000000Nb7i') {
        this.detailNum = 1;
        if (profileId != this.systemProfileId && profileId != this.j3ProfileId && profileId != this.s61ProfileId && profileId != this.s62ProfileId && profileId != this.m4ProfileId) {
            this.showToast("您没有授权申请的权限。请联系系统管理员。","error");
            return;
        }
        queryQuote({
            estimationId: this.estimationId
        }).then(result=>{
            console.log(result);
            if(result == true){
                this.showToast("包含虚拟产品,不能授权,请更新报价单后申请","error");
                return;
            }
             //贸易合规 you
        var AccDealerBlacklist = this.AccDealerBlacklist;//判断客户/经销商是否为黑名单
        var angency1 = this.angency1;
        var angency2 = this.angency2;
        var accname = this.accname;
        var ownerids = this.ownerids;
        var ddid = this.ddid;
        if(TradeComplianceStatusFlag=='true'){
            //拦截+邮件提醒
            var oppflag=false;
            if (AccDealerBlacklist=='123') {
                // alert('客户,经销商1,经销商2都为黑名单,不能做授权申请,'+IFTradeComplianceAlert);
                this.showToast('客户,经销商1,经销商2都为黑名单,不能做授权申请,'+IFTradeComplianceAlert,'error');
                oppflag=true;
            }else if(AccDealerBlacklist=='12'){
                // alert('客户,经销商1都为黑名单,不能做授权申请,'+IFTradeComplianceAlert);
                this.showToast('客户,经销商1都为黑名单,不能做授权申请,'+IFTradeComplianceAlert,'error');
                oppflag=true;
            }else if(AccDealerBlacklist=='23'){
                // alert('经销商1,经销商2都为黑名单,不能做授权申请,'+IFTradeComplianceAlert);
                this.showToast('经销商1,经销商2都为黑名单,不能做授权申请,'+IFTradeComplianceAlert,'error');
                oppflag=true;
            }else if(AccDealerBlacklist=='13'){
                // alert('客户,经销商2都为黑名单,不能做授权申请,'+IFTradeComplianceAlert);
                this.showToast('客户,经销商2都为黑名单,不能做授权申请,'+IFTradeComplianceAlert,'error');
                oppflag=true;
            }else if(AccDealerBlacklist=='1'){
                // alert('客户为黑名单,不能做授权申请,'+IFTradeComplianceAlert);
                this.showToast('客户为黑名单,不能做授权申请,'+IFTradeComplianceAlert,'error');
                oppflag=true;
            }else if(AccDealerBlacklist=='2'){
                // alert('经销商1为黑名单,不能做授权申请,'+IFTradeComplianceAlert);
                this.showToast('经销商1为黑名单,不能做授权申请,'+IFTradeComplianceAlert,'error');
                oppflag=true;
            }else if(AccDealerBlacklist=='3'){
                // alert('经销商2为黑名单,不能做授权申请,'+IFTradeComplianceAlert);
                this.showToast('经销商2为黑名单,不能做授权申请,'+IFTradeComplianceAlert,'error');
                oppflag=true;
            }
            console.log('y');
            console.log(oppflag);
            if(oppflag){
                accSendEmail({
                    "AccDealerBlacklist":AccDealerBlacklist,
                    "accname":accname,
                    "angency1":angency1,
                    "angency2":angency2,
                    "ownerids":ownerids,
                    "ddid":ddid,
                    "oppid":oppid
                }).then(result=>{
                    console.log('q');
                    var opprtn = result;
                    if (opprtn = true) {
                        return;
                    }
                    //警示提醒
                    if (AccDealerBlacklist=='567') {
                        this.handleConfirmClick('您所选择的客户,经销商1,经销商2存在贸易合规警示风险,不建议做授权申请,请您确认是否继续申请,'+IFTradeComplianceAlert);
                    }else if(AccDealerBlacklist=='56'){
                        this.handleConfirmClick('您所选择的客户,经销商1存在贸易合规警示风险,不建议做授权申请,请您确认是否继续申请,'+IFTradeComplianceAlert);
                    }else if(AccDealerBlacklist=='67'){
                        this.handleConfirmClick('您所选择的经销商1,经销商2存在贸易合规警示风险,不建议做授权申请,请您确认是否继续申请,'+IFTradeComplianceAlert);
                    }else if(AccDealerBlacklist=='57'){
                        this.handleConfirmClick('您所选择的客户,经销商2存在贸易合规警示风险,不建议做授权申请,请您确认是否继续申请,'+IFTradeComplianceAlert);
                    }else if(AccDealerBlacklist=='5'){
                        this.handleConfirmClick('您所选择的客户存在贸易合规警示风险,不建议做授权申请,请您确认是否继续申请,'+IFTradeComplianceAlert);
                    }else if(AccDealerBlacklist=='6'){
                        this.handleConfirmClick('您所选择的经销商1存在贸易合规警示风险,不建议做授权申请,请您确认是否继续申请,'+IFTradeComplianceAlert);
                    }else if(AccDealerBlacklist=='7'){
                        this.handleConfirmClick('您所选择的经销商2存在贸易合规警示风险,不建议做授权申请,请您确认是否继续申请,'+IFTradeComplianceAlert);
                    }
                });
            }else{
                this.ss();
            }
        }else{
            this.ss();
        }
        //贸易合规 you
        });
    }
    ss(){
        if (this.stageName != '引合' && this.stageName != '询价' ) {
            this.showToast("状态1:" + this.stageName + "、不能做授权申请!","error");
            return;
        } else if (this.sapSendOK == '1') {
            this.showToast("已经上传SAP、不能做授权申请了!","error");
            return;
        } else if (this.oppOrderType != '' && this.ifHave170 == true) {
        } else if (this.oppOrderType != undefined && this.ifHave170 == true) {
            this.showToast("耗材不可与170产品同时存在!","error");
            return;
        } else if (this.oppOrderType != '' && this.ifHaveAH == true) {
        } else if (this.oppOrderType != undefined && this.ifHaveAH == true) {
            this.showToast("耗材不可与奥辉产品同时存在!","error");
            return;
        } else if (this.cntLostCancelDraft > 0) {
        if(!confirm('询价有草案中的取消/失单报告,是否继续?')){
            return ;
        }
            // if(!confirm('询价有草案中的取消/失单报告,是否继续?')){
            //     this.dispatchEvent(new CloseActionScreenEvent());
            //     return ;
            // }
            this.handleConfirmClick1("询价有草案中的取消/失单报告,是否继续?");
        } else if (this.cntLostCancelReport - this.cntLostCancelDraft > 0) {
            this.showToast('询价有已提交的取消/失单报告。',"error");
            return;
        } else if (this.estimationId == '' || this.detailNum == 0) {
        } else if (this.estimationId == undefined || this.detailNum == 0) {
            this.showToast('报价未完成,请先报价。',"error");
            return;
        } else if (this.estimationDecision == '1') {
@@ -123,23 +255,24 @@
        } else if (this.salesRoot != '販売店') {
            this.showToast('医院直销不需要授权申请。',"error");
            return;
        }
        // else if ('{!Opportunity.AcecideCntCheck__c}' != '1') {
        // alert('阿西赛多询价只能包含危化品,或者,普通询价不能包含危化品。');
        // return;
        // }
        else if (this.ifSubmit == '1') {
        }else if (this.ifSubmit == '1') {
            this.showToast('上传失败,请联系系统管理员!',"error");
            return;
        }else{
            this.dd();
        }
        if (this.ifAuthorizingLock == 'true') {
    }
    dd(){
        if (this.ifAuthorizingLock == true) {
            this.showToast('询价正在授权中,请不要重复提交。',"error");
            return;
        }
        if (this.trade == '内貿') {
            if(this.isCorrosion == '1'){
                checkDangerItem({
                    agency1: angency
                    agency1: this.agency1Id
                }).then(result=>{
                    var rtn1 = result;
                    if (rtn1 != 'OK') {
@@ -150,7 +283,7 @@
            });
            }else{
                oppCheck({
                    oppid: oppid,
                    oppid: this.recordId,
                    saveFlg: '1'
                }).then(result=>{
                    var rtn = result;
@@ -163,20 +296,54 @@
            }
        } else {
            updReg({
                oppid: oppid
                oppid: this.recordId
            }).then(()=>{
                this.update();
            });
        }  
    }
    showToast(msg,type) {
        const event = new ShowToastEvent({
            title: '',
    async handleConfirmClick(msg) {
        const result = await LightningConfirm.open({
            message: msg,
            variant: type
            variant: 'headerless',
            label: 'this is the aria-label value'
        });
        this.dispatchEvent(event);
        this.dispatchEvent(new CloseActionScreenEvent());
        if (result) {
            this.ss();
        } else {
            this.dispatchEvent(new CloseActionScreenEvent());
        }
    }
    async handleConfirmClick1(msg) {
        const result = await LightningConfirm.open({
            message: msg,
            variant: 'headerless',
            label: 'this is the aria-label value'
        });
        if (result) {
            this.dd();
        } else {
            this.dispatchEvent(new CloseActionScreenEvent());
        }
    }
    showToast(msg,type) {
        if(type == 'success'){
            const event = new ShowToastEvent({
                message: msg,
                variant: type,
            });
            this.dispatchEvent(event);
            this.dispatchEvent(new CloseActionScreenEvent());
        }else{
            const event = new ShowToastEvent({
                message: msg,
                variant: type,
                mode: 'sticky'
            });
            this.dispatchEvent(event);
            this.dispatchEvent(new CloseActionScreenEvent());
        }
    }
    updateRecordView(recordId) {
        updateRecord({fields: { Id: recordId }});