var Maze_Device = { system : [], ids : false, Init : function(ids) { var self = this; this.ids = ids; this.Load(); var func = function() { self.Data(); }; //setInterval(func, 3000); } ,Load : function() { var self = this; if(self.ids) { for(var i in self.ids) { $(i).each(function(index) { self.Bind(index, i, self.ids[i], $(this)); }); } } } ,Data : function() { var self = this; var e = $("#device_data"); if(e.length) { var url = e.attr('data-url') + '&callback=?'; $.getJSON(url, function(t) { var state = 1; if(e.find('.business-list').eq(0).length) { e.find('.business-list').eq(0).html(t.data); state = 2; } if(e.find('.business-list').eq(1).length) { e.find('.business-list').eq(1).html(t.button); self.Load(); state = 2; } if(state == 1 && e.find('.equip-info').eq(0).length) { e.find('.equip-info').eq(0).html(t.button); self.Load(); state = 2; } if(state == 1) { e.html(t.data); } //$("#baidumap").html(t.map); }) } } ,Bind : function(index, id, config, parent) { var self = this; var key = id + '_' + index; self.system[key] = 1; if(config[0]) { var e = parent.find(config[0]); } else { var e = parent; } if(e.attr('style') == 'background:#bababa') { return; } e.bind('click', function() { var current = $(this); var open_callback = { 'yes' : function() { var state = self.Check(); if(state) { self.Handle(index, key, current, parent, config[1], config[2], 1); Maze.Modal().Close(); self.Data(); } } }; var close_callback = { 'yes' : function() { self.Handle(index, key, current, parent, config[1], config[2], 1); Maze.Modal().Close(); self.Data(); } }; var name = self.system[key] == 1 ? current.attr('current-name') : current.attr('next-name'); var type = self.system[key] == 1 ? current.attr('current-class') : current.attr('next-class'); var body = ''; if($(this).find('.input').length) { body = $(this).find('.input').html(); $(this).find('.input').html(''); } if(type == 'close' && index == 0) { //关闭中,需要开启 Maze.Modal().Alert('确认'+name+current.attr('data-text'), open_callback, body); self.Setting(id, config); } else { //开启中,需要关闭 Maze.Modal().Confirm('确认'+name+current.attr('data-text'), close_callback, body); self.Reset(); } }); } //为setting绑定事件 以后再优化吧 赶出功能来 ,Setting : function(id, config) { if($("#device_box .device_setting").length) { var self = this; if($("#device_box .device_append").length && !$(".device_control_setting").length) { $("#device_box .device_append").each(function(index) { index = index + 1; var key = id + '_' + index; var control = $(".device_control .btn").eq(index); if(control.length) { var name = '同时设置' + control.attr('data-name'); var status = control.attr('current-class'); if(status == 'open') { var current = 'next'; var next = 'current'; var close_active = ''; var open_active = 'active'; } else { var current = 'current'; var next = 'next'; var close_active = 'active'; var open_active = ''; } var open_name = control.attr(current + '-name'); var close_name = control.attr(next + '-name'); var open_attr = ' data-desc="" data-link="'+control.attr(current + '-link')+'" '; var close_attr = ' data-desc="" data-link="'+control.attr(next + '-link')+'" '; var html = '
'+name+':
'+close_name+'
'+open_name+'
'; $(this).append(html); } }); } $(".device_setting").unbind('click').bind('click', function() { if($(this).attr('class').indexOf('active') != -1) { return; } if($(this).attr('class').indexOf('device_control_setting') != -1) { //存在 var k = $(this).attr('data-key'); var n = $(this).attr('data-num'); var i = $(this).attr('data-index'); var p = $(".device_control").eq(i); var c = p.find('.btn'); //self.system[k] = n; console.info(p); self.Handle(i, k, c, p, config[1], config[2], 2); } Maze.BackRun($(this).attr('data-link')); self.Data(); var parent = $(this).parent(); parent.find('.active').removeClass('active'); $(this).addClass('active'); if($(this).attr('data-desc') && parent.prev().find('span').length) { parent.prev().find('span').html('(' + $(this).attr('data-desc') + ')'); } }); } } ,Reset : function() { if($("#device_box .device_setting").length) { $(".device_setting").each(function() { $(this).removeClass('active'); }); } } ,Check : function() { if($("#device_box .device_setting").length) { $(".device_setting").each(function() { if(!$(this).attr('active')) { Maze.Out('请选择' + $(this).html()); return false; } }); } return true; } ,Handle : function(index, key, current, parent, state, button, run) { var self = this; var state = parent.find(state); var background = $(button).eq(index); var param = self.Param(); if(this.system[key] == 1) { parent.removeClass(current.attr('current-class')).addClass(current.attr('next-class')); state.html(current.attr('next-text')); current.html(current.attr('next-name') + current.attr('data-name')); if(background.length) { background.removeClass(current.attr('current-class')).addClass(current.attr('next-class')); } if(run == 1) { Maze.BackRun(current.attr('current-link') + param); self.Data(); } this.system[key] = 2; } else { parent.removeClass(current.attr('next-class')).addClass(current.attr('current-class')); state.html(current.attr('current-text')); current.html(current.attr('current-name') + current.attr('data-name')); if(background.length) { background.removeClass(current.attr('next-class')).addClass(current.attr('current-class')); } if(run == 1) { Maze.BackRun(current.attr('next-link') + param); self.Data(); } this.system[key] = 1; } } ,Param : function() { var value = []; $("#J_content .set_code_list").each(function(i) { var code = []; if($("#J_content .set_code_value_" + i).length) { $("#J_content .set_code_value_" + i).each(function() { if($(this).attr("type") == "radio") { if($(this).get(0).checked) { code.push($(this).val()); } } else { code.push($(this).val()); } }) } value[i] = code.join(" "); }); if(value) { return '&set_code=' + value.join("@"); } else { return ''; } } }