From f0584331cc6a7e0ff0a38d18b2b7463492f92f23 Mon Sep 17 00:00:00 2001
From: KKbes <1620284052@qq.com>
Date: 星期五, 14 四月 2023 14:21:05 +0800
Subject: [PATCH] 备品set详细  选择借出按钮

---
 force-app/main/default/classes/SelectRentalButtonController.cls          |   95 +++++++++++++++++++
 force-app/main/default/lwc/lexSelectRental/lexSelectRental.js-meta.xml   |   11 ++
 force-app/main/default/lwc/lexSelectRental/lexSelectRental.css           |   11 ++
 force-app/main/default/lwc/lexSelectRental/lexSelectRental.js            |  136 +++++++++++++++++++++++++++
 force-app/main/default/classes/SelectRentalButtonController.cls-meta.xml |    5 +
 force-app/main/default/lwc/lexSelectRental/lexSelectRental.html          |    4 
 6 files changed, 262 insertions(+), 0 deletions(-)

diff --git a/force-app/main/default/classes/SelectRentalButtonController.cls b/force-app/main/default/classes/SelectRentalButtonController.cls
new file mode 100644
index 0000000..1c18872
--- /dev/null
+++ b/force-app/main/default/classes/SelectRentalButtonController.cls
@@ -0,0 +1,95 @@
+global with sharing class SelectRentalButtonController {
+   
+    @AuraEnabled
+    public static Equipment_Set_Detail__c  getEquipmentSetId(String recordId){
+        Equipment_Set_Detail__c res=new Equipment_Set_Detail__c();
+        try{
+            res=[select  Equipment_Set__c,Select_rental__c from Equipment_Set_Detail__c where Id=: recordId];
+        }
+        catch(Exception e){
+            System.debug(Logginglevel.info,'*******e'+e);
+        }
+        return res;
+
+    }
+
+
+
+
+
+
+
+   @AuraEnabled
+   public static List<Equipment_Set_Detail__c>  getEquipmentSet(String esid){
+   
+    try{
+         List<Equipment_Set_Detail__c>    res=[select Id,Name,Select_rental__c
+          from Equipment_Set_Detail__c
+           where Equipment_Set__c = : esid];
+         return res;
+    }
+    catch(Exception e){
+        System.debug(Logginglevel.info,'*******e'+e);
+    }
+   
+    return null;
+   }
+
+
+   @AuraEnabled
+   public static List<String>  updateEquipment(List<Equipment_Set_Detail__c> sqlResult){
+    List<String> res=new List<String>();
+    try{
+        for(Equipment_Set_Detail__c equipMent :  sqlResult){
+            update equipMent;
+            res.add('success');
+        }  
+    }
+    
+    catch(Exception e){
+        System.debug(Logginglevel.info,'*******e'+e);
+    }
+    return res;
+
+
+   }
+
+
+   @AuraEnabled
+   public static List<Equipment_Set_Detail__c> findIdArea(List<String> id){
+    List<Equipment_Set_Detail__c> res = new  List<Equipment_Set_Detail__c>();
+    try{
+        
+        res=[select Id,Select_rental__c from Equipment_Set_Detail__c where Id IN : id ];
+    }
+    catch (Exception e) {
+        System.debug(Logginglevel.info,'*******e'+e);
+    }
+    return res;
+   }
+
+
+   @AuraEnabled
+    public static String getSessionId(){
+        return UserInfo.getSessionId();
+    }
+
+    @AuraEnabled
+    public static List<String>  getRecords(){
+        List<String> res= new List<String>();
+
+        try{
+        List<Equipment_Set_Detail__c>    obj = [select Id  from Equipment_Set_Detail__c where Select_rental__c=true];
+            for(Equipment_Set_Detail__c equipMent : obj){
+                res.add(equipMent.Id);
+            }
+        }
+
+        catch(Exception e){
+              System.debug(Logginglevel.info,'*******e'+e);
+        }
+
+        return res;
+    }
+
+}
\ No newline at end of file
diff --git a/force-app/main/default/classes/SelectRentalButtonController.cls-meta.xml b/force-app/main/default/classes/SelectRentalButtonController.cls-meta.xml
new file mode 100644
index 0000000..d75b058
--- /dev/null
+++ b/force-app/main/default/classes/SelectRentalButtonController.cls-meta.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
+    <apiVersion>51.0</apiVersion>
+    <status>Active</status>
+</ApexClass>
diff --git a/force-app/main/default/lwc/lexSelectRental/lexSelectRental.css b/force-app/main/default/lwc/lexSelectRental/lexSelectRental.css
new file mode 100644
index 0000000..89ffcef
--- /dev/null
+++ b/force-app/main/default/lwc/lexSelectRental/lexSelectRental.css
@@ -0,0 +1,11 @@
+.lexSelectRentalHolder{
+ position: relative;
+ display: inline-block;
+ width: 80px;
+ height: 80px;
+ text-align: center;
+}
+
+.container .uiContainerManager{
+ display : none !important;
+}
\ No newline at end of file
diff --git a/force-app/main/default/lwc/lexSelectRental/lexSelectRental.html b/force-app/main/default/lwc/lexSelectRental/lexSelectRental.html
new file mode 100644
index 0000000..c45065c
--- /dev/null
+++ b/force-app/main/default/lwc/lexSelectRental/lexSelectRental.html
@@ -0,0 +1,4 @@
+<template>
+<div class="lexSelectRentalHolder" if:true={IsLoding}>
+<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/lexSelectRental/lexSelectRental.js b/force-app/main/default/lwc/lexSelectRental/lexSelectRental.js
new file mode 100644
index 0000000..5afc145
--- /dev/null
+++ b/force-app/main/default/lwc/lexSelectRental/lexSelectRental.js
@@ -0,0 +1,136 @@
+import { LightningElement,api, track, wire } from 'lwc';
+import getEquipmentSetId  from '@salesforce/apex/SelectRentalButtonController.getEquipmentSetId';
+
+import getEquipmentSet  from '@salesforce/apex/SelectRentalButtonController.getEquipmentSet';
+
+import updateEquipment  from '@salesforce/apex/SelectRentalButtonController.updateEquipment';
+
+import getSessionId  from '@salesforce/apex/SelectRentalButtonController.getSessionId';
+
+import getRecords  from '@salesforce/apex/SelectRentalButtonController.getRecords';
+
+
+import findIdArea   from '@salesforce/apex/SelectRentalButtonController.findIdArea';
+import {CurrentPageReference} from 'lightning/navigation';
+import { CloseActionScreenEvent } from 'lightning/actions';
+export default class lexSelectRental extends LightningElement {
+
+	@api recordId;
+	IsLoading;
+	Equipment_Set_Detail__c;
+
+	@wire(CurrentPageReference)
+    getStateParameters(currentPageReference){
+    	if(currentPageReference){
+    		console.log(currentPageReference);
+    		console.log("杩涘叆鑾峰彇page鍙傛暟")
+    		const IdValue=currentPageReference.state.recordId;
+    		if(IdValue){
+    			let str=`${IdValue}`;
+    			this.recordId=str;
+    			console.log("recordId="+str);
+    		}
+    	}
+    }
+
+    connectedCallback(){
+        getEquipmentSetId({recordId:this.recordId}).then(res=>{
+        	if(res!=null){
+        	this.IsLoading=false;
+        	console.log("res");
+        	console.log(res);
+        	console.log("杩涘叆鍒濆鍖栧璞″叾浠栧睘鎬�");
+        	this.Equipment_Set_Detail__c=res;
+        	console.log(this.Equipment_Set_Detail__c);
+        	console.log(this.Equipment_Set_Detail__c.Select_rental__c);
+        	
+            this.SelectLending();
+        	}
+        	else{
+        		 let a="娌¤繘鏂规硶";
+     			console.log(a);
+        	}
+        }).catch(error =>{
+        	console.log("error");
+        	console.log(error.message);
+        }).finally(()=>{
+
+        });
+    }
+
+
+
+    async SelectLending(){
+
+
+    	try{
+            this.dispatchEvent(new CloseActionScreenEvent());
+            window.sforce = window.sforce || {};
+            window.sforce.connection = window.sforce.connection || {};
+            let a =await getSessionId();
+            window.sforce.connection.sessionId =await getSessionId();
+            console.log(a);
+            let esid = this.Equipment_Set_Detail__c.Equipment_Set__c;
+            console.log(esid);
+            //閫夋嫨鍊熷嚭鏄竴涓閫夋锛岃繖閲屽氨鏄壘澶嶉�夋鍕句笂鐨勬暟鎹甀d锛屼笉鐭ラ亾杩欎釜鎬庝箞鎺ュ彈浠庡墠绔┛鍙傛暟銆�
+            //鎵�浠ユ垜鐩存帴鏌ユ暟鎹簱
+            let esdids =new Array();
+            esdids=await getRecords();
+            console.log(esdids);
+            let hasError = false;
+            //鏇存柊鏁版嵁
+            if (esdids.length > 0) {
+            	console.log('杩涘叆绗竴涓猧f鏂规硶');
+                let sqlResult = await getEquipmentSet({esid:esid});
+                console.log(sqlResult);
+                console.log('杩斿洖瀵硅薄鏁扮粍绗竴涓�'+sqlResult[0]);
+                for (let i = 0; i < sqlResult.length; i++) {
+                    let esd = sqlResult[i];
+                    console.log(i);
+                    esd.Select_rental__c = false;
+                }
+                let result = await updateEquipment({sqlResult : sqlResult});
+                console.log(result);
+                for (let i=0; i<result.length; i++) {
+                    if (result[i]!="success") { 
+                        alert(result[i].errors.message);
+                        hasError = true;
+                        return;
+                    }
+
+      		    }
+                let EqObject = await findIdArea({id : esdids});
+                console.log(EqObject);
+                for (let i = 0; i < EqObject.length; i++) {
+                    let esd = EqObject[i];
+                    esd.Select_rental__c = true;
+                }
+                result = await updateEquipment({sqlResult : EqObject});
+                console.log(result);
+                for (let i=0; i<result.length; i++) {
+                    if (result[i]!="success") { 
+                        alert(result[i].errors.message);
+                        hasError = true;
+                        return;
+                    }
+                }
+        
+            if (!hasError) {
+                //window.top.location.reload;
+                //杩欓噷濂藉儚top涓嶅瓨鍦�
+                window.location.reload();
+
+            }
+        }
+
+        else {
+            alert("璇疯嚦灏戦�夋嫨涓�涓鍝乻et鏄庣粏銆�");
+        }
+    }
+        catch(e){
+            console.log(e);
+            alert(e.message);
+    }
+
+    }
+}
\ No newline at end of file
diff --git a/force-app/main/default/lwc/lexSelectRental/lexSelectRental.js-meta.xml b/force-app/main/default/lwc/lexSelectRental/lexSelectRental.js-meta.xml
new file mode 100644
index 0000000..c0a5ac1
--- /dev/null
+++ b/force-app/main/default/lwc/lexSelectRental/lexSelectRental.js-meta.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata" fqn="lexSelectRental">
+    <apiVersion>51.0</apiVersion>
+    <isExposed>true</isExposed>
+    <targets>
+        <target>lightning__AppPage</target>
+        <target>lightning__RecordPage</target>
+        <target>lightning__HomePage</target>
+        <target>lightning__RecordAction</target>
+    </targets>
+</LightningComponentBundle>
\ No newline at end of file

--
Gitblit v1.9.1