apiready = function(){ var ctrl = { init : {}, bind : {}, selected : null, GYNumbers : [], DYNumbers : [], BYQNumbers : [], ZLPNumbers : [], anothersNumbers : [], getNumbers : {}, renderNumbers : {}, sendNumber : {} } ctrl.init = function(){ ctrl.bind(); ctrl.getNumbers(); } ctrl.bind = function(){ //切换调度号 $("#list").on("touchend", ".number", function(){ var number = $(this).data("number"); var name = $(this).data("name"); ctrl.selected = { number : number, name:name}; $(".number").removeClass("active"); $(this).addClass("active"); }) //确定 $("#ok").on("touchend", function(){ ctrl.sendNumber(ctrl.selected); api.closeDrawerPane(); }) //取消 $("#cancel").on("touchend", function(){ api.closeDrawerPane(); }) //监听主页请求调度号的消息 api.addEventListener({ name:'energyAskNumber' },function(ret,err){ ctrl.init(); }); //如果没有初始化 初始化 api.addEventListener({ name:'viewappear' },function(ret,err){ if(!ctrl.selected){ ctrl.init(); } }); } //获取调度号 ctrl.getNumbers = function(){ var url = "/ems/rest/ddnum/list"; var param = { prId : $api.getStorage('powerRoom').prId, flag : 1, // 吃查询能耗点的调度号 } $api.get(url,param, callback); function callback(ret, err){ ctrl.GYNumbers = []; ctrl.DYNumbers = []; ctrl.BYQNumbers = []; ctrl.ZLPNumbers = []; ctrl.anothersNumbers = []; if(!err){ if(ret.code == "200"){ var list = ret.body; var length = list.length; for(var i=0; i 0){ if(!ctrl.selected){ ctrl.selected = { number : classes[i].numbers[0].ddNum, name:classes[i].numbers[0].deivceName} } //分类名称 content += '
'+ classes[i].name +'
' for(var j=0; j'+'('+numbers[j].ddNum+')  '+ numbers[j].deivceName +'' } } } if(!ctrl.selected){ ctrl.sendNumber(null); }else{ $("#list").html(content); ctrl.sendNumber(ctrl.selected); $(".number").eq(0).addClass("active"); } } //发送调度号选中的事件 ctrl.sendNumber = function(selected){ api.sendEvent({ name : 'energySelectedNumber', extra : selected, }); } ctrl.bind(); }