zhangqian
2023-06-02 9322dd73bd4a7085cc406dc6ff3908d9da35e02c
新建耗材申请(OPD计划)

新建耗材申请(OPD计划)
5个文件已添加
210 ■■■■■ 已修改文件
force-app/main/default/classes/lexConsumApply_FromOPDPlanCtl.cls 81 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
force-app/main/default/classes/lexConsumApply_FromOPDPlanCtl.cls-meta.xml 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
force-app/main/default/lwc/lexConsumApply_FromOPDPlan/lexConsumApply_FromOPDPlan.html 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
force-app/main/default/lwc/lexConsumApply_FromOPDPlan/lexConsumApply_FromOPDPlan.js 99 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
force-app/main/default/lwc/lexConsumApply_FromOPDPlan/lexConsumApply_FromOPDPlan.js-meta.xml 20 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
force-app/main/default/classes/lexConsumApply_FromOPDPlanCtl.cls
New file
@@ -0,0 +1,81 @@
public with sharing class lexConsumApply_FromOPDPlanCtl {
    public lexConsumApply_FromOPDPlanCtl() {
    }
    @AuraEnabled
    public static List<FieldDefinition> fieldDefineApp(){
        try {
            List<FieldDefinition> rep = [Select QualifiedApiName, EntityDefinition.KeyPrefix, DurableId From FieldDefinition WHERE EntityDefinition.QualifiedApiName = 'Consum_Apply__c'];
            return rep;
        } catch (Exception e) {
            throw new AuraHandledException(e.getMessage());
        }
    }
    //获取当前登录人的 id
    @AuraEnabled
    public static UserResult UserInfo_Owner() {
        UserResult result = new UserResult();
        ID myUserID = UserInfo.getUserId();
        try {
            User tempUser =
                [select Id,isFormal_Stuff__c,FirstName,LastName from user where id = : myUserID ];
            result.id = tempUser.Id;
            result.isFormalStuff = tempUser.isFormal_Stuff__c;
            result.firstName = tempUser.FirstName;
            result.lastName = tempUser.LastName;
        } 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,OPDPlan_Report__c,Name,Rental_Apply2__c,HospitalName__c,OCM_category_Name__c,Account_Laboratory__c from OPDPlan__c where Id =: recordId];
            res.opdPlan = rep.OPDPlan_Report__c;
            res.name = rep.Name;
            res.rentalApply2 = rep.Rental_Apply2__c;
            res.hospitalName = rep.HospitalName__c;
            res.ocmCategoryName = rep.OCM_category_Name__c;
            res.accountLab = rep.Account_Laboratory__c;
            return res;
        } catch (Exception e) {
            throw new AuraHandledException(e.getMessage());
        }
    }
    public class InitData{
        @AuraEnabled
        public String opdPlan;
        @AuraEnabled
        public String rentalApply2;
        @AuraEnabled
        public String hospitalName;
        @AuraEnabled
        public String ocmCategoryName;
        @AuraEnabled
        public String accountLab;
        @AuraEnabled
        public String name;
    }
    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;
    }
}
force-app/main/default/classes/lexConsumApply_FromOPDPlanCtl.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/lexConsumApply_FromOPDPlan/lexConsumApply_FromOPDPlan.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/lexConsumApply_FromOPDPlan/lexConsumApply_FromOPDPlan.js
New file
@@ -0,0 +1,99 @@
import { LightningElement,wire,track,api} from 'lwc';
import { CurrentPageReference, NavigationMixin} from "lightning/navigation";
import { CloseActionScreenEvent } from 'lightning/actions';
import  init  from '@salesforce/apex/lexConsumApply_FromOPDPlanCtl.init';
import  fieldDefineApp  from '@salesforce/apex/lexConsumApply_FromOPDPlanCtl.fieldDefineApp';
import UserInfo_Owner from '@salesforce/apex/lexConsumApply_FromOPDPlanCtl.UserInfo_Owner';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import { encodeDefaultFieldValues } from 'lightning/pageReferenceUtils';
export default class LexConsumApply_FromOPDPlan 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=>{
            UserInfo_Owner({}).then(res=>{
                if(res.isFormalStuff == 'true'){
                    this.showToast('试用期内,不能申请','warning');
                    return;
                }else{
                    fieldDefineApp({}).then(resp=>{
                        var fieldmap = new Map();
                        for (var i=0; i< resp.length; i++) {
                            var record = resp[i];
                            fieldmap.set(record.QualifiedApiName,record.DurableId.toString().split('.')[1]);
                        }
                    })
                    .catch(e=>{console.log(e)})
                    const defaultValues = encodeDefaultFieldValues({
                        OPD__c: result.opdPlan,
                        OPDPlan__c: result.name,
                        Rental_Apply__c:result.rentalApply2,
                        Hospital__c:result.hospitalName,
                        Strategic_dept__c:result.ocmCategoryName,
                        Account__c:result.accountLab,
                        Name:'*',
                        demo_purpose2__c:'OPD试用',
                        Person_In_Charge__c:res.lastName + res.firstName,
                        applyUser__c:res.lastName + res.firstName
                    });
                    this[NavigationMixin.Navigate]({
                        type: 'standard__objectPage',
                        attributes: {
                            objectApiName: 'Consum_Apply__c',
                            actionName: 'new'
                        },
                        state:{
                            defaultFieldValues: this.defaultValues
                        }
                    })
                }
            })
            .catch(error => {
                console.log("error");
                console.log(error);
            })
        })
        .catch(error => {
            console.log("error");
            console.log(error);
        }).finally(() => {
            this.dispatchEvent(new CloseActionScreenEvent());
        });
    }
    showToast(message, type) {
        const evt = new ShowToastEvent({
            title: '',
            message: message,
            variant: type
        });
        this.dispatchEvent(evt);
    }
}
force-app/main/default/lwc/lexConsumApply_FromOPDPlan/lexConsumApply_FromOPDPlan.js-meta.xml
New file
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata" fqn="lexEquipmentRentalApply_FromSA">
    <apiVersion>56.0</apiVersion>
    <isExposed>true</isExposed>
    <targets>
        <target>lightning__AppPage</target>
        <target>lightning__RecordPage</target>
        <target>lightning__HomePage</target>
        <target>lightning__RecordAction</target>
        <!-- 屏幕流配置 -->
        <target>lightning__FlowScreen</target>
    </targets>
    <!-- 定义变量 -->
    <targetConfigs>
        <targetConfig targets="lightning__FlowScreen">
            <!-- name js中使用的变量,从屏幕流中获取参数  label 在屏幕流的该LWC的设置中显示 -->
            <property name="recordId" type="String" label="recordId"/>
        </targetConfig>
    </targetConfigs>
</LightningComponentBundle>