device.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. var Maze_Device =
  2. {
  3. system : [],
  4. ids : false,
  5. Init : function(ids)
  6. {
  7. var self = this;
  8. this.ids = ids;
  9. this.Load();
  10. var func = function()
  11. {
  12. self.Data();
  13. };
  14. //setInterval(func, 3000);
  15. }
  16. ,Load : function()
  17. {
  18. var self = this;
  19. if(self.ids)
  20. {
  21. for(var i in self.ids)
  22. {
  23. $(i).each(function(index)
  24. {
  25. self.Bind(index, i, self.ids[i], $(this));
  26. });
  27. }
  28. }
  29. }
  30. ,Data : function()
  31. {
  32. var self = this;
  33. var e = $("#device_data");
  34. if(e.length)
  35. {
  36. var url = e.attr('data-url') + '&callback=?';
  37. $.getJSON(url, function(t)
  38. {
  39. var state = 1;
  40. if(e.find('.business-list').eq(0).length)
  41. {
  42. e.find('.business-list').eq(0).html(t.data);
  43. state = 2;
  44. }
  45. if(e.find('.business-list').eq(1).length)
  46. {
  47. e.find('.business-list').eq(1).html(t.button);
  48. self.Load();
  49. state = 2;
  50. }
  51. if(state == 1 && e.find('.equip-info').eq(0).length)
  52. {
  53. e.find('.equip-info').eq(0).html(t.button);
  54. self.Load();
  55. state = 2;
  56. }
  57. if(state == 1)
  58. {
  59. e.html(t.data);
  60. }
  61. //$("#baidumap").html(t.map);
  62. })
  63. }
  64. }
  65. ,Bind : function(index, id, config, parent)
  66. {
  67. var self = this;
  68. var key = id + '_' + index;
  69. self.system[key] = 1;
  70. if(config[0])
  71. {
  72. var e = parent.find(config[0]);
  73. }
  74. else
  75. {
  76. var e = parent;
  77. }
  78. if(e.attr('style') == 'background:#bababa')
  79. {
  80. return;
  81. }
  82. e.bind('click', function()
  83. {
  84. var current = $(this);
  85. var open_callback =
  86. {
  87. 'yes' : function()
  88. {
  89. var state = self.Check();
  90. if(state)
  91. {
  92. self.Handle(index, key, current, parent, config[1], config[2], 1);
  93. Maze.Modal().Close();
  94. self.Data();
  95. }
  96. }
  97. };
  98. var close_callback =
  99. {
  100. 'yes' : function()
  101. {
  102. self.Handle(index, key, current, parent, config[1], config[2], 1);
  103. Maze.Modal().Close();
  104. self.Data();
  105. }
  106. };
  107. var name = self.system[key] == 1 ? current.attr('current-name') : current.attr('next-name');
  108. var type = self.system[key] == 1 ? current.attr('current-class') : current.attr('next-class');
  109. var body = '';
  110. if($(this).find('.input').length)
  111. {
  112. body = $(this).find('.input').html();
  113. $(this).find('.input').html('');
  114. }
  115. if(type == 'close' && index == 0)
  116. {
  117. //关闭中,需要开启
  118. Maze.Modal().Alert('确认'+name+current.attr('data-text'), open_callback, body);
  119. self.Setting(id, config);
  120. }
  121. else
  122. {
  123. //开启中,需要关闭
  124. Maze.Modal().Confirm('确认'+name+current.attr('data-text'), close_callback, body);
  125. self.Reset();
  126. }
  127. });
  128. }
  129. //为setting绑定事件 以后再优化吧 赶出功能来
  130. ,Setting : function(id, config)
  131. {
  132. if($("#device_box .device_setting").length)
  133. {
  134. var self = this;
  135. if($("#device_box .device_append").length && !$(".device_control_setting").length)
  136. {
  137. $("#device_box .device_append").each(function(index)
  138. {
  139. index = index + 1;
  140. var key = id + '_' + index;
  141. var control = $(".device_control .btn").eq(index);
  142. if(control.length)
  143. {
  144. var name = '同时设置' + control.attr('data-name');
  145. var status = control.attr('current-class');
  146. if(status == 'open')
  147. {
  148. var current = 'next';
  149. var next = 'current';
  150. var close_active = '';
  151. var open_active = 'active';
  152. }
  153. else
  154. {
  155. var current = 'current';
  156. var next = 'next';
  157. var close_active = 'active';
  158. var open_active = '';
  159. }
  160. var open_name = control.attr(current + '-name');
  161. var close_name = control.attr(next + '-name');
  162. var open_attr = ' data-desc="" data-link="'+control.attr(current + '-link')+'" ';
  163. var close_attr = ' data-desc="" data-link="'+control.attr(next + '-link')+'" ';
  164. var html = '<div class="slider"><div class="name">'+name+':</div><div class="list middle clearfix"><div data-key="'+key+'" data-index="'+index+'" data-num="1" class="item device_control_setting device_setting '+close_active+'" '+close_attr+'>'+close_name+'</div><div data-key="'+key+'" data-index="'+index+'" data-num="2" class="item device_control_setting device_setting '+open_active+'" '+open_attr+'>'+open_name+'</div></div></div>';
  165. $(this).append(html);
  166. }
  167. });
  168. }
  169. $(".device_setting").unbind('click').bind('click', function()
  170. {
  171. if($(this).attr('class').indexOf('active') != -1)
  172. {
  173. return;
  174. }
  175. if($(this).attr('class').indexOf('device_control_setting') != -1)
  176. {
  177. //存在
  178. var k = $(this).attr('data-key');
  179. var n = $(this).attr('data-num');
  180. var i = $(this).attr('data-index');
  181. var p = $(".device_control").eq(i);
  182. var c = p.find('.btn');
  183. //self.system[k] = n;
  184. console.info(p);
  185. self.Handle(i, k, c, p, config[1], config[2], 2);
  186. }
  187. Maze.BackRun($(this).attr('data-link'));
  188. self.Data();
  189. var parent = $(this).parent();
  190. parent.find('.active').removeClass('active');
  191. $(this).addClass('active');
  192. if($(this).attr('data-desc') && parent.prev().find('span').length)
  193. {
  194. parent.prev().find('span').html('(' + $(this).attr('data-desc') + ')');
  195. }
  196. });
  197. }
  198. }
  199. ,Reset : function()
  200. {
  201. if($("#device_box .device_setting").length)
  202. {
  203. $(".device_setting").each(function()
  204. {
  205. $(this).removeClass('active');
  206. });
  207. }
  208. }
  209. ,Check : function()
  210. {
  211. if($("#device_box .device_setting").length)
  212. {
  213. $(".device_setting").each(function()
  214. {
  215. if(!$(this).attr('active'))
  216. {
  217. Maze.Out('请选择' + $(this).html());
  218. return false;
  219. }
  220. });
  221. }
  222. return true;
  223. }
  224. ,Handle : function(index, key, current, parent, state, button, run)
  225. {
  226. var self = this;
  227. var state = parent.find(state);
  228. var background = $(button).eq(index);
  229. var param = self.Param();
  230. if(this.system[key] == 1)
  231. {
  232. parent.removeClass(current.attr('current-class')).addClass(current.attr('next-class'));
  233. state.html(current.attr('next-text'));
  234. current.html(current.attr('next-name') + current.attr('data-name'));
  235. if(background.length)
  236. {
  237. background.removeClass(current.attr('current-class')).addClass(current.attr('next-class'));
  238. }
  239. if(run == 1)
  240. {
  241. Maze.BackRun(current.attr('current-link') + param);
  242. self.Data();
  243. }
  244. this.system[key] = 2;
  245. }
  246. else
  247. {
  248. parent.removeClass(current.attr('next-class')).addClass(current.attr('current-class'));
  249. state.html(current.attr('current-text'));
  250. current.html(current.attr('current-name') + current.attr('data-name'));
  251. if(background.length)
  252. {
  253. background.removeClass(current.attr('next-class')).addClass(current.attr('current-class'));
  254. }
  255. if(run == 1)
  256. {
  257. Maze.BackRun(current.attr('next-link') + param);
  258. self.Data();
  259. }
  260. this.system[key] = 1;
  261. }
  262. }
  263. ,Param : function()
  264. {
  265. var value = [];
  266. $("#J_content .set_code_list").each(function(i)
  267. {
  268. var code = [];
  269. if($("#J_content .set_code_value_" + i).length)
  270. {
  271. $("#J_content .set_code_value_" + i).each(function()
  272. {
  273. if($(this).attr("type") == "radio")
  274. {
  275. if($(this).get(0).checked)
  276. {
  277. code.push($(this).val());
  278. }
  279. }
  280. else
  281. {
  282. code.push($(this).val());
  283. }
  284. })
  285. }
  286. value[i] = code.join(" ");
  287. });
  288. if(value)
  289. {
  290. return '&set_code=' + value.join("@");
  291. }
  292. else
  293. {
  294. return '';
  295. }
  296. }
  297. }