set_update.html 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <filter><script src="../js/common.js"></script><script src="../js/jquery.min.js"></script></filter>
  5. <script class="include" system="" path="inc/" file="head">include()</script>
  6. </head>
  7. <body class="gray">
  8. <header>
  9. 智能设置 <a href="#" class="ico-back"></a>
  10. </header>
  11. <section class="wrapper">
  12. <section class="card w100">
  13. <h4>设备条件:</h4>
  14. <label for="">&nbsp;</label>
  15. <p class="form-group">
  16. <select name="product" id="product" onchange="set()">
  17. <option value="">请选择设备</option>
  18. <option value="">222</option>
  19. <option value="">444</option>
  20. </select>
  21. <select name="type" id="type" onchange="set()">
  22. <option value="">请选择设备类型</option>
  23. <option value="">222</option>
  24. <option value="">444</option>
  25. </select>
  26. </p>
  27. <p class="form-group">
  28. <select name="element" id="element">
  29. <option value="">请选择传感器</option>
  30. <option value="">222</option>
  31. <option value="">444</option>
  32. </select>
  33. </p>
  34. </section>
  35. <section class="card w100 sensor" style="display:none;">
  36. <h4>条件判断:</h4>
  37. <label for="">&nbsp;</label>
  38. <p class="form-group" style="display:none;">
  39. 表达式:<input type="text" value="{b}" name="exp" id="exp"/>({b}为当前值)
  40. </p>
  41. <p class="form-group">
  42. <select name="than" id="than">
  43. <option value="">大于</option>
  44. <option value="">小于</option>
  45. </select>
  46. <input type="text" value="0" name="value" id="value" />
  47. </p>
  48. </section>
  49. <section class="card w100 sensor" style="display:none;">
  50. <h4>执行结果:<input type="hidden" value="" name="result" id="result" /></h4>
  51. <label for="">&nbsp;</label>
  52. <p class="form-group">
  53. <select class="result" id="result_1">
  54. <option value="1">报警</option>
  55. <option value="2">不报警</option>
  56. </select>
  57. </p>
  58. <div id="result_add">
  59. </div>
  60. <p class="form-group">
  61. <a href="javascript:;" onclick="add()" class="input">+</a>
  62. </p>
  63. </section>
  64. <section class="card w100 control" style="display:none;">
  65. <h4>操作类型:</h4>
  66. <label for="">&nbsp;</label>
  67. <p class="form-group">
  68. <select name="oper" id="oper">
  69. <option value="">大于</option>
  70. <option value="">小于</option>
  71. </select>
  72. <input type="text" value="600" name="time" id="time" />
  73. </p>
  74. </section>
  75. <input type="hidden" id="set_id" name="set_id" value="-1">
  76. <input type="hidden" id="result_num" name="result_num" value="">
  77. <input type="hidden" id="result_value" name="result_value" value="">
  78. <input type="button" value="确定" class="button" id="set" />
  79. <div style="display:none;">
  80. <select id="result_2">
  81. <option value="">请选择传感器</option>
  82. </select>
  83. <select id="result_3">
  84. <option value="3">不操作</option>
  85. <option value="1">打开</option>
  86. <option value="2">关闭</option>
  87. </select>
  88. </div>
  89. </section>
  90. </body>
  91. </html>
  92. <script>
  93. var addindex = 0;
  94. $("select option").each(function()
  95. {
  96. if($(this).attr('select') && $(this).attr('select') == 'true')
  97. {
  98. $(this).attr('selected', 'true');
  99. }
  100. else
  101. {
  102. $(this).removeAttr('selected');
  103. }
  104. });
  105. function set()
  106. {
  107. var type = $("#type").val();
  108. var product_id = $("#product").val();
  109. var url = $("#set").attr('url');
  110. $.getJSON(url, {type:type,id:product_id}, function(t)
  111. {
  112. t = t.data;
  113. if(t)
  114. {
  115. $("#element").html(t);
  116. $("#element").parent().show();
  117. }
  118. else
  119. {
  120. $("#element").parent().hide();
  121. }
  122. if(type == 1)
  123. {
  124. $(".control").hide();
  125. $(".sensor").show();
  126. }
  127. else
  128. {
  129. $(".sensor").hide();
  130. $(".control").show();
  131. }
  132. });
  133. $.getJSON(url, {type:2,id:product_id}, function(t)
  134. {
  135. t = t.data;
  136. if(t)
  137. {
  138. $("#result_2").html(t);
  139. if(addindex <= 0)
  140. {
  141. var num = $("#result_num").val();
  142. var value = $("#result_value").val();
  143. if(num > 0)
  144. {
  145. num = num*2;
  146. var v = value.split(',');
  147. for(var i=0; i<num; i++)
  148. {
  149. add(v[i], v[i+1]);
  150. i++;
  151. }
  152. }
  153. }
  154. }
  155. else
  156. {
  157. $("#result_2").hide();
  158. }
  159. });
  160. }
  161. function add(v1,v2)
  162. {
  163. var e = $('#result_add');
  164. var r = $("#result_2");
  165. var a = $("#result_3");
  166. var html = '<p class="form-group"><select class="result" id="result_i_'+addindex+'">' + r.html() + '</select>' + '<select class="result" id="result_j_'+addindex+'">' + a.html() + '</select></p>';
  167. e.append(html);
  168. if(v1)
  169. {
  170. $("#result_i_" + addindex).val(v1);
  171. }
  172. if(v2)
  173. {
  174. $("#result_j_" + addindex).val(v2);
  175. }
  176. addindex++;
  177. }
  178. function result()
  179. {
  180. var result = [];
  181. $(".result").each(function()
  182. {
  183. result.push($(this).val());
  184. });
  185. $("#result").val(result.join(','));
  186. }
  187. set();
  188. </script>