online-fitolab.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. var i = 1;
  2. function Add(evt){
  3. evt.style.display="none";
  4. i ++;
  5. var div = document.createElement('div');
  6. var from_hr = 'from_hr' + i;
  7. var from_min = 'from_min' + i;
  8. var to_hr = 'to_hr' + i;
  9. var to_min = 'to_min' + i;
  10. var id = evt.getAttribute('id');
  11. var len = id.length;
  12. var add = id.split('_')[0] + '_add' + i;
  13. var del = id.split('_')[0] + '_del' + i;
  14. var html = '';
  15. var begin = id.split('_')[0];
  16. if(begin == 'tank1'){
  17. div.className = "col-12 row";
  18. div.style.marginTop = "10px";
  19. html += '<div class="col-xl-5 col-lg-5 col-md-4" style="margin-top:10px;">';
  20. html += '<span>Duration</span> <select name="tank1_duration' + i + '" class="duration"><option selected value="30min">30 min</option><option value="60min">60 min</option><option value="90min">90 min</option><option value="120min">120 min</option><option value="150min">150 min</option></select>';
  21. html += '</div>';
  22. html += '<div class="from-to col-xl-7 col-lg-7 col-md-8" style="margin-top:10px;padding-right:0px;">';
  23. html += '<div>';
  24. html += '<div class="from row" style="margin-left:10px;">';
  25. }else if(begin == 'tank2'){
  26. div.className = "col-12 row";
  27. div.style.marginTop = "10px";
  28. html += '<div class="col-xl-5 col-lg-5 col-md-4" style="margin-top:10px;">';
  29. html += '<span>Duration</span> <select name="tank2_duration' + i + '" class="duration"><option selected value="30min">30 min</option><option value="60min">60 min</option><option value="90min">90 min</option><option value="120min">120 min</option><option value="150min">150 min</option></select>';
  30. html += '</div>';
  31. html += '<div class="from-to col-xl-7 col-lg-7 col-md-8" style="margin-top:10px;padding-right:0px;">';
  32. html += '<div>';
  33. html += '<div class="from row" style="margin-left:10px;">';
  34. }else if(begin == 'music'){
  35. html += '<div class="from row col-xl-12 col-lg-12 col-md-12 col-sm-12 col-xs-12">';
  36. html += '<div class="col-md-3 col-sm-12 col-xs-12">';
  37. html += '<select name="music' + i + '" class="music-select"><option selected value="playlist1">playlist1</option><option value="playlist2">playlist2</option><option value="playlist3">playlist3</option></select>';
  38. html += '</div>';
  39. }else if(begin == 'v'){
  40. html += '<div class="from row col-xl-12 col-lg-12 col-md-12 col-sm-12 col-xs-12">';
  41. html += '<div class="col-md-3 col-sm-12 col-xs-12">';
  42. html += '<select name="vibration' + i + '" class="vibration-select"><option selected value="5Hz">5Hz</option><option value="10Hz">10Hz</option><option value="15Hz">15Hz</option></select>';
  43. html += '</div>';
  44. };
  45. html += '<div class="col-xs-3">';
  46. html += '<span>From</span>';
  47. html += '</div>';
  48. html += '<div class="col-xs-6">';
  49. if(id.split('_')[0] == 'music'){
  50. html += '<select name="music_from_hr' + i + '">';
  51. }else if(id.split('_')[0] == 'v'){
  52. html += '<select name="v_from_hr' + i + '">';
  53. }else if(id.split('_')[0] == 'tank1'){
  54. html += '<select name="tank1_from_hr' + i + '">';
  55. }else if(id.split('_')[0] == 'tank2'){
  56. html += '<select name="tank2_from_hr' + i + '">';
  57. }else{
  58. html += '<select name="from_hr1">';
  59. };
  60. for(var hr = 0; hr < 24; hr++){
  61. if(hr < 10){
  62. html += '<option value="0' + hr + '">0' + hr + '</option>';
  63. }else{
  64. html += '<option value="' + hr + '">' + hr + '</option>';
  65. };
  66. };
  67. html += '</select>';
  68. if(id.split('_')[0] == 'music'){
  69. html += ' :<select name="music_from_min' + i + '">';
  70. }else if(id.split('_')[0] == 'v'){
  71. html += ' :<select name="v_from_min' + i + '">';
  72. }else if(id.split('_')[0] == 'tank1'){
  73. html += ' :<select name="tank1_from_min' + i + '">';
  74. }else if(id.split('_')[0] == 'tank2'){
  75. html += ' :<select name="tank2_from_min' + i + '">';
  76. }else{
  77. html += ' :<select name="from_min1">';
  78. };
  79. for(var min = 0; min < 60; min++){
  80. if(min < 10){
  81. html += '<option value="0' + min + '">0' + min + '</option>';
  82. }else{
  83. html += '<option value="' + min + '">' + min + '</option>';
  84. };
  85. };
  86. html += '</select>';
  87. html += '</div>';
  88. html += '<div class="col-xs-3">';
  89. html += '<input id=' + del + ' class="delete" type="button" value="Delete" onclick="Delete(' + del + ');">';
  90. html += '</div>';
  91. html += '</div>';
  92. if(begin == 'music' || begin == 'v'){
  93. html += '<div class="to row" style="margin-left:130px;">';
  94. }else{
  95. html += '<div class="to row">';
  96. };
  97. html += '<div class="col-xs-3">';
  98. if(begin == 'v' || begin == 'music'){
  99. html += '<span style="margin-left: 33px;">To</span>';
  100. }else{
  101. html += '<span style="margin-left: 31px;">To</span>';
  102. };
  103. html += '</div>';
  104. html += '<div class="col-xs-6">';
  105. if(id.split('_')[0] == 'music'){
  106. html += '<select name="music_to_hr' + i + '">';
  107. }else if(id.split('_')[0] == 'v'){
  108. html += '<select name="v_to_hr' + i + '">';
  109. }else if(id.split('_')[0] == 'tank1'){
  110. html += '<select name="tank1_to_hr' + i + '">';
  111. }else if(id.split('_')[0] == 'tank2'){
  112. html += '<select name="tank2_to_hr' + i + '">';
  113. }else{
  114. html += '<select name="to_hr1">';
  115. };
  116. for(var hr = 0; hr < 24; hr++){
  117. if(hr < 10){
  118. html += '<option value="0' + hr + '">0' + hr + '</option>';
  119. }else{
  120. html += '<option value="' + hr + '">' + hr + '</option>';
  121. };
  122. };
  123. html += '</select>';
  124. if(id.split('_')[0] == 'music'){
  125. html += ' :<select name="music_to_min' + i + '">';
  126. }else if(id.split('_')[0] == 'v'){
  127. html += ' :<select name="v_to_min' + i + '">';
  128. }else if(id.split('_')[0] == 'tank1'){
  129. html += ' :<select name="tank1_to_min' + i + '">';
  130. }else if(id.split('_')[0] == 'tank2'){
  131. html += ' :<select name="tank2_to_min' + i + '">';
  132. }else{
  133. html += ' :<select name="to_min1">';
  134. };
  135. for(var min = 0; min < 60; min++){
  136. if(min < 10){
  137. html += '<option value="0' + min + '">0' + min + '</option>';
  138. }else{
  139. html += '<option value="' + min + '">' + min + '</option>';
  140. };
  141. };
  142. html += '</select><br>';
  143. html += '<input id=' + add + ' class="add" type="button" value="Add" onclick="Add(' + add + ');">';
  144. html += '</div>';
  145. html += '<div class="col-xs-3"></div>';
  146. html += '</div>';
  147. if(begin == 'tank1' || begin == 'tank2'){
  148. html += '</div>';
  149. html += '</div>';
  150. };
  151. div.innerHTML = html;
  152. div.style.marginTop = '15px';
  153. div.style.zIndex = '100';
  154. if(begin == 'tank1' || begin == 'tank2'){
  155. evt.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.appendChild(div);
  156. }else{
  157. evt.parentNode.parentNode.parentNode.parentNode.appendChild(div);
  158. };
  159. };
  160. function Delete(evt){
  161. var id = evt.getAttribute('id');
  162. var add = id.split('_')[0] + '_' + 'add';
  163. var clo_xs_3 = evt.parentNode;
  164. var from = clo_xs_3.parentNode;
  165. var begin = id.split('_')[0];
  166. if(begin == 'tank1' || begin == 'tank2'){
  167. var div = from.parentNode.parentNode.parentNode;
  168. var next_div = div.nextElementSibling;
  169. var pre_div = div.previousElementSibling;
  170. }else{
  171. var div = from.parentNode;
  172. var next_div = div.nextElementSibling;
  173. var pre_div = div.previousElementSibling;
  174. };
  175. if(next_div && pre_div == null){
  176. div.parentNode.removeChild(div);
  177. next_div.style.marginTop = '0px';
  178. }else if(next_div && pre_div){
  179. div.parentNode.removeChild(div);
  180. }else if(next_div == null && pre_div == null){
  181. if(id.split('_')[0] == 'music' || id.split('_')[0] == 'v'){
  182. div.parentNode.parentNode.parentNode.parentNode.children[1].style.display = 'inline-block';
  183. div.parentNode.style.display = 'none';
  184. }else if(begin == 'tank1' || begin == 'tank2'){
  185. div.parentNode.parentNode.children[1].style.display = 'inline-block';
  186. div.parentNode.style.visibility = 'hidden';
  187. }else{
  188. div.parentNode.parentNode.parentNode.children[1].style.display = 'inline-block';
  189. div.parentNode.style.display = 'none';
  190. };
  191. var name = id.split('_')[0];
  192. var from_hr = name + '_from_hr' + 1;
  193. var from_min = name + '_from_min' + 1;
  194. var to_hr = name + '_to_hr' + 1;
  195. var to_min = name + '_to_min' + 1;
  196. $('select[name=' + from_hr + ']').val('00');
  197. $('select[name=' + from_min + ']').val('00');
  198. $('select[name=' + to_hr + ']').val('00');
  199. $('select[name=' + to_min + ']').val('00');
  200. }else{
  201. div.parentNode.removeChild(div);
  202. i --;
  203. add = add + i;
  204. add = document.getElementById(add);
  205. if(add == null){
  206. if(begin == 'tank1' || begin == 'tank2'){
  207. add = pre_div.children[1].children[0].children[1].children[1].children[3];
  208. }else{
  209. add = pre_div.children[1].children[1].children[3];
  210. };
  211. };
  212. add.style.display = 'block';
  213. };
  214. };
  215. function Echart(evt){
  216. $("#" + evt + "-div").css('display','block');
  217. //基於準備好的dom,初始化echarts例項
  218. var myChart = echarts.init(document.getElementsByClassName('' + evt)[0]);
  219. //指定圖表的配置項和資料
  220. var option = {
  221. xAxis: {
  222. type: 'category',
  223. data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
  224. },
  225. yAxis: {
  226. type: 'value'
  227. },
  228. series: [{
  229. data: [820, 932, 901, 934, 1290, 1330, 1320],
  230. type: 'line'
  231. }]
  232. };
  233. //使用剛指定的配置項和資料顯示圖表
  234. myChart.setOption(option);
  235. };
  236. $(function(){
  237. $("#fitolab1").click(function(){
  238. $("#fitolab1").css('display','none');
  239. $(".show-fitolab1").css('display','block');
  240. $(".page-title").text("Fitolab1");
  241. });
  242. $(".stem-light-btn").click(function(){
  243. $("#stem-light-control").css('display','block');
  244. document.getElementsByName('anchor')[0].click();
  245. });
  246. $(".stem-light-cancel").click(function(){
  247. $("#stem-light-control").css('display','none');
  248. });
  249. $(".root-light-btn").click(function(){
  250. $("#root-light-control").css('display','block');
  251. document.getElementsByName('anchor')[0].click();
  252. });
  253. $(".root-light-cancel").click(function(){
  254. $("#root-light-control").css('display','none');
  255. });
  256. $(".stem-music-btn").click(function(){
  257. $("#music-control").css('display','block');
  258. document.getElementsByName('anchor')[0].click();
  259. });
  260. $(".music-control-cancel").click(function(){
  261. $("#music-control").css('display','none');
  262. });
  263. var music = $(".set-schedule")[0];
  264. var music_div = $("#music_div");
  265. var vol_div = $(".vol-div");
  266. music.onclick = function(){
  267. console.log(vol_div);
  268. music.style.display = 'none';
  269. music_div.css('display', 'block');
  270. vol_div.css('display', 'block');
  271. };
  272. $(".show-tem").click(function(){
  273. $("#stem-tem").css('display','block');
  274. });
  275. $(".stem-tem-cancel").click(function(){
  276. $("#stem-tem").css('display','none');
  277. });
  278. $(".stem-camera-btn").click(function(){
  279. $("#camera-control").css('display','block');
  280. document.getElementsByName('anchor')[0].click();
  281. });
  282. $(".camera-control-cancel").click(function(){
  283. $("#camera-control").css('display','none');
  284. });
  285. $(".gallery").click(function(){
  286. $("#gallery").css('display','block');
  287. $("#camera-control").css('display','none');
  288. });
  289. $(".gallery-cancel").click(function(){
  290. $("#gallery").css('display','none');
  291. $("#camera-control").css('display','block');
  292. });
  293. $(".stem-stress-btn").click(function(){
  294. $("#plant-stress-monitor").css('display','block');
  295. document.getElementsByName('anchor')[0].click();
  296. });
  297. $(".plant-stress-monitor-cancel").click(function(){
  298. $("#plant-stress-monitor").css('display','none');
  299. });
  300. $(".show-weight").click(function(){
  301. $("#weight").css('display','block');
  302. });
  303. $(".weight-cancel").click(function(){
  304. $("#weight").css('display','none');
  305. });
  306. $(".h2-cancel").click(function(){
  307. $("#h2-div").css('display','none');
  308. });
  309. $(".root-vibration-btn").click(function(){
  310. $("#vibration").css('display','block');
  311. document.getElementsByName('anchor')[0].click();
  312. });
  313. $(".vibration-cancel").click(function(){
  314. $("#vibration").css('display','none');
  315. });
  316. var vibration = $(".set-schedule")[1];
  317. var vibration_div = $("#vibration_div");
  318. var pow_div = $(".pow-div");
  319. vibration.onclick = function(){
  320. vibration.style.display = 'none';
  321. vibration_div.css('display', 'block');
  322. pow_div.css('display', 'block');
  323. };
  324. var tank1 = $(".set-schedule")[2];
  325. var tank1_div = $("#tank1_div");
  326. tank1.onclick = function(){
  327. tank1.style.display = 'none';
  328. tank1_div.css('visibility','visible');
  329. };
  330. var tank2 = $(".set-schedule")[3];
  331. var tank2_div = $("#tank2_div");
  332. tank2.onclick = function(){
  333. tank2.style.display = 'none';
  334. tank2_div.css('visibility','visible');
  335. };
  336. $(".root-water-btn").click(function(){
  337. $("#water-con-con").css('display','block');
  338. document.getElementsByName('anchor')[0].click();
  339. });
  340. $(".water-con-con-cancel").click(function(){
  341. $("#water-con-con").css('display','none');
  342. });
  343. $("#list li").click(function(){
  344. $("#list li").removeClass("current_li");
  345. $("#list li a").removeClass("current");
  346. });
  347. $(".s-js-color").click(function(){
  348. var $this = $(this);
  349. var hex = $this.attr('data-hex');
  350. var rgb = $this.attr('data-rgb');
  351. $(".s_show_color").css('background-color', hex);
  352. $("input[name=stem-color]").val(rgb);
  353. $(".s_span_color").text(hex);
  354. });
  355. $(".r-js-color").click(function(){
  356. var $this = $(this);
  357. var hex = $this.attr('data-hex');
  358. var rgb = $this.attr('data-rgb');
  359. $(".r_show_color").css('background-color', hex);
  360. $("input[name=root-color]").val(rgb);
  361. $(".r_span_color").text(hex);
  362. });
  363. $(".brightness").click(function(){
  364. $(".brightness_info").css('display','block');
  365. $(".color_info").css('display','none');
  366. $(".recomendation_info").css('display','none');
  367. });
  368. $(".color").click(function(){
  369. $(".brightness_info").css('display','none');
  370. $(".color_info").css('display','block');
  371. $(".recomendation_info").css('display','none');
  372. });
  373. $(".recomendations").click(function(){
  374. $(".recomendation_info").css('display','block');
  375. $(".color_info").css('display','none');
  376. $(".brightness_info").css('display','none');
  377. });
  378. });