From ddb0231ef7c5cf2bad9d3f1afc2f733674ad38a5 Mon Sep 17 00:00:00 2001
From: unknown <sunxia@prec-tech.com>
Date: 星期四, 24 八月 2023 14:50:51 +0800
Subject: [PATCH] 再修理按钮

---
 force-app/main/default/lwc/lexLoanerArrangedEmail/lexLoanerArrangedEmail.js |   93 +++++++++++++++++++++++++++++-----------------
 1 files changed, 59 insertions(+), 34 deletions(-)

diff --git a/force-app/main/default/lwc/lexLoanerArrangedEmail/lexLoanerArrangedEmail.js b/force-app/main/default/lwc/lexLoanerArrangedEmail/lexLoanerArrangedEmail.js
index 3916190..4e09ac0 100644
--- a/force-app/main/default/lwc/lexLoanerArrangedEmail/lexLoanerArrangedEmail.js
+++ b/force-app/main/default/lwc/lexLoanerArrangedEmail/lexLoanerArrangedEmail.js
@@ -1,11 +1,13 @@
 import { LightningElement, track, wire, api } from 'lwc';
 import { CurrentPageReference,NavigationMixin } from 'lightning/navigation';
 import { CloseActionScreenEvent } from 'lightning/actions';
+import { ShowToastEvent } from 'lightning/platformShowToastEvent';
+import { updateRecord } from 'lightning/uiRecordApi';
 
-import init from '@salesforce/apex/loanerArrangedEmailController.init';
-import getRentalApplyEquipmentSet from '@salesforce/apex/loanerArrangedEmailController.getRentalApplyEquipmentSet';
+import init from '@salesforce/apex/LexLoanerArrangedEmailController.init';
+import getRentalApplyEquipmentSet from '@salesforce/apex/LexLoanerArrangedEmailController.getRentalApplyEquipmentSet';
 import approvalCheck from '@salesforce/apex/RentalApplyWebService.approvalCheck';
