319 lines
8.2 KiB
JavaScript
319 lines
8.2 KiB
JavaScript
var prId = -1;
|
||
var initDdNumberCallbackCount = 0;
|
||
var hasLoaded = false;//标记是否已经加载过调度号
|
||
|
||
var varTypes = {
|
||
"AI" : 1,
|
||
"DI" : 2
|
||
};
|
||
|
||
var varTypesName = {
|
||
1 : "AI",
|
||
2 : "DI"
|
||
};
|
||
|
||
var filterResult = {
|
||
locName: "高压侧",
|
||
ctValue: "1",
|
||
ddNumber: "201",
|
||
varType: varTypes.AI,
|
||
varTypeName: "遥测"
|
||
};
|
||
|
||
|
||
var ctValueAndDdNumbersMap = { AI: {}, DI: {} };
|
||
|
||
/**
|
||
* 根据id清空所有子元素
|
||
*/
|
||
function clearAllChildren(id) {
|
||
var tobeRemoved = $("#" + id);
|
||
tobeRemoved.empty();
|
||
}
|
||
|
||
/**
|
||
* 为单选按钮绑定事件
|
||
*/
|
||
function bindSwitchButtonEvent(buttons) {
|
||
for (var i = 0; i < buttons.length; i++) {
|
||
var btn = $(buttons[i]);
|
||
btn.on('touchend', switchButtonClicked);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 单选按钮被点击
|
||
*/
|
||
function switchButtonClicked() {
|
||
var sender = $(this);
|
||
var brothers = sender.parent().children();
|
||
for (var i = 0; i < brothers.length; i++) {
|
||
var inputElement = $(brothers[i]);
|
||
inputElement.attr('class', 'btn');
|
||
}
|
||
sender.attr('class', 'btn btn-highlight');
|
||
|
||
var groupName = sender.attr('group');
|
||
switch (groupName) {
|
||
case "loc":
|
||
locationButton_clicked(sender);
|
||
break;
|
||
case "ddNumber":
|
||
ddNumberButton_clicked(sender);
|
||
break;
|
||
case "type":
|
||
typeButton_clicked(sender);
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 用户点击了位置按钮中的一个
|
||
*/
|
||
function locationButton_clicked(locButton) {
|
||
filterResult.locName = locButton.attr("value");
|
||
filterResult.ctValue = locButton.attr("ctvalue");
|
||
updateDdNumberView();
|
||
}
|
||
|
||
/**
|
||
* 用户点击了调度号中的一个
|
||
*/
|
||
function ddNumberButton_clicked(ddButton) {
|
||
filterResult.ddNumber = ddButton.attr("value");
|
||
}
|
||
|
||
/**
|
||
* 用户点击了类型按钮中的一个
|
||
*/
|
||
function typeButton_clicked(typeButton) {
|
||
filterResult.varType = typeButton.attr("tpvalue");
|
||
filterResult.varTypeName = typeButton.attr("value");
|
||
updateDdNumberView();
|
||
}
|
||
|
||
/**
|
||
* 清空界面上的所有调度号
|
||
*/
|
||
function clearDdnumberGroup() {
|
||
clearAllChildren("ddnumber-group");
|
||
}
|
||
|
||
/**
|
||
* 弹出提示框
|
||
*/
|
||
function toast(msg) {
|
||
api.toast({
|
||
msg: msg,
|
||
duration: 3000,
|
||
locaiton: 'top'
|
||
});
|
||
}
|
||
|
||
/**
|
||
* 调接口获取各个分类下的调度号
|
||
*/
|
||
function initDdNumber(callback) {
|
||
ctValueAndDdNumbersMap.AI["1"] = [];//AI高压侧调度号数据
|
||
ctValueAndDdNumbersMap.AI["2"] = [];//AI低压侧数据
|
||
ctValueAndDdNumbersMap.AI["3"] = [];//AI变压器数据
|
||
ctValueAndDdNumbersMap.AI["4"] = [];//AI直流屏数据
|
||
ctValueAndDdNumbersMap.AI["5"] = [];//AI信号屏数据
|
||
ctValueAndDdNumbersMap.AI["6"] = [];//AI其他数据
|
||
|
||
ctValueAndDdNumbersMap.DI["1"] = [];//DI高压侧调度号数据
|
||
ctValueAndDdNumbersMap.DI["2"] = [];//DI低压侧数据
|
||
ctValueAndDdNumbersMap.DI["3"] = [];//DI变压器数据
|
||
ctValueAndDdNumbersMap.DI["4"] = [];//DI直流屏数据
|
||
ctValueAndDdNumbersMap.DI["5"] = [];//DI信号屏数据
|
||
ctValueAndDdNumbersMap.DI["6"] = [];//DI其他数据
|
||
initDdNumberCallbackCount = 0;//回调计数清零
|
||
|
||
var tempVarTypeEnmu = [varTypes.AI, varTypes.DI];
|
||
|
||
var url = '/ems/rest/ddnum/list';
|
||
for (var i = 1; i <= 6; i++) {
|
||
for (var j = 0; j < tempVarTypeEnmu.length; j++) {
|
||
|
||
(function (position, varType) {
|
||
var args = { prId: prId, location: position, varType: varType };
|
||
//本次循环的类型:AI、DI
|
||
var tmpType = varTypesName[tempVarTypeEnmu[j]];
|
||
|
||
$api.get(url, args, function (data, err) {
|
||
initDdNumberCallbackCount++;
|
||
if (err) {
|
||
toast("网络请求失败");
|
||
} else {
|
||
if (!data.code || data.code != 200) {
|
||
toast("服务器响应错误" + (data.code ? (",错误码:" + data.code) : ""));
|
||
} else {
|
||
|
||
if (data.body) {
|
||
|
||
for (var i = 0; i < data.body.length; i++) {
|
||
var element = data.body[i];
|
||
ctValueAndDdNumbersMap[tmpType][element.location + ""].push(element.ddNum);
|
||
}
|
||
|
||
}
|
||
}
|
||
}
|
||
|
||
if (initDdNumberCallbackCount == 8) {
|
||
callback();
|
||
}
|
||
});
|
||
})(i, tempVarTypeEnmu[j]);
|
||
}
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 显示调度号不存在和类型不存在的占位符
|
||
*/
|
||
function showEmptyDataPlaceHolder() {
|
||
//隐藏调度号
|
||
$("#ddnumber-group").css("display", "none");
|
||
$("#ddnumber-group-none").css("display", "flex");
|
||
}
|
||
|
||
/**
|
||
* 隐藏调度号不存在和类型不存在的占位符
|
||
*/
|
||
function hideEmptyDataPlaceHolder() {
|
||
//隐藏调度号
|
||
$("#ddnumber-group").css("display", "flex");
|
||
$("#ddnumber-group-none").css("display", "none");
|
||
}
|
||
|
||
/**
|
||
* 更新界面显示的调度号
|
||
*/
|
||
function updateDdNumberView() {
|
||
//先清空界面上显示的调度号
|
||
clearDdnumberGroup();
|
||
var ddNumbers = ctValueAndDdNumbersMap[varTypesName[filterResult.varType]][filterResult.ctValue];
|
||
|
||
if (ddNumbers.length > 0) {
|
||
//隐藏占位符
|
||
hideEmptyDataPlaceHolder();
|
||
for (var i = 0; i < ddNumbers.length; i++) {
|
||
var dd = ddNumbers[i];
|
||
addDdnumber(dd);
|
||
}
|
||
//默认选中第一个调度号
|
||
var childrens = $("#ddnumber-group").children();
|
||
if (childrens.length > 0) {
|
||
var first = $(childrens[0]);
|
||
first.attr("class", "btn btn-highlight");
|
||
ddNumberButton_clicked(first);
|
||
}
|
||
//为所有的调度号绑定事件
|
||
bindSwitchButtonEvent($("#ddnumber-group").children());
|
||
} else {
|
||
//显示占位符
|
||
showEmptyDataPlaceHolder();
|
||
//设置调度号为空
|
||
filterResult.ddNumber = null;
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 向调度号列表中添加一个调度号
|
||
*/
|
||
function addDdnumber(ddnumber) {
|
||
var template = '<input class="btn" type="button" value="{dd}" group="ddNumber"/>';
|
||
template = template.replace("{dd}", ddnumber);
|
||
|
||
$("#ddnumber-group").append(template);
|
||
}
|
||
|
||
/**
|
||
* 用户点击了取消按钮
|
||
*/
|
||
function btCancel_clicked() {
|
||
api.closeDrawerPane();
|
||
}
|
||
|
||
/**
|
||
* 向主窗体发送筛选条件
|
||
*/
|
||
function sendResult() {
|
||
api.sendEvent({
|
||
name: 'filterSelectionChanged',
|
||
extra: filterResult
|
||
});
|
||
}
|
||
|
||
/**
|
||
* 用户点击了确定按钮
|
||
*/
|
||
function btOk_clicked() {
|
||
if (filterResult.ddNumber) {
|
||
sendResult();
|
||
api.closeDrawerPane();
|
||
} else {
|
||
toast("当前分类下暂无数据");
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 主窗体通知侧栏加载数据
|
||
*/
|
||
function rtDataLoadData() {
|
||
//标记为已经加载数据
|
||
hasLoaded = true;
|
||
//获取prId
|
||
prId = $api.getStorage('powerRoom').prId;
|
||
if (prId > 0) {
|
||
//获取各个位置下的调度号
|
||
initDdNumber(function () {
|
||
updateDdNumberView();
|
||
//默认查询高压侧第一个调度号的遥测数据
|
||
sendResult();
|
||
});
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 界面显示完成后的回调
|
||
*/
|
||
function viewAppear(ret, err) {
|
||
if (!hasLoaded) {
|
||
//如果用户滑动打开了侧栏,但是还没加载过数据,则开始加载
|
||
toast("加载中...");
|
||
rtDataLoadData();
|
||
}
|
||
}
|
||
|
||
apiready = function () {
|
||
// 解决iphonex底部标签栏被虚拟home键遮挡
|
||
$api.fixTabBar($api.byId('footer'));
|
||
var ctrl = {
|
||
init: {},
|
||
bind: {}
|
||
}
|
||
|
||
ctrl.bind = function () {
|
||
//主窗体通知侧栏加载数据
|
||
api.addEventListener({ name: 'rtDataLoadData' }, rtDataLoadData);
|
||
//界面显示完成后的回调
|
||
api.addEventListener({ name: 'viewappear' }, viewAppear);
|
||
//为位置和类型绑定事件
|
||
bindSwitchButtonEvent($("#location-group").children());
|
||
bindSwitchButtonEvent($("#type-group").children());
|
||
//为确定和取消绑定事件
|
||
$("#btn-cancel").on("touchend", btCancel_clicked);
|
||
$("#btn-ok").on("touchend", btOk_clicked);
|
||
}
|
||
|
||
ctrl.init = function () {
|
||
ctrl.bind();
|
||
}
|
||
|
||
ctrl.init();
|
||
}
|