update_Picture.html 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>{{ title }}</title>
  6. <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  7. <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
  8. <script>
  9. $(function(){
  10. });
  11. </script>
  12. </head>
  13. <style>
  14. .input-cond-delete {
  15. background: #E43030;
  16. border: 1px solid #CFCFCF;
  17. box-sizing: border-box;
  18. border-radius: 5px;
  19. margin-left: 5px;
  20. width: 65px;
  21. height: 33px;
  22. font-size: 16px;
  23. text-align: center;
  24. line-height: 16px;
  25. color: #FFFFFF;
  26. }
  27. .input-cond-add {
  28. background: #008CBA;
  29. border: 1px solid #CFCFCF;
  30. box-sizing: border-box;
  31. border-radius: 5px;
  32. margin-left: 5px;
  33. width: 65px;
  34. height: 33px;
  35. font-size: 16px;
  36. text-align: center;
  37. line-height: 16px;
  38. color: #FFFFFF;
  39. }
  40. </style>
  41. <body>
  42. <div id="ERP_header">
  43. <!-- 匯入共同使用的 header.html 內容 -->
  44. {% include 'ERP_header.html' %}
  45. </div>
  46. 待測試!!! <br>
  47. 請選擇欲更新的圖片內部料號 :
  48. <input list="insert_PR_id_item" id="PR_id" style="height: 25px;" onChange="loadOldImg(event)">
  49. <datalist id="insert_PR_id_item">
  50. {% for data in Component_id_name_salesnum %}
  51. {% if data[2] == '' or data[2] == None %}
  52. <option value="{{data[0]}}">{{data[1]}}, (無原廠料號)</option>
  53. {% else %}
  54. <option value="{{data[0]}}">{{data[1]}}, {{data[2]}}</option>
  55. {% endif %}
  56. {% endfor %}
  57. </datalist>
  58. <br>
  59. <span id="showOldImg_filename"></span><br>
  60. <img id="showOldImg" width="180">
  61. <script>
  62. var sql = '';
  63. var sql_data = { "sql":sql };
  64. var loadOldImg = function(event) {
  65. var reader = new FileReader();
  66. reader.onload = function(){
  67. var showImg = document.getElementById('PR_id');
  68. showImg.src = reader.result;
  69. };
  70. reader.readAsDataURL(event.target.files[0]);
  71. };
  72. // var loadOldImg = function(event) {
  73. // var reader = new FileReader();
  74. // reader.onload = function(evt){
  75. // var new_PR_id = document.getElementById("PR_id");
  76. // console.log("new_PR_id: " + new_PR_id);
  77. // sql = 'SELECT `圖片` FROM `規格表` WHERE `內部料號`="' + new_PR_id + '"'
  78. // sql_data = { "sql":sql };
  79. // $.get('/sql_get', sql_data, function (res) {
  80. // if (res.labels[0] != '') {
  81. // var showImg = document.getElementById('showOldImg');
  82. // showImg.src = 'C:/Users/USER/Rita/ERP_Rita/static/Component_IMG/' + res.labels[0][0];
  83. // var showImg_filename = document.getElementById('showOldImg_filename');
  84. // showImg_filename.value = res.labels[0][0];
  85. // } else {
  86. // showImg_filename.value = '無圖片上傳';
  87. // }
  88. // }, 'json');
  89. // var showImg = document.getElementById('05070001T01_showImg');
  90. // showImg.src = reader.result;
  91. // };
  92. // reader.readAsDataURL(event.target.files[0]);
  93. // };
  94. function get_id_updatePicure(id) {
  95. var new_PR_id = document.getElementById(id).value;
  96. sql = 'SELECT `圖片` FROM `規格表` WHERE `內部料號`="' + new_PR_id + '"'
  97. sql_data = { "sql":sql };
  98. $.get('/sql_get', sql_data, function (res) {
  99. if (res.labels[0] != '') {
  100. var showImg = document.getElementById('showOldImg');
  101. showImg.src = 'C:/Users/USER/Rita/ERP_Rita/static/Component_IMG/' + res.labels[0][0];
  102. var showImg_filename = document.getElementById('showOldImg_filename');
  103. showImg_filename.value = res.labels[0][0];
  104. } else {
  105. showImg_filename.value = '無圖片上傳';
  106. }
  107. }, 'json');
  108. }
  109. </script>
  110. <br>
  111. <br>
  112. <span id="picture_exist"></span>
  113. <br>
  114. <br>
  115. <hr>
  116. 圖片上傳至 ERP 檔案內儲存, 測試 OK
  117. <form action="upload" method="post" enctype="multipart/form-data">
  118. <input type="file" id="05070001T01_loadImg" multiple="" accept="image/*" name="file[]" onchange="loadImg(event)"><br/>
  119. <img id="05070001T01_showImg" width="60"><br>
  120. <input type="submit" value="Upload">
  121. </form>
  122. <script>
  123. var loadImg = function(event) {
  124. var reader = new FileReader();
  125. reader.onload = function(){
  126. var showImg = document.getElementById('05070001T01_showImg');
  127. showImg.src = reader.result;
  128. };
  129. reader.readAsDataURL(event.target.files[0]);
  130. };
  131. function UploadImg(id) {
  132. // 取得檔案名稱
  133. var fileName = document.getElementById( id + '_loadImg').value;
  134. alert("fileName: " + String(fileName).substr(12))
  135. // 上傳圖片
  136. $.get('/upload/' + String(fileName).substr(12), '', function (res) {
  137. alert("UPLOAD success!")
  138. }, 'json');
  139. }
  140. </script>
  141. </body>
  142. </html>