zhangqian
2023-06-12 39c063d623cd287669f017212565a3bc9e0d9ada
新建备品opd计划

1
5个文件已添加
440 ■■■■■ 已修改文件
force-app/main/default/classes/lexNewSparePartsLoanApplicationCtl.cls 137 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
force-app/main/default/classes/lexNewSparePartsLoanApplicationCtl.cls-meta.xml 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
force-app/main/default/lwc/lexNewSparePartsLoanApplication/lexNewSparePartsLoanApplication.html 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
force-app/main/default/lwc/lexNewSparePartsLoanApplication/lexNewSparePartsLoanApplication.js 282 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
force-app/main/default/lwc/lexNewSparePartsLoanApplication/lexNewSparePartsLoanApplication.js-meta.xml 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
force-app/main/default/classes/lexNewSparePartsLoanApplicationCtl.cls
New file
@@ -0,0 +1,137 @@
public with sharing class lexNewSparePartsLoanApplicationCtl {
    public lexNewSparePartsLoanApplicationCtl() {
    }
    //获取当前登录人的 id
    @AuraEnabled
    public static UserResult UserInfo_Owner() {
        UserResult result = new UserResult();
        ID myUserID = UserInfo.getUserId();
        try {
            User tempUser =
                [select Id,Job_Category__c,isFormal_Stuff__c,FirstName,LastName,Province__c from user where id = : myUserID ];
            result.id = tempUser.Id;
            result.isFormalStuff = tempUser.isFormal_Stuff__c;
            result.firstName = tempUser.FirstName;
            result.lastName = tempUser.LastName;
            result.userProvince = tempUser.Province__c;
            result.userJobCategory = tempUser.Job_Category__c;
        } catch (exception e) {
            result.result = e.getMessage();
        }
        return result;
    }
    @AuraEnabled
    public static InitData init(String recordId){
        InitData res = new initData();
        try {
            OPDPlan__c rep = [select Id,Status__c,Rental_Apply_Flag__c,OPDType__c,CampaignStatus__c,CampaignRecodeTypeId__c,Internal_in_charge_province__c,StayOrNot__c,OriginalOpdPlanApplication__c,IF_Approved__c,Approved_No__c,Approved_Status__c,Rental_Apply2__c,OriginalOpdPlan__c,CampaignName__c,Related_Opportunity1_Name__c,NoOpp_Reason__c,Account_Laboratory__c,OCM_category_Name__c,HospitalName__c,Name,IsJump__c,JumpCause__c,originalOpdRentalApply__c,RentalApplyName__c from OPDPlan__c where Id =: recordId];
            res.opdPlanId = rep.Id;
            res.opdStatus = rep.Status__c;
            res.opdRentalApplyFlag = rep.Rental_Apply_Flag__c;
            res.opdType = rep.OPDType__c;
            res.opdCampaignStatus = rep.CampaignStatus__c;
            res.opdCampaignRecodeTypeId = rep.CampaignRecodeTypeId__c;
            res.opdInternalinchargeprovince = rep.Internal_in_charge_province__c;
            res.opdStayOrNot = rep.StayOrNot__c;
            res.opdOriginalOpdPlanApplication = rep.OriginalOpdPlanApplication__c;
            res.opdIFApproved = rep.IF_Approved__c;
            res.opdApprovedNo = rep.Approved_No__c;
            res.opdApprovedStatus = rep.Approved_Status__c;
            res.opdRentalApply2 = rep.Rental_Apply2__c;
            res.opdOriginalOpdPlan = rep.OriginalOpdPlan__c;
            res.opdCampaignName = rep.CampaignName__c;
            res.opdRelatedOpportunity1Name = rep.Related_Opportunity1_Name__c;
            res.opdNoOppReason = rep.NoOpp_Reason__c;
            res.opdAccountLaboratory = rep.Account_Laboratory__c;
            res.opdOCMcategoryName = rep.OCM_category_Name__c;
            res.opdHospitalName = rep.HospitalName__c;
            res.opdName = rep.Name;
            res.opdIsJump = rep.IsJump__c;
            res.opdJumpCause = rep.JumpCause__c;
            res.opdoriginalOpdRentalApply = rep.originalOpdRentalApply__c;
            res.opdRentalApplyName = rep.RentalApplyName__c;
            res.opdStatusProcessState = System.Label.StatusProcessState;
            return res;
        } catch (Exception e) {
            throw new AuraHandledException(e.getMessage());
        }
    }
    public class InitData{
        @AuraEnabled
        public String opdPlanId;
        @AuraEnabled
        public String opdStatus;
        @AuraEnabled
        public Decimal opdRentalApplyFlag;
        @AuraEnabled
        public String opdType;
        @AuraEnabled
        public String opdCampaignStatus;
        @AuraEnabled
        public String opdCampaignRecodeTypeId;
        @AuraEnabled
        public String opdInternalinchargeprovince;
        @AuraEnabled
        public String opdStayOrNot;
        @AuraEnabled
        public String opdOriginalOpdPlanApplication;
        @AuraEnabled
        public Boolean opdIFApproved;
        @AuraEnabled
        public String opdApprovedNo;
        @AuraEnabled
        public String opdApprovedStatus;
        @AuraEnabled
        public String opdRentalApply2;
        @AuraEnabled
        public String opdOriginalOpdPlan;
        @AuraEnabled
        public String opdCampaignName;
        @AuraEnabled
        public String opdRelatedOpportunity1Name;
        @AuraEnabled
        public String opdNoOppReason;
        @AuraEnabled
        public String opdAccountLaboratory;
        @AuraEnabled
        public String opdOCMcategoryName;
        @AuraEnabled
        public String opdHospitalName;
        @AuraEnabled
        public String opdName;
        @AuraEnabled
        public Boolean opdIsJump;
        @AuraEnabled
        public String opdJumpCause;
        @AuraEnabled
        public String opdoriginalOpdRentalApply;
        @AuraEnabled
        public String opdRentalApplyName;
        @AuraEnabled
        public String opdStatusProcessState;
    }
    public class UserResult {
        @AuraEnabled
        public string result;
        public UserResult( ) {
            result = 'Success';
        }
        @AuraEnabled
        public string id;
        @AuraEnabled
        public Boolean isFormalStuff;
        @AuraEnabled
        public string firstName;
        @AuraEnabled
        public string lastName;
        @AuraEnabled
        public string userProvince;
        @AuraEnabled
        public string userJobCategory;
    }
}
force-app/main/default/classes/lexNewSparePartsLoanApplicationCtl.cls-meta.xml
New file
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>57.0</apiVersion>
    <status>Active</status>
</ApexClass>
force-app/main/default/lwc/lexNewSparePartsLoanApplication/lexNewSparePartsLoanApplication.html
New file
@@ -0,0 +1,5 @@
<template>
    <div class="dispatchOCSMQARAHolder" if:true={IsLoading}>
        <lightning-spinner alternative-text="Loading" size="medium"></lightning-spinner>
    </div>
</template>
force-app/main/default/lwc/lexNewSparePartsLoanApplication/lexNewSparePartsLoanApplication.js
New file
@@ -0,0 +1,282 @@
import { LightningElement,wire,track,api} from 'lwc';
import { CurrentPageReference, NavigationMixin} from "lightning/navigation";
import { CloseActionScreenEvent } from 'lightning/actions';
import  init  from '@salesforce/apex/lexNewSparePartsLoanApplicationCtl.init';
import UserInfo_Owner from '@salesforce/apex/lexNewSparePartsLoanApplicationCtl.UserInfo_Owner';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import { encodeDefaultFieldValues } from 'lightning/pageReferenceUtils';
// 新建备品借出申请 opd计划
export default class LexNewSparePartsLoanApplication extends LightningElement {
    @api recordId;
    IsLoading = true;
    @wire(CurrentPageReference)
    getStateParameters(currentPageReference) {
            console.log(111);
            console.log(currentPageReference);
        if (currentPageReference) {
          const urlValue = currentPageReference.state.recordId;
          if (urlValue) {
            let str = `${urlValue}`;
            console.log("str");
            console.log(str);
            this.recordId = str;
          }
        }
    }
    connectedCallback(){
        console.log(this.recordId);
        init({
            recordId: this.recordId
        }).then(result => {
            this.IsLoading = false;
            if (result != null) {
                if (result.opdStayOrNot == '已离职') {
                    this.showToast('所有人已经离职,请联系系统管理员修改所有人。','warning');
                    return;
                }
                if (result.opdIFApproved == true && result.opdApprovedNo == ''){
                this.showToast('需要决裁时,决裁编码不能为空','warning');
                return;
                }
                if (result.opdIFApproved == true && result.opdApprovedNo != '' && result.opdStatusProcessState.indexOf(result.opdApprovedStatus)!= -1 && result.opdApprovedStatus != '草稿' ){
                this.showToast('已申请决裁但决裁状态不符合条件','warning');
                return;
                }
                var HaveValue = "{!OPDPlan__c.Rental_Apply2__c}";
                if (result.opdRentalApply2 != '' && result.opdType != '学会') {
                this.showToast('一个OPD计划只可关联创建一个备品申请单','warning');
                return;
                }
                if (result.opdStatus != '计划中') {
                this.showToast('OPD计划的状态不是计划中,不能新建备品借出申请','warning');
                return;
                }
                UserInfo_Owner({}).then(res=>{
                    if(res.isFormalStuff == 'true'){
                        this.showToast('试用期内,不能申请','warning');
                        return;
                    }
                    if (result.opdType == '学会' && result.opdCampaignId != '') {
                        if (result.opdRentalApplyFlag < 7) {
                        this.showToast("申请提交必须在7天(含)以上才可以",'warning');
                        return;
                        }
                        var ups = res.userProvince.slice(0, 2);
                        if (result.opdCampaignTypeId != '01210000000R26P' && res.userJobCategory == '销售服务' ) {
                        this.showToast('FSE不能申请该学会类型备品','warning');
                        return;
                        } else if ((res.userJobCategory == '销售服务' || res.userJobCategory == '支援') && result.opdCampaignTypeId == '01210000000R26P' && result.opdInternalinchargeprovince.indexOf(ups) == -1) {
                        this.showToast("与FSE所在省一致,才可使用备品",'warning');
                        return;
                        } else if (result.opdCampaignStatus == '已结束') {
                        this.showToast("已结束,不能申请",'warning');
                        return;
                        } else if (result.opdCampaignStatus == '已提交报告') {
                        this.showToast("已提交报告,不能申请",'warning');
                        return;
                        } else if (result.opdCampaignStatus == '取消申请中') {
                        this.showToast("取消申请中,不能申请",'warning');
                        return;
                        } else if (result.opdCampaignStatus == '取消') {
                        this.showToast("已经取消,不能申请",'warning');
                        return;
                        }
                    }
                    if (result.opdOriginalOpdPlan == '') {
                        const defaultValues = null;
                        if (result.opdOriginalOpdPlanApplication == '') {
                            if (result.opdType == '学会' && result.opdCampaignId != '') {
                                // var purposeStr = '&00N10000003Msk0=产品试用' +
                                // '&00N10000003Msk5=学会展会' +
                                // '&CF00N10000003Mp2q_lkid={!URLENCODE(OPDPlan__c.CampaignId__c)}' +
                                // '&CF00N10000003Mp2q={!URLENCODE(OPDPlan__c.CampaignName__c)}';
                                defaultValues = encodeDefaultFieldValues({
                                    // OPDPlan__c:this.recordId,
                                    Demo_purpose1__c:'产品试用',
                                    demo_purpose2__c:'学会展会',
                                    Campaign__c:result.opdCampaign,
                                    Account__c:result.opdAccountLaboratory,
                                    Strategic_dept__c:result.opdOCMcategoryName,
                                    Hospital__c:result.opdHospitalName,
                                    OPDPlan__c:opdName,
                                    Person_In_Charge__c:res.lastName + res.firstName,
                                    applyUser__c:res.lastName + res.firstName,
                                    Loaner_received_staff__c:res.lastName + res.firstName,
                                    IsJump__c:result.opdIsJump,
                                    JumpCause__c:result.opdJumpCause,
                                    Name:'*',
                                    Approved_State_Create__c:result.ApprovedStatus,
                                    ApprovedNo_Create__c:result.opdApprovedNo
                                });
                            } else if (result.opdOpportunityId != '') {
                                // var purposeStr = '&00N10000003Msk0=产品试用' +
                                // '&00N10000003Msk5=试用(有询价)' +
                                // '&CF00N10000003O3VB_lkid={!OPDPlan__c.Related_Opportunity1_IDId__c}' +
                                // '&CF00N10000003O3VB={!HTMLENCODE(OPDPlan__c.Related_Opportunity1_Name__c)}';
                                defaultValues = encodeDefaultFieldValues({
                                    // OPDPlan__c:this.recordId,
                                    Demo_purpose1__c:'产品试用',
                                    demo_purpose2__c:'试用(有询价)',
                                    Follow_UP_Opp__c:result.opdRelatedOpportunity1Name,
                                    Account__c:result.opdAccountLaboratory,
                                    Strategic_dept__c:result.opdOCMcategoryName,
                                    Hospital__c:result.opdHospitalName,
                                    OPDPlan__c:opdName,
                                    Person_In_Charge__c:res.lastName + res.firstName,
                                    applyUser__c:res.lastName + res.firstName,
                                    Loaner_received_staff__c:res.lastName + res.firstName,
                                    IsJump__c:result.opdIsJump,
                                    JumpCause__c:result.opdJumpCause,
                                    Name:'*',
                                    Approved_State_Create__c:result.ApprovedStatus,
                                    ApprovedNo_Create__c:result.opdApprovedNo
                                });
                            } else {
                                // var purposeStr = '&00N10000003Msk0=产品试用' +
                                // '&00N10000003Msk5=试用(无询价)' +
                                // '&00N100000098amW={!OPDPlan__c.NoOpp_Reason__c}';
                                defaultValues = encodeDefaultFieldValues({
                                    // OPDPlan__c:this.recordId,
                                    Demo_purpose1__c:'产品试用',
                                    demo_purpose2__c:'试用(有询价)',
                                    NoOpp_Reason__c:result.opdNoOppReason,
                                    Account__c:result.opdAccountLaboratory,
                                    Strategic_dept__c:result.opdOCMcategoryName,
                                    Hospital__c:result.opdHospitalName,
                                    OPDPlan__c:opdName,
                                    Person_In_Charge__c:res.lastName + res.firstName,
                                    applyUser__c:res.lastName + res.firstName,
                                    Loaner_received_staff__c:res.lastName + res.firstName,
                                    IsJump__c:result.opdIsJump,
                                    JumpCause__c:result.opdJumpCause,
                                    Name:'*',
                                    Approved_State_Create__c:result.ApprovedStatus,
                                    ApprovedNo_Create__c:result.opdApprovedNo
                                });
                            }
                            // var urlStr = '&CF00N10000003Mp2R={!HTMLENCODE(OPDPlan__c.Account_Laboratory__c)}' +
                            // '&CF00N10000003O3V6={!HTMLENCODE(OPDPlan__c.OCM_category_Name__c)}' +
                            // '&CF00N10000003Mp1d={!HTMLENCODE(OPDPlan__c.HospitalName__c)}' +
                            // '&CF00N10000008ps61={!HTMLENCODE(OPDPlan__c.Name)}' +
                            // '&CF00N10000005HzRr={!URLENCODE($User.LastName&' '&$User.FirstName)}' +
                            // '&CF00N10000005HzRz={!URLENCODE($User.LastName&' '&$User.FirstName)}' +
                            // '&00N10000003OJzc={!URLENCODE($User.LastName&' '&$User.FirstName)}' +
                            // '&00N100000098dmS={!OPDPlan__c.IsJump__c}' +
                            // '&00N100000098dmI={!HTMLENCODE(OPDPlan__c.JumpCause__c)}' +
                            // '&Name=*'+
                            // '&00N10000009HBWg= {!OPDPlan__c.Approved_Status__c} ' +
                            // '&00N10000009HBXK= {!OPDPlan__c.Approved_No__c} '; //// 20220211 sx add 备品借出申请-决裁控制 No.2
                            // window.open('/a0t/e?retURL=%2F{!OPDPlan__c.Id}' + purposeStr + urlStr );
                            this[NavigationMixin.Navigate]({
                                type: 'standard__objectPage',
                                attributes: {
                                    objectApiName: 'Rental_Apply__c',
                                    actionName: 'new'
                                },
                                state:{
                                    defaultFieldValues: this.defaultValues,
                                }
                            })
                        } else {
                            defaultValues = encodeDefaultFieldValues({
                                // OPDPlan__c:this.recordId,
                                Cancel_Reason__c:'',
                                Loaner_cancel_reason__c:'',
                                Loaner_cancel_request__c:'',
                                Request_demo_time__c:'',
                                Request_approval_time__c:'',
                                Application_accept_time__c:'',
                                Response__c:'',
                                Status__c:'草案中',
                                Zsq_Rental_Apply__c:result.opdRentalApplyName,
                                OPDPlan__c:result.opdName,
                                Assign_Person__c:'',
                                Old_Rental_Apply__c:'',
                                Split_Apply_Reason__c:''
                            });
                            this[NavigationMixin.Navigate]({
                                type: 'standard__objectPage',
                                attributes: {
                                    objectApiName: 'Rental_Apply__c',
                                    actionName: 'new'
                                },
                                state:{
                                    defaultFieldValues: this.defaultValues,
                                }
                            })
                            // var url = "/{!OPDPlan__c.originalOpdRentalApply__c}/e?newclone=1&retURL=%2F{!OPDPlan__c.originalOpdRentalApply__c}&common.udd.actions.ActionsUtilORIG_URI=%2F{!OPDPlan__c.RentalApplyId__c}%2Fe&cloneli=1&00N10000007MNF8=&00N100000098uKJ=&00N10000004oFTC=&00N10000003O1JF=&00N10000003O1JK=&00N10000006pvpZ=&00N10000003O1JU=&00N10000006gY9x=&00N10000003Mp2H=草案中&CF00N10000009EKKp_lkid={!OPDPlan__c.RentalApplyId__c}&CF00N10000009EKKp={!OPDPlan__c.RentalApplyName__c}&CF00N10000008ps61={!OPDPlan__c.Name}&CF00N10000008ps61_lkid={!OPDPlan__c.Id}&CF00N10000008poFM=&CF00N10000008poFM_lkid=&CF00N10000005HzRq=&CF00N10000005HzRq_lkid=&00N10000007oQKh=";
                            // window.open(url);
                        }
                    }else {
                        defaultValues = encodeDefaultFieldValues({
                            // OPDPlan__c:this.recordId,
                            Cancel_Reason__c:'',
                            Loaner_cancel_reason__c:'',
                            Loaner_cancel_request__c:'',
                            Request_shipping_day__c:'',
                            Hope_Lonaer_date_Num__c:'',
                            Request_return_day__c:'',
                            Status__c:'草案中',
                            Zsq_Rental_Apply__c:result.opdRentalApplyName,
                            OPDPlan__c:result.opdName,
                            Assign_Person__c:'',
                            Old_Rental_Apply__c:'',
                            Split_Apply_Reason__c:''
                        });
                        this[NavigationMixin.Navigate]({
                            type: 'standard__objectPage',
                            attributes: {
                                objectApiName: 'Rental_Apply__c',
                                actionName: 'new'
                            },
                            state:{
                                defaultFieldValues: this.defaultValues,
                            }
                        })
                    //     var url = "/{!OPDPlan__c.RentalApplyId__c}/e?newclone=1&retURL=%2F{!OPDPlan__c.RentalApplyId__c}&common.udd.actions.ActionsUtilORIG_URI=%2F{!OPDPlan__c.RentalApplyId__c}%2Fe&cloneli=1&00N10000007MNF8=&00N100000098uKJ=&00N10000004oFTC=&00N10000003Ntz7=&00N10000008rG1M=&00N10000005HzRw=&00N10000003Mp2H=草案中&CF00N10000009EKKp_lkid={!OPDPlan__c.RentalApplyId__c}&CF00N10000009EKKp={!OPDPlan__c.RentalApplyName__c}&CF00N10000008ps61={!OPDPlan__c.Name}&CF00N10000008ps61_lkid={!OPDPlan__c.Id}&CF00N10000008poFM=&CF00N10000008poFM_lkid=&CF00N10000005HzRq=&CF00N10000005HzRq_lkid=&00N10000007oQKh=";
                    //     window.open(url);
                    }
                })
                this.dispatchEvent(new CloseActionScreenEvent());
                // window.location.reload();
            }
        }).catch(error => {
            console.log("error");
            console.log(error);
        });
    }
    showToast(message, type) {
        const evt = new ShowToastEvent({
            title: '',
            message: message,
            variant: type
        });
        this.dispatchEvent(evt);
    }
}
force-app/main/default/lwc/lexNewSparePartsLoanApplication/lexNewSparePartsLoanApplication.js-meta.xml
New file
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>56.0</apiVersion>
    <isExposed>true</isExposed>
    <targets>
        <target>lightning__RecordPage</target>
        <target>lightning__AppPage</target>
        <target>lightning__HomePage</target>
        <target>lightning__RecordAction</target>
    </targets>
</LightningComponentBundle>