123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346 |
- 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 = '<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>';
-
- $(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 '';
- }
- }
- }
|