-import setShipment_request from '@salesforce/apex/RentalApplyWebService.approvalCheck';
+import setShipment_request from '@salesforce/apex/RentalApplyWebService.setShipment_request';
 export default class lexLoanerArrangedEmail extends LightningElement {
 	@api recordId;
 	IsLoading = true;
@@ -22,52 +24,60 @@
 	}
 
 	connectedCallback() {
+
 		init({
 			recordId: this.recordId
 		}).then(result => {
-			console.log(this.recordId);
+			let id = result.id;
+			let statusArr = result.statusList;
 			console.log('result==='+JSON.stringify(result));
 			if(result != null) {
-				if( result.WeiAssignedCnt > 0 ) {
-					alert("鐢宠鍗曞唴瀛樺湪鏈垎閰嶇殑閰嶅锛岃鍒嗛厤澶囧搧鎴栧垎鍓茬敵璇峰崟");
-				}else if(result.CampaignStatus == "鍙栨秷") {
-					alert("瀛︿細鍙栨秷锛屼笉鍙嚭搴撴寚绀�"); 
-				}else if (result.RaStatus == "宸插嚭搴撴寚绀�" && result.AssignedNotShipment == 0){
-					alert("鎵�鏈夌殑鍊熷嚭澶囧搧Set涓�瑙堥兘杩涜杩囧嚭搴撴寚绀轰簡");
-				}else if (result.AssignedNotShipment == 0) {
-					alert("娌℃湁鍙互鍑哄簱鎸囩ず鐨勬槑缁�"); 
-				}else if (result.DemoPurpose1 == "闀挎湡鍊熷嚭" && result.ContractPdfUpdated == 0){
-					alert("闀挎湡鍊熷嚭鏃讹紝蹇呴』鍏堜笂浼犲绾︿功"); 
-				}else if (result.RepairId != '' && (result.RepairFinalInspectionDateF != null && result.RepairFinalInspectionDateF != '') || (result.RCReturnToOffice != null && result.RCReturnToOffice != '')){
-					alert("淇悊鏈夋渶缁堟娴嬫棩鎴栦慨鐞嗗搧杩旈�佹棩锛屼笉鍙嚭搴撴寚绀�"); 
-				}else if (result.IFApproved == "true" && (result.MeetingApprovedNo == null || result.MeetingApprovedNo == "")){
-					alert("娌℃湁鍐宠鍙风殑锛屾殏涓嶈兘鍑哄��,璇锋洿鏂拌鍐充俊鎭��"); 
-				}else if (result.IFApproved == "true" && result.MeetingApprovedNo != "" && result.StatusList.indexOf(records[0].Approved_Status__c) != -1){
-					alert("宸茬敵璇峰喅瑁佷絾鍐宠鐘舵�佷笉绗﹀悎鏉′欢銆�"); 
-				}else {
+				if( result.weiAssignedCnt > 0 ) {
+					this.showToast("鐢宠鍗曞唴瀛樺湪鏈垎閰嶇殑閰嶅锛岃鍒嗛厤澶囧搧鎴栧垎鍓茬敵璇峰崟",'error');
+				}else if(result.campaignStatus == "鍙栨秷") {
+					this.showToast("瀛︿細鍙栨秷锛屼笉鍙嚭搴撴寚绀�",'error');
+				}else if (result.raStatus == "宸插嚭搴撴寚绀�" && result.assignedNotShipment == 0){
+					this.showToast("鎵�鏈夌殑鍊熷嚭澶囧搧Set涓�瑙堥兘杩涜杩囧嚭搴撴寚绀轰簡",'error');
+				}else if (result.assignedNotShipment == 0) {
+					this.showToast("娌℃湁鍙互鍑哄簱鎸囩ず鐨勬槑缁�",'error');
+				}else if (result.demoPurpose1 == "闀挎湡鍊熷嚭" && result.contractPdfUpdated == false){
+					this.showToast("闀挎湡鍊熷嚭鏃讹紝蹇呴』鍏堜笂浼犲绾︿功",'error');
+				}else if (result.repairId != '' && (result.repairFinalInspectionDateF != null && result.repairFinalInspectionDateF != '') || (result.rCReturnToOffice != null && result.rCReturnToOffice != '')){
+					this.showToast("淇悊鏈夋渶缁堟娴嬫棩鎴栦慨鐞嗗搧杩旈�佹棩锛屼笉鍙嚭搴撴寚绀�",'error');
+				}else if (result.iFApproved == true && (result.meetingApprovedNo == null || result.meetingApprovedNo == "")){
+					this.showToast("娌℃湁鍐宠鍙风殑锛屾殏涓嶈兘鍑哄��,璇锋洿鏂拌鍐充俊鎭��",'error');
+				}else if (result.iFApproved == true && result.meetingApprovedNo != "" && statusArr.indexOf(result.approvedStatus) != -1){
+					this.showToast("宸茬敵璇峰喅瑁佷絾鍐宠鐘舵�佷笉绗﹀悎鏉′欢銆�",'error');
+				}else{
 					approvalCheck({
 						rentalApplyId: this.recordId
-					}).then(res=>{
-						if (res != '1') {
-							alert(rs1);
-						} else {
+					}).then(res1 =>{
+						if (res1 != '1') {
+							this.showToast(res1,'error');
+						}else{
 							//bp2 var rs2 = sforce.apex.execute("RentalApplyWebService", "reserve", {rentalApplyId: raid});
 							//bp2 if (rs2 != '1') {
 							//bp2 alert(rs2);
 							//bp2 } else {
 							//var rs1 = sforce.apex.execute("RentalApplyWebService", "setShipment_request", {raid : "{!Rental_Apply__c.Id}"}); 
-
 							setShipment_request({
 								raid: this.recordId
 							}).then(res=>{
-								if (res == "鐘舵�佹洿鏂板埌宸插嚭搴撴寚绀�") { 
-									alert("鐘舵�佹洿鏂板埌宸插嚭搴撴寚绀�");
+								console.log('res==',res);
+								if (res == '鐘舵�佹洿鏂板埌宸插嚭搴撴寚绀�') {
+									this.showToast('鐘舵�佹洿鏂板埌宸插嚭搴撴寚绀�','success');
 									print();
-									setTimeout(function() {
-										location.href = "/{!Rental_Apply__c.Id}"; 
-									},100);
+									this.updateRecordView(this.recordId);
+									return;
 								}else {
-									alert(res);
+									console.log('else==',res);
+									 const evt = new ShowToastEvent({
+					                    title: 'Error',
+					                    message:res,
+					                    variant: 'error'
+					                });
+					                this.dispatchEvent(evt);
+					                this.dispatchEvent(new CloseActionScreenEvent());
 								}
 							}).catch(e=>{
 								console.log('approvalCheck==='+e);
@@ -77,7 +87,6 @@
 						console.log('setShipment_request==='+e);
 					})				
 				}
-				this.dispatchEvent(new CloseActionScreenEvent());
 			}
 		})
 	}
@@ -86,7 +95,7 @@
 		getRentalApplyEquipmentSet({
 			recordId: this.recordId
 		}).then(result => {
-			window.open("https://ocsm--partial.sandbox.lightning.force.com/apex/FixtureRentalPDF?raid=" + this.recordId + "&page=" + result);
+			window.open("/apex/FixtureRentalPDF?raid=" + this.recordId + "&page=" + result);
 		})
 	}
 
@@ -99,4 +108,20 @@
 		var Seconds = fixTime(date.getSeconds());
 		return date.getFullYear() + "-" + Month + "-" + Day + "T" + Time;
 	}
+
+	showToast(msg,type) {
+        const event = new ShowToastEvent({
+            message: msg,
+            variant: type
+        });
+        if(type == 'success'){
+            this.updateRecordView(this.recordId);
+        }
+        this.dispatchEvent(event);
+        this.dispatchEvent(new CloseActionScreenEvent());
+    }
+
+    updateRecordView(recordId) {
+        updateRecord({fields: { Id: recordId }});
+    }
 }
\ No newline at end of file

--
Gitblit v1.9.1