From 69dc5df6ec51f6f7f6737c61d9c4c1e7757a2b96 Mon Sep 17 00:00:00 2001
From: Li Jun <buli@deloitte.com.cn>
Date: 星期四, 17 三月 2022 21:05:08 +0800
Subject: [PATCH] PIPLFixBugs0317V1

---
 force-app/main/default/pages/UploadPdf.page |  123 ++++++++++++++++++++++++++++------------
 1 files changed, 85 insertions(+), 38 deletions(-)

diff --git a/force-app/main/default/pages/UploadPdf.page b/force-app/main/default/pages/UploadPdf.page
index 431ef8e..cc9e50b 100644
--- a/force-app/main/default/pages/UploadPdf.page
+++ b/force-app/main/default/pages/UploadPdf.page
@@ -1,6 +1,7 @@
 <!-- 璇ラ〉闈㈢敤浜嶭ead瀵硅薄涓婁紶PDF锛屾湭鏉ュ鏋滆娣诲姞鍏朵粬瀵硅薄鐨勪笂浼燩DF鍔熻兘锛屽鍒惰椤甸潰锛屽皢**standardController**淇敼涓哄叾浠栧璞PI鍚嶇О鍗冲彲 -->
 <apex:page standardController="Lead" extensions="FileUploadController" id="page" lightningStyleSheets="true">
     <apex:includeScript value="{! URLFOR($Resource.AWSService, 'AWSService.js') }" />
+    <apex:includeScript value="{!URLFOR($Resource.jquery183minjs)}"/>
     <script>
         var staticResources = JSON.parse('{!staticResource}');
         var parentId = '{!parentId}';
@@ -29,8 +30,8 @@
             return new Promise((resolve, reject) => {
                 const reader = new FileReader();
                 reader.readAsDataURL(file);
-                reader.onload = () => resolve(reader.result);
-                reader.onerror = error => reject(error);
+                reader.onload = function(){resolve(reader.result)} ;
+                reader.onerror =function(error){reject(error)};
             });
         }
         function disableButtonStatus() {
@@ -47,7 +48,7 @@
             disableButtonStatus();
             var fileObject = document.getElementById("file").files[0];
             getBase64(fileObject).then(
-                data => {
+               function(data) {
                     console.log(data);
                     uploadFileToAWS(data, (fileObject.size).toString(), fileObject.name);
                     
@@ -56,23 +57,31 @@
         }
         function confirmTrans(transId, isSuccess) {
             
-            fetch(staticResources.updateUrl, {
-                method: 'POST',
-                body: JSON.stringify({ 'txId': transId, "isSuccess": isSuccess }),
-                headers: {
-                    'Content-Type': 'application/json',
-                    'pi-token': staticResources.token
-                }
-            }).then((data) => {
-                return data.json();
-            }).then(data => {
-                console.log("confirmTrans-" + JSON.stringify(data));
-                document.getElementById("file").files[0].name = '';
-                enableButtonStatus();
-                refreshFiles();            
-                return data.status;
-            })
-            
+            // fetch(staticResources.updateUrl, {
+            //     method: 'POST',
+            //     body: JSON.stringify({ 'txId': transId, "isSuccess": isSuccess }),
+            //     headers: {
+            //         'Content-Type': 'application/json',
+            //         'pi-token': staticResources.token
+            //     }
+            // }).then(function(data) {
+            //     return data.json();
+            // }).then(function(data) {
+            //     console.log("confirmTrans-" + JSON.stringify(data));
+            //     document.getElementById("file").files[0].name = '';
+            //     enableButtonStatus();
+            //     refreshFiles();            
+            //     return data.status;
+            // })
+              
+            AWSService.post(staticResources.updateUrl, JSON.stringify({
+                "txId":transId,
+                "sfRecordId":"",
+                "isSuccess":isSuccess
+            }), function(result){
+                window.location.reload();
+            }, staticResources.token);
+        
         }
         function calculateFileSize(fileObject) {
             if (fileObject.size > 20971520) {
@@ -81,21 +90,14 @@
         }
         function uploadFileToAWS(data, size, fileName) {
             console.log("body=" + JSON.stringify({ 'file': data, "size": size, 'fileName': fileName }));
-            
-            fetch(uploadUrl, {
-                method: 'POST',
-                body: JSON.stringify({ 'file': data, "size": size, 'fileName': fileName }),
-                headers: {
-                    'Content-Type': 'application/json',
-                    'pi-token': staticResources.token
-                }
-            }).then((data) => {
-                return data.json();
-            }).then(result => {
+            AWSService.post(uploadUrl, JSON.stringify({ 
+                'file': data, 
+                "size": size, 
+                'fileName': fileName })
+                , function(result){
+                    console.log("result" + JSON.stringify(result));
 
-                console.log("result" + JSON.stringify(result));
-                
-                if (result.success == true) {
+                    if (result.success == true) {
                     key = result.object;
 
                     Visualforce.remoting.Manager.invokeAction(
@@ -124,11 +126,56 @@
                 } else {
                     alertErrorMessage('涓婁紶澶辫触璇风◢鍚庡啀璇曪紒');
                 }
-            }).catch((error) => {
-                console.error('Error:', error);
-            })
-            debugger
+            }, staticResources.token);
+        
         }
+            // fetch(uploadUrl, {
+            //     method: 'POST',
+            //     body: JSON.stringify({ 'file': data, "size": size, 'fileName': fileName }),
+            //     headers: {
+            //         'Content-Type': 'application/json',
+            //         'pi-token': staticResources.token
+            //     }
+            // }).then(function(data)  {
+            //     return data.json();
+            // }).then(function(result) {
+
+            //     console.log("result" + JSON.stringify(result));
+                
+            //     if (result.success == true) {
+            //         key = result.object;
+
+            //         Visualforce.remoting.Manager.invokeAction(
+            //             '{!$RemoteAction.FileUploadController.saveFile}',
+            //             fileName, key, result.txId, parentId,
+            //             function (resultvalue, event) {
+
+
+                            
+            //                 //2. show file list
+            //                 if (resultvalue.status == 'fail') {
+            //                     alertErrorMessage(resultvalue.message);
+            //                     //1. Confirm trans
+            //                     confirmTrans(result.txId, 0);                              
+            //                 } else {
+            //                     alertErrorMessage('涓婁紶鎴愬姛');
+            //                     confirmTrans(result.txId, 1);
+            //                 }
+                            
+            //                 // window.location.reload();
+            //             },
+            //             { escape: true }
+            //         );
+                   
+            //         console.log('key' + key);
+            //     } else {
+            //         alertErrorMessage('涓婁紶澶辫触璇风◢鍚庡啀璇曪紒');
+            //     }
+            // }).catch(function(error) {
+            //     console.error('Error:', error);
+            // })
+            // debugger
+        // }
         function downPdf(fileUrl) {
             window.open(fileUrl,'_blank');
         }

--
Gitblit v1.9.1