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/lexOCSMNoToReportRepair/lexOCSMNoToReportRepair.js |   73 ++++++++++++++++++++----------------
 1 files changed, 40 insertions(+), 33 deletions(-)

diff --git a/force-app/main/default/lwc/lexOCSMNoToReportRepair/lexOCSMNoToReportRepair.js b/force-app/main/default/lwc/lexOCSMNoToReportRepair/lexOCSMNoToReportRepair.js
index 44ef2be..1712fda 100644
--- a/force-app/main/default/lwc/lexOCSMNoToReportRepair/lexOCSMNoToReportRepair.js
+++ b/force-app/main/default/lwc/lexOCSMNoToReportRepair/lexOCSMNoToReportRepair.js
@@ -14,6 +14,7 @@
 import {
     ShowToastEvent
 } from 'lightning/platformShowToastEvent';
+import LightningConfirm from 'lightning/confirm';
 
 export default class LexOCSMNoToReportRepair extends LightningElement {
     @api recordId;
@@ -42,52 +43,21 @@
         }).then(result => {
             console.log(result);
             if (result != null) {
-                this.IsLoading = false;
                 this.Id = result.Id;
                 this.OCSMAdministrativeReportNumberC = result.OCSMAdministrativeReportNumberC;
                 this.OCSMAdministrativeReportDateC = result.OCSMAdministrativeReportDateC;
                 this.AwareDateC = result.AwareDateC;
 
                 this.OCSMNoToReport();
-                this.dispatchEvent(new CloseActionScreenEvent());
             }
         }).catch(error => {
             console.log(error);
-        }).finally(() => {
-
-        });
+        })
     }
 
     // OCSM涓嶈鎶ュ憡
     OCSMNoToReport() {
-        if (!confirm("涓嶈鎶ュ憡鍚庢棤娉曟挙鍥烇紝鏄惁缁х画锛�")) {
-            return;
-        }
-
-        if (this.OCSMAdministrativeReportNumberC != undefined ||
-            this.OCSMAdministrativeReportDateC != undefined) {
-            this.ShowToastEvent("宸茬粡鎶ュ憡鐨凲IS锛屼笉鍙互鐐瑰嚮OCSM涓嶈鎶ュ憡銆�", "error")
-            // alert("宸茬粡鎶ュ憡鐨凲IS锛屼笉鍙互鐐瑰嚮OCSM涓嶈鎶ュ憡銆�");
-            return;
-        }
-
-        if (this.AwareDateC != undefined) {
-            updateRepair({
-                recordId: this.Id
-            }).catch(error => {
-                if (error.body.pageErrors.length > 0) {
-                    var errmsg = error.body.pageErrors[0].message.toString();
-                    this.ShowToastEvent(errmsg.join("\n"), "error")
-                    // alert(errmsg.join("\n"));
-                    return;
-                }
-            })
-            window.location.reload();
-        } else {
-            this.ShowToastEvent("娌℃湁AwareDate鎴栧凡缁廜CSM琛屾斂鎶ュ憡锛岃纭銆�", "error")
-            // alert("娌℃湁AwareDate鎴栧凡缁廜CSM琛屾斂鎶ュ憡锛岃纭銆�");
-            return;
-        }
+        this.handleConfirmClick("涓嶈鎶ュ憡鍚庢棤娉曟挙鍥烇紝鏄惁缁х画锛�");
     }
 
     // 寮圭獥
@@ -99,4 +69,41 @@
         });
         this.dispatchEvent(event);
     }
+
+    async handleConfirmClick(msg) {
+        const result = await LightningConfirm.open({
+            message: msg,
+            variant: 'headerless',
+            label: 'this is the aria-label value'
+        });
+
+        if (result) {
+            if (this.OCSMAdministrativeReportNumberC != undefined ||
+                this.OCSMAdministrativeReportDateC != undefined) {
+                this.ShowToastEvent("宸茬粡鎶ュ憡鐨凲IS锛屼笉鍙互鐐瑰嚮OCSM涓嶈鎶ュ憡銆�", "error");
+                this.dispatchEvent(new CloseActionScreenEvent());
+                return;
+            }
+            if (this.AwareDateC != undefined) {
+                updateRepair({
+                    recordId: this.Id
+                }).then(result => {
+                    console.log(result);
+                    if (result.length > 0) {
+                        var split = result.split(", ");
+                        this.ShowToastEvent(split[1], "error");
+                        this.dispatchEvent(new CloseActionScreenEvent());
+                        return;
+                    }
+                    window.location.reload();
+                })
+            } else {
+                this.ShowToastEvent("娌℃湁AwareDate鎴栧凡缁廜CSM琛屾斂鎶ュ憡锛岃纭銆�", "error");
+                this.dispatchEvent(new CloseActionScreenEvent());
+                return;
+            }
+        } else {
+            this.dispatchEvent(new CloseActionScreenEvent());
+        }
+    }
 }
\ No newline at end of file

--
Gitblit v1.9.1