tank_relation.html 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  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. <!-- 新 Bootstrap4 核心 CSS 文件 -->
  8. <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
  9. <!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
  10. <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
  11. <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
  12. <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
  13. <!--可用來建立使用者小圖示-->
  14. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
  15. <script language="JavaScript">
  16. var set_dryImport_number = 2; // prompt("請輸入乾燥 入料儲豆槽 數量:")
  17. var set_dryTank_number = 12; // prompt("請輸入乾燥 桶槽 數量:")
  18. var set_dryExport_number = 2; // prompt("請輸入乾燥 出料儲豆槽 數量:")
  19. console.log("get number: " + set_dryImport_number + "-" + set_dryTank_number + "-" + set_dryExport_number);
  20. // 儲存乾燥貨櫃所有桶槽、入料儲豆槽、出料儲豆槽
  21. var dry_import_list = [];
  22. var dry_tank_list = [];
  23. var dry_export_list = [];
  24. // 桶槽對應值
  25. var dry_tank_data_list = [];
  26. var dry_import_data_list = [];
  27. var dry_export_data_list = [];
  28. var html = '';
  29. var dry_export_data = [];
  30. var data = '{{dtr[0]}}';
  31. console.log("data: " + data);
  32. $(function(){
  33. // 網頁 title
  34. $("#coffee_title_pc").text("桶槽關係建立");
  35. $("#coffee_title_phone").text("桶槽關係建立");
  36. console.log("dry_import_list: " + dry_import_list);
  37. console.log("dry_tank_list: " + dry_tank_list);
  38. console.log("dry_export_list: " + dry_export_list);
  39. console.log("dry_tank_data_list: " + dry_tank_data_list);
  40. console.log("dry_import_data_list: " + dry_import_data_list);
  41. console.log("dry_export_data_list: " + dry_export_data_list);
  42. // 從 入料桶槽出料 取得 桶槽值 D1, 轉換成下拉式選單選項
  43. html = '';
  44. for (let dil = 0; dil < dry_import_list.length; dil++) {
  45. html += '<option value="' + dry_import_list[dil] + '">' + dry_import_list[dil] + '</option>';
  46. }
  47. for (let dtl = 0; dtl < dry_tank_list.length; dtl++) {
  48. html += '<option value="' + dry_tank_list[dtl] + '">' + dry_tank_list[dtl] + '</option>';
  49. }
  50. for (let del = 0; del < dry_export_list.length; del++) {
  51. html += '<option value="' + dry_export_list[del] + '">' + dry_export_list[del] + '</option>';
  52. }
  53. // 賦值到下拉式選單中 - 入料 + 出料
  54. for (let dil = 0; dil < dry_import_list.length; dil++) {
  55. var divbox = document.getElementById(dry_import_list[dil] + '_import');
  56. divbox.insertAdjacentHTML('beforeend', html);
  57. var divbox = document.getElementById(dry_import_list[dil] + '_export');
  58. divbox.insertAdjacentHTML('beforeend', html);
  59. }
  60. for (let dtl = 0; dtl < dry_tank_list.length; dtl++) {
  61. var divbox = document.getElementById(dry_tank_list[dtl] + '_import');
  62. divbox.insertAdjacentHTML('beforeend', html);
  63. var divbox = document.getElementById(dry_tank_list[dtl] + '_export');
  64. divbox.insertAdjacentHTML('beforeend', html);
  65. }
  66. for (let del = 0; del < dry_export_list.length; del++) {
  67. var divbox = document.getElementById(dry_export_list[del] + '_import');
  68. divbox.insertAdjacentHTML('beforeend', html);
  69. var divbox = document.getElementById(dry_export_list[del] + '_export');
  70. divbox.insertAdjacentHTML('beforeend', html);
  71. }
  72. var divbox = document.getElementById('new_import');
  73. divbox.insertAdjacentHTML('beforeend', html);
  74. var divbox = document.getElementById('new_export');
  75. divbox.insertAdjacentHTML('beforeend', html);
  76. // DB 取值後顯示
  77. // // 儲存乾燥貨櫃所有桶槽、入料儲豆槽、出料儲豆槽
  78. // var dry_import_list = [];
  79. // var dry_tank_list = [];
  80. // var dry_export_list = [];
  81. // // 桶槽對應值
  82. // var dry_tank_data_list = [];
  83. // var dry_import_data_list = [];
  84. // var dry_export_data_list = [];
  85. for (let i = 0; i < dry_tank_data_list.length; i++) {
  86. if (dry_tank_data_list.includes(dry_import_data_list[i])) {
  87. $("#" + dry_tank_data_list[i] + "_import").val(dry_import_data_list[i]);
  88. } else {
  89. $("#" + dry_tank_data_list[i] + "_import").val('-');
  90. }
  91. if (dry_tank_data_list.includes(dry_export_data_list[i])) {
  92. $("#" + dry_tank_data_list[i] + "_export").val(dry_export_data_list[i]);
  93. } else {
  94. $("#" + dry_tank_data_list[i] + "_export").val('-');
  95. }
  96. // $("#" + dry_tank_data_list[i] + "_export").val(dry_export_data_list[i]);
  97. // if (dry_tank_data_list.includes(dry_import_data_list[i])) {
  98. // console.log("tttest " + dry_import_data_list[i]);
  99. // $("#" + dry_tank_data_list[i] + "_import").val(dry_import_data_list[i]);
  100. // $("#" + dry_tank_data_list[i] + "_export").val(dry_export_data_list[i]);
  101. // } else {
  102. // console.log("else tttest " + dry_import_data_list[i]);
  103. // $("#" + dry_tank_data_list[i] + "_import").val('-');
  104. // $("#" + dry_tank_data_list[i] + "_export").val('-');
  105. // }
  106. }
  107. // var html = '<table border="5" style="border: 3px lightgray solid; text-align: center; margin-left: auto; margin-right: auto; width: 500px;">' +
  108. // '<tr>' +
  109. // '<th>桶槽名稱</th>' +
  110. // '<th>桶槽類別</th>' +
  111. // '<th>桶槽入料</th>' +
  112. // '<th>桶槽出料</th>' +
  113. // '</tr>';
  114. // // 增加入料儲豆槽 設定表格
  115. // for (let di = 1; di <= set_dryImport_number; di++) {
  116. // html +='<tr>' +
  117. // '<td>DI' + di + '</td>' +
  118. // '<td></td>' +
  119. // '<td></td>' +
  120. // '<td></td>' +
  121. // '</tr>';
  122. // }
  123. // // 增加桶槽 設定表格
  124. // for (let dt = 1; dt <= set_dryTank_number; dt++) {
  125. // html +='<tr>' +
  126. // '<td>D' + dt + '</td>' +
  127. // '<td></td>' +
  128. // '<td></td>' +
  129. // '<td></td>' +
  130. // '</tr>';
  131. // }
  132. // // 增加出料儲豆槽 設定表格
  133. // for (let de = 1; de <= set_dryExport_number; de++) {
  134. // html +='<tr>' +
  135. // '<td>DO' + de + '</td>' +
  136. // '<td></td>' +
  137. // '<td></td>' +
  138. // '<td></td>' +
  139. // '</tr>';
  140. // }
  141. // html += '<tr>' +
  142. // '<td colspan="5">[修改確認]</td>' +
  143. // '</table>';
  144. // var divbox = document.getElementById('set_table');
  145. // divbox.insertAdjacentHTML('beforeend', html);
  146. });
  147. </script>
  148. <style>
  149. .input-cond-delete {
  150. background: #E43030;
  151. border: 1px solid #CFCFCF;
  152. box-sizing: border-box;
  153. border-radius: 5px;
  154. margin-left: 5px;
  155. width: 86px;
  156. height: 33px;
  157. font-size: 16px;
  158. text-align: center;
  159. line-height: 16px;
  160. color: #FFFFFF;
  161. }
  162. .input-cond-add {
  163. background: #008CBA;
  164. border: 1px solid #CFCFCF;
  165. box-sizing: border-box;
  166. border-radius: 5px;
  167. margin-left: 5px;
  168. width: 80px;
  169. height: 33px;
  170. font-size: 16px;
  171. text-align: center;
  172. line-height: 16px;
  173. color: #FFFFFF;
  174. }
  175. .r5_position {
  176. position: absolute;
  177. top: 160px;
  178. left: 310px;
  179. width: 40px;
  180. height: 150px;
  181. border-style: solid;
  182. border-color: aqua;
  183. }
  184. .div_relay_css {
  185. position: absolute;
  186. border-style: solid;
  187. border-color: aqua;
  188. text-align: center;
  189. font-size: 12px;
  190. }
  191. /* header */
  192. /* 文字輸入框 */
  193. .input-text {
  194. height: 25px;
  195. width: 40px;
  196. text-align: center;
  197. margin-left: 2px;
  198. margin-right: 5px;
  199. }
  200. /* 致動器狀態表格置中 */
  201. .label_ActuatorStatus {
  202. margin: auto;
  203. }
  204. /* 致動器 ON 樣式 */
  205. .input-button-on {
  206. color: #008CBA;
  207. border: 2px rgb(182, 181, 181) solid;
  208. background-color: whitesmoke;
  209. padding: 1px 3px;
  210. width: 45px;
  211. }
  212. /* 致動器 OFF 樣式 */
  213. .input-button-off {
  214. color: #707070;
  215. border: 2px rgb(192, 192, 192) solid;
  216. background-color: whitesmoke;
  217. padding: 1px 3px;
  218. width: 45px;
  219. }
  220. /* 輸入按鈕 */
  221. .input-button {
  222. font-size: 14px;
  223. color: #008CBA;
  224. border: 2px rgb(182, 181, 181) solid;
  225. background-color: whitesmoke;
  226. padding: 1px 3px;
  227. }
  228. /* 大表格樣式 */
  229. .table-all {
  230. font-size:18px;
  231. border:2px #cccccc solid;
  232. margin-left: 10px;
  233. margin-right: 10px;
  234. width: 98%;
  235. }
  236. /* footer */
  237. .footer{
  238. height: 40px;
  239. box-sizing: border-box;
  240. /* 設定footer絕對位置在底部 */
  241. position: absolute;
  242. bottom: 0px;
  243. width: 100%;
  244. background-color: #eee;
  245. text-align: center;
  246. }
  247. html, body {
  248. height: 100%;
  249. /* margin: 0; */
  250. position: relative;
  251. }
  252. #wrapper {
  253. /* 設定高度最小為100%, 如果內容區塊很多, 可以長大 */
  254. min-height: 100%;
  255. /* 位置設為relative, 作為footer區塊位置的參考 */
  256. position: relative;
  257. }
  258. </style>
  259. </head>
  260. <body style="font-size: 18px;">
  261. <div id="wrapper" style="height: fit-content; text-align: center; margin-left: auto; margin-right: auto;">
  262. <div id="coffee_header">
  263. <!-- 匯入共同使用的 header.html 內容 -->
  264. {% include 'header.html' %}
  265. </div>
  266. <!-- <div id="set_table">
  267. </div> -->
  268. <table border="5" style="border: 3px lightgray solid; text-align: center; margin-left: auto; margin-right: auto; width: 700px;">
  269. <tr>
  270. <th>桶槽名稱</th>
  271. <th>桶槽類別</th>
  272. <th>入料</th>
  273. <th>出料</th>
  274. <th></th>
  275. </tr>
  276. {% for i in dtr %}
  277. <script>
  278. dry_tank_data_list.push('{{ i.tank_id }}');
  279. if ('{{ i.tank_id }}'.substring(0, 2) === 'DO') {
  280. dry_export_list.push('{{ i.tank_id }}');
  281. } else if ('{{ i.tank_id }}'.substring(0, 2) === 'DI') {
  282. dry_import_list.push('{{ i.tank_id }}');
  283. } else {
  284. dry_tank_list.push('{{ i.tank_id }}');
  285. }
  286. </script>
  287. <tr>
  288. <td>
  289. {{ i.tank_id }}
  290. </td>
  291. <td>
  292. <select id="{{ i.tank_id }}_type" onchange="" class="select-input">
  293. <option value="mix" selected>混合槽</option>
  294. <option value="clean_tank">清洗桶槽</option>
  295. <option value="reclaimedwater_tank">中水桶</option>
  296. <option value="colorselect_tank">色選機</option>
  297. <option value="peel_tank">脫皮機</option>
  298. <option value="ferment_in">發酵入料</option>
  299. <option value="ferment_tank">發酵桶槽</option>
  300. <option value="ferment_out">發酵出料</option>
  301. <option value="dry_in">乾燥入料</option>
  302. <option value="dry_tank">乾燥桶槽</option>
  303. <option value="dry_out">乾燥出料</option>
  304. </select>
  305. </td>
  306. <script>
  307. var tank_type_data = '{{i.tank_type}}';
  308. $("#{{ i.tank_id }}_type").val(tank_type_data);
  309. </script>
  310. <td>
  311. <select id="{{ i.tank_id }}_import" onchange="" class="select-input">
  312. <option value="-">-</option>
  313. </select>
  314. </td>
  315. <script>
  316. dry_import_data_list.push('{{ i.tank_import }}');
  317. </script>
  318. <td>
  319. <select id="{{ i.tank_id }}_export" onchange="" class="select-input">
  320. <option value="-">-</option>
  321. </select>
  322. </td>
  323. <script>
  324. dry_export_data_list.push('{{ i.tank_export }}');
  325. </script>
  326. <td>
  327. <input type="button" id="{{ i.tank_id }}_del" value="刪除 {{ i.tank_id }}" onclick="relation_del('{{ i.tank_id }}')" class="input-cond-delete">
  328. <script>
  329. function relation_del(tankID) {
  330. var confirm_relation_del = confirm("是否要移除 " + tankID + " ?\n確認後即刪除該項關聯")
  331. if (!confirm_relation_del) {
  332. alert("已取消動作");
  333. } else {
  334. const SQL_delete = 'DELETE FROM `dry_tank_relation` WHERE `tank_id` = "' + tankID + '"';
  335. // console.log("sql_data: " + sql_data);
  336. var sql_data = { "sql": SQL_delete };
  337. console.log("sql_data: ", sql_data)
  338. $.get('/sql_get', sql_data, function (res) {
  339. if (res['response'] == '') {
  340. alert("OK");
  341. } else {
  342. alert(res['response']);
  343. }
  344. }, 'json');
  345. // TRUNCATE TABLE `dry_tank_relation`;
  346. }
  347. }
  348. </script>
  349. </td>
  350. </tr>
  351. {% endfor %}
  352. <tr>
  353. <td>
  354. <input type="text" id="new_tank_id" style="width: 120px;">
  355. </td>
  356. <td>
  357. <select id="new_type" onchange="" class="select-input">
  358. <option value="mix" selected>混合槽</option>
  359. <option value="clean_tank">清洗桶槽</option>
  360. <option value="reclaimedwater_tank">中水桶</option>
  361. <option value="colorselect_tank">色選機</option>
  362. <option value="peel_tank">脫皮機</option>
  363. <option value="ferment_in">發酵入料</option>
  364. <option value="ferment_tank">發酵桶槽</option>
  365. <option value="ferment_out">發酵出料</option>
  366. <option value="dry_in">乾燥入料</option>
  367. <option value="dry_tank">乾燥桶槽</option>
  368. <option value="dry_out">乾燥出料</option>
  369. </select>
  370. </td>
  371. <td>
  372. <select id="new_import" onchange="" class="select-input">
  373. <option value="-">-</option>
  374. </select>
  375. </td>
  376. <td>
  377. <select id="new_export" onchange="" class="select-input">
  378. <option value="-">-</option>
  379. </select>
  380. </td>
  381. <td>
  382. <input type="button" id="new_insert" value="新增" onclick="relation_ins()" class="input-cond-add">
  383. <script>
  384. function relation_ins() {
  385. const new_insert_tid = $('#new_tank_id').val();
  386. const new_insert_type = $("#new_type").val();
  387. const new_insert_import = $("#new_import").val();
  388. const new_insert_export = $("#new_export").val();
  389. // console.log("new_insert_tid: " + new_insert_tid);
  390. // console.log("new_insert_type: " + new_insert_type);
  391. // console.log("new_insert_import: " + new_insert_import);
  392. // console.log("new_insert_export: " + new_insert_export);
  393. const SQL_delete = 'INSERT INTO `dry_tank_relation`(`tank_id`, `tank_type`, `tank_import`, `tank_export`, `datetime`) ' +
  394. 'VALUES ("' + new_insert_tid +
  395. '","' + new_insert_type +
  396. '","' + new_insert_import +
  397. '","' + new_insert_export +
  398. '", current_timestamp())';
  399. console.log("SQL_delete: " + SQL_delete);
  400. var sql_data = { "sql": SQL_delete };
  401. $.get('/sql_get', sql_data, function (res) {
  402. if (res['response'] == '') {
  403. alert("OK");
  404. } else {
  405. alert(res['response']);
  406. }
  407. }, 'json');
  408. }
  409. </script>
  410. </td>
  411. </tr>
  412. <script>
  413. </script>
  414. <tr>
  415. <td colspan="5">
  416. [確認]
  417. </td>
  418. </tr>
  419. </table>
  420. <div id="coffee_footer">
  421. <!-- 匯入共同使用的 footer.html 內容 -->
  422. {% include 'footer.html' %}
  423. <br>
  424. <br>
  425. </div>
  426. </div>
  427. </body>
  428. </html>