From cdff37596ef14a95a3e557b0d978f50140410308 Mon Sep 17 00:00:00 2001
From: 涂煌豪 <tuhuanghao@prec-tech.com>
Date: 星期二, 10 五月 2022 16:17:59 +0800
Subject: [PATCH] 【委托】URF限次修理合同的最高价格修改

---
 force-app/main/default/pages/UploadPdf.page |  130 ++++++++++++++++++++++++++++++-------------
 1 files changed, 90 insertions(+), 40 deletions(-)

diff --git a/force-app/main/default/pages/UploadPdf.page b/force-app/main/default/pages/UploadPdf.page
index 431ef8e..6759466 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}';
@@ -22,15 +23,14 @@
             var fileObject = document.getElementById("page:theForm:block:uploadSection:file");
             var reader = new FileReader();
             var data = reader.readAsDataURL(fileObject.files[0]);
-            debugger
             console.log(event);
         }
         function getBase64(file) {
             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 +47,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 +56,34 @@
         }
         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 => {
+            // 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){
                 console.log("confirmTrans-" + JSON.stringify(data));
                 document.getElementById("file").files[0].name = '';
                 enableButtonStatus();
-                refreshFiles();            
-                return data.status;
-            })
-            
+                refreshFiles();   
+            }, staticResources.token);
+        
         }
         function calculateFileSize(fileObject) {
             if (fileObject.size > 20971520) {
@@ -80,22 +91,16 @@
             }
         }
         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 => {
-
-                console.log("result" + JSON.stringify(result));
-                
-                if (result.success == true) {
+            console.log("body=" + JSON.stringify({ 'file': data, "size": size, 'fileName': fileName }));
+            AWSService.post(uploadUrl, JSON.stringify({ 
+                'file': data, 
+                "size": size, 
+                'fileName': fileName })
+                , function(result){
+                    console.log("result" + JSON.stringify(result));
+                    
+                    if (result.success == true) {
                     key = result.object;
 
                     Visualforce.remoting.Manager.invokeAction(
@@ -115,20 +120,65 @@
                                 confirmTrans(result.txId, 1);
                             }
                             
-                            // window.location.reload();
+                               window.location.reload();
                         },
                         { escape: true }
                     );
-                   
+                    
                     console.log('key' + key);
                 } 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');
         }
@@ -148,7 +198,7 @@
         }
     </style>
     <apex:form id="theForm">
-        <apex:actionFunction name="refreshFiles" action="{!refreshFiles}" reRender="pdf,uploadSection"/>      
+        <apex:actionFunction name="refreshFiles" action="{!refreshFiles}" reRender="pdf,theForm"/>      
         <br/>
         <br/>
         <apex:pageBlock id="block">

--
Gitblit v1.9.1