From 2d3a04ebf1a594f6f60e48a25db356ba89f531ec Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@prec-tech.com>
Date: 星期二, 06 六月 2023 11:07:31 +0800
Subject: [PATCH] 新建耗材申请(客户)

---
 force-app/main/default/classes/lexConsumApply_FromAccountCtl.cls                             |   71 +++++++++++++++++
 force-app/main/default/lwc/lexConsumApply_FromAccount/lexConsumApply_FromAccount.html        |    5 +
 force-app/main/default/lwc/lexConsumApply_FromAccount/lexConsumApply_FromAccount.js-meta.xml |   20 +++++
 force-app/main/default/lwc/lexConsumApply_FromAccount/lexConsumApply_FromAccount.js          |   97 ++++++++++++++++++++++++
 force-app/main/default/classes/lexConsumApply_FromAccountCtl.cls-meta.xml                    |    5 +
 5 files changed, 198 insertions(+), 0 deletions(-)

diff --git a/force-app/main/default/classes/lexConsumApply_FromAccountCtl.cls b/force-app/main/default/classes/lexConsumApply_FromAccountCtl.cls
new file mode 100644
index 0000000..d360ecb
--- /dev/null
+++ b/force-app/main/default/classes/lexConsumApply_FromAccountCtl.cls
@@ -0,0 +1,71 @@
+public with sharing class lexConsumApply_FromAccountCtl {
+    public lexConsumApply_FromAccountCtl() {
+
+    }
+    @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 {
+            Account rep = [select Id,Name,Hospital__c,Department_Class__c from Account where Id =: recordId];
+            res.name = rep.Name;
+            res.hospitalName = rep.Hospital__c;
+            res.departClass = rep.Department_Class__c;
+            return res;
+        } catch (Exception e) {
+            throw new AuraHandledException(e.getMessage());
+        }
+    }
+    public class InitData{
+        @AuraEnabled
+        public String hospitalName;
+        @AuraEnabled
+        public String departClass;
+        @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;
+    }
+}
\ No newline at end of file
diff --git a/force-app/main/default/classes/lexConsumApply_FromAccountCtl.cls-meta.xml b/force-app/main/default/classes/lexConsumApply_FromAccountCtl.cls-meta.xml
new file mode 100644
index 0000000..45cccbd
--- /dev/null
+++ b/force-app/main/default/classes/lexConsumApply_FromAccountCtl.cls-meta.xml
@@ -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>
\ No newline at end of file
diff --git a/force-app/main/default/lwc/lexConsumApply_FromAccount/lexConsumApply_FromAccount.html b/force-app/main/default/lwc/lexConsumApply_FromAccount/lexConsumApply_FromAccount.html
new file mode 100644
index 0000000..ae58c6c
--- /dev/null
+++ b/force-app/main/default/lwc/lexConsumApply_FromAccount/lexConsumApply_FromAccount.html
@@ -0,0 +1,5 @@
+<template>
+    <div class="dispatchOCSMQARAHolder" if:true={IsLoading}>
+        <lightning-spinner alternative-text="Loading" size="medium"></lightning-spinner>
+    </div>
+</template>
\ No newline at end of file
diff --git a/force-app/main/default/lwc/lexConsumApply_FromAccount/lexConsumApply_FromAccount.js b/force-app/main/default/lwc/lexConsumApply_FromAccount/lexConsumApply_FromAccount.js
new file mode 100644
index 0000000..161d51d
--- /dev/null
+++ b/force-app/main/default/lwc/lexConsumApply_FromAccount/lexConsumApply_FromAccount.js
@@ -0,0 +1,97 @@
+import { LightningElement,wire,track,api} from 'lwc';
+import { CurrentPageReference, NavigationMixin} from "lightning/navigation";
+import { CloseActionScreenEvent } from 'lightning/actions';
+import  init  from '@salesforce/apex/lexConsumApply_FromAccountCtl.init';
+import  fieldDefineApp  from '@salesforce/apex/lexConsumApply_FromAccountCtl.fieldDefineApp';
+import UserInfo_Owner from '@salesforce/apex/lexConsumApply_FromAccountCtl.UserInfo_Owner';
+import { ShowToastEvent } from 'lightning/platformShowToastEvent';
+import { encodeDefaultFieldValues } from 'lightning/pageReferenceUtils';
+
+export default class LexConsumApply_FromAccount 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({
+                        Hospital__c:result.hospitalName,
+                        Strategic_dept__c:result.departClass,
+                        Account__c:result.name,
+                        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);
+    }
+
+}
\ No newline at end of file
diff --git a/force-app/main/default/lwc/lexConsumApply_FromAccount/lexConsumApply_FromAccount.js-meta.xml b/force-app/main/default/lwc/lexConsumApply_FromAccount/lexConsumApply_FromAccount.js-meta.xml
new file mode 100644
index 0000000..622f243
--- /dev/null
+++ b/force-app/main/default/lwc/lexConsumApply_FromAccount/lexConsumApply_FromAccount.js-meta.xml
@@ -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>
\ No newline at end of file

--
Gitblit v1.9.1