SAPUI5 1.44开发文档
一、主要类概述
一、前端类
1、XXX.view.js : html页面视图层,主要在该类中编写前端页面布局、注册控件。XXX为具体业务名称,view.js为固定后缀,不可更改;
2、XXX.controller.js : html页面控制层,主要在该类中编写前后端交互、页面跳转。XXX为具体业务名称,controller.js为固定后缀,不可更改;
3、XXXBrowse.view.js : 一般用于被跳转后的页面展示,展示数据一般为通过后台查询到的数据;XXX为具体业务名称,view.js为固定后缀,不可更改;
2、XXXBrowse.controller.js : 一般用于被跳转后的页面展示页面控制层,主要在该类中编写前后端交互、页面跳转。XXX为具体业务名称,controller.js为固定后缀,不可更改;
二、后端类
1.MobileCoreController.java : 通用处理类,传入参数、SQL代码名,返回数据或执行修改操作
路径 : /source/com/sapdev/crystal/module/controller/MobileCoreController.java
二、基本控件
1.输入框
①注册
MobileApi.view.js
// 注册输入框
oItem = new sap.m.CustomListItem();
oHbox = new sap.m.HBox();
var barcodeInputField = new com.sap.me.control.Input({
id: this.createId("barcodeInput"),// ID 必须唯一 不唯一会导致页面打不开,控制台会提示duplicate错误
maxLength: 40,// 最大字符长度
width: "310px",// 输入框宽度
placeholder: "BARCODE",// 缺省值
showClear: true,// 是否展示清除按钮 会在输入框右边展示
upperCase: true,// 是否转换为大写
showBrowse: true,// 是否展示页面跳转按钮
browseTap: [ oCon.browseBarcodeTap, oCon ]// 点击页面跳转按钮触发事件(对应Controller层browseBarcodeTap方法)
});
oHbox.addItem(barcodeInputField);
oItem.addContent(oHbox);
dcList.addItem(oItem);
②输入框"放大镜点击事件"
MobileApi.controller.js
// 输入框“放大镜图标”点击事件
browseBarcodeTap : function(evt) {
util.Model.removeData("TEMP_BarcodeInputFilterValue");
var oView = this.getView();
if (oView) {
util.Model.setData("TEMP_BarcodeInputFilterValue", oView.byId("barcodeInput").getValue());
}
var bus = sap.ui.getCore().getEventBus();
bus.publish("nav", "to", {// 视图跳转 to、back、home
id : "CrudTestBrowse",// 要跳转的视图ID
data : {
namespace : "com.sap.me.browse.view",// 要跳转的视图的命名空间。完整路径:com.sap.me.browse.view.CrudTestBrowse
fromId : "WipProcess",// 本视图ID
fromNamespace : "com.crystal.wipProcess.view"// 本视图的命名空间 。完整路径:com.sap.me.wipProcess.view.WipProcess
}
});
},
2.文本域
①注册
MobileApi.view.js
oItem = new sap.m.CustomListItem();
oHbox = new sap.m.HBox();
oHbox.setAlignItems(sap.m.FlexAlignItems.Center);
var checkRemark = new sap.m.TextArea({
id : this.createId("checkRemark"),
maxLength : 128,
width : "256px",
height: "128px",
placeholder : "文本域",
liveChange: [oCon.checkRemarkLiveChange, oCon],
});
oHbox.addItem(checkRemark);
oItem.addContent(oHbox);
dcList.addItem(oItem);
②文本域值实时改变事件
MobileApi.controller.js
/* 文本域值实时改变事件*/
checkRemarkLiveChange : function(oControlEvent) {
var value = oControlEvent.getParameter("value"); // 获取文本域值
this.showMessage("文本域值:"+ value);
},
3.日期控件
①注册日期控件
MobileApi.view.js
/* 时间选择器输入框*/
oItem = new sap.m.CustomListItem();
oHbox = new sap.m.HBox();
oHbox.setAlignItems(sap.m.FlexAlignItems.Center);
var dataPicker = new sap.m.DatePicker({// 显示为2023年2月15日数据格式
id: this.createId("dataPicker"),
});
oHbox.addItem(dataPicker);
oItem.addContent(oHbox);
dcList.addItem(oItem);
/* 盘点日期输入框*/
oItem = new sap.m.CustomListItem();
oHbox = new sap.m.HBox();
oHbox.setAlignItems(sap.m.FlexAlignItems.Center);
var checkDate = new sap.m.DatePicker({// 显示为2023/2/15数据格式
id: this.createId("checkDate"),
maxLength: 40,
width: "256px",
placeholder: "盘点日期",
liveChange: [oCon.operationChange, oCon],
valueFormat:"yyyy-MM-dd",
displayFormat:"short",
dateValue:new Date(),
editable: true
});
oHbox.addItem(checkDate);
oItem.addContent(oHbox);
dcList.addItem(oItem);
4.下拉框
4.1下拉框-后台查询
①注册下拉框
MobileApi.view.js
/* add the combobox 下拉框-后台查询*/
oItem = new sap.m.CustomListItem();
oItem.setType(sap.m.ListType.Inactive);
oHbox = new sap.m.HBox();
oHbox.setAlignItems(sap.m.FlexAlignItems.Center);
var selectField = new sap.m.Select({
id: this.createId("wipProcessType"),
width: "300px",
enabled: true,
change: [oCon.processTypeChange, oCon]
});
oHbox.addItem(selectField);
oItem.addContent(oHbox);
dcList.addItem(oItem);
②下拉框赋值
MobileApi.controller.js
var wipProcessTypeControl = oView.byId('wipProcessType');// 下拉框
for (var i = 0; i < oModel.oData.DATA_LIST.length; i++) {
// 给下拉框赋值
item = oModel.oData.DATA_LIST[i];
comboBoxItem = new sap.ui.core.ListItem({
id: this.createId("wipProcessComboBoxItem"+i),// 确保ID唯一
text: item.BARCODE,// 展示值
key: item.RN// 实际值
});
wipProcessTypeControl.addItem(comboBoxItem);
}
③拉框-后台查询 改变事件
MobileApi.controller.js
// 下拉框-后台查询 改变事件
processTypeChange : function(oControlEvent){
var oView = this.getView();
var oSelectControl = oView.byId("wipProcessType");
if (oSelectControl) {
var oItem = oSelectControl.getSelectedItem();
if (oItem) {
var sKey = oItem.getKey();
var sText = oItem.getText();
this.showMessage(sKey + "-" + sText);
}
}
},
4.2 下拉框-外部类
①注册
MobileApi.view.js
这段代码需加在MobileApi.view.js类中最上面(导入外部文件)
jQuery.sap.require(“com.crystal.wipProcess.view.WipSelectList”);
/* 下拉框-外部类*/
oItem = new sap.m.CustomListItem();
oHbox = new sap.m.HBox();
oHbox.setAlignItems(sap.m.FlexAlignItems.Center);
var selectField = new sap.m.Select({
id: this.createId("collectionType"),
width: "256px",
enabled: true,
change: [oCon.collectionTypeChange, oCon]
});
var sTypes = com.crystal.wipProcess.view.WipSelectList; // 外部类(返回一个数组)
for (var i = 0; i < sTypes.length; i++) {
var oListItem = new sap.ui.core.ListItem({
id: this.createId("collectionType"+i),
text: sTypes[i].value,
key: sTypes[i].key
});
selectField.addItem(oListItem);
if (i == 1) {
selectField.setSelectedItem(oListItem);// 设置默认选中
}
}
oHbox.addItem(selectField);
oItem.addContent(oHbox);
dcList.addItem(oItem);
②外部类文件
WipSelectList.js
jQuery.sap.declare("com.crystal.wipProcess.view.WipSelectList");
com.crystal.wipProcess.view.WipSelectList = [
{key : "1", value : "SFC"},
{key : "2", value : "SHOP_ORDER"},
{key : "3", value : "PROCESS_LOT"}
];
5.单选按钮
①注册
MobileApi.view.js
// 单选按钮
var radioButton = new sap.m.RadioButton({
id: this.createId("radioButton"),
groupName: "radioGroup",
editable: true,
text: "男",
valueState: sap.ui.core.ValueState.Information,
select: [oCon.radioButtonTap, oCon]
});
var radioButton2 = new sap.m.RadioButton({
id: this.createId("radioButton2"),
groupName: "radioGroup",
editable: true,
text: "女",
valueState: sap.ui.core.ValueState.Information,
select: [oCon.radioButtonTap, oCon]
});
②选中事件
MobileApi.controller.js
// 单选按钮
radioButtonTap : function(oControlEvent){
var oView = this.getView();
var oRadioControl = oView.byId("radioButton");
console.log(oRadioControl.getText());
},
6.复选框
①注册
MobileApi.view.js
/* 复选框*/
oItem = new sap.m.CustomListItem();
oHbox = new sap.m.HBox();
oHbox.setAlignItems(sap.m.FlexAlignItems.Center);
var checkBox = new sap.m.CheckBox({
id: this.createId("checkBox"),
editable: true, /*是否允许编辑 默认true 背景颜色不变且不允许编辑*/
enabled: true, /*是否启用 默认true 背景颜色变浅且不允许编辑*/
name: "复选框1", /*复选框名称 可不唯一*/
selected: true, /*是否选中 设置true则默认选中*/
text: "我是复选框1", /*复选框右边显示文本*/
valueState: sap.ui.core.ValueState.None, /*"None", "Error", "Warning", "Success" and "Information" 默认None*/
wrapping: false, /*确定标签的文本是否换行 设置为 (默认值) 时,标签的文本将在末尾用省略号截断 默认false*/
select: [oCon.checkBoxChange, oCon], /*选中取消触发事件*/
});
var checkBox2 = new sap.m.CheckBox({
id: this.createId("checkBox2"),
editable: true, /*是否允许编辑 默认true 背景颜色不变且不允许编辑*/
enabled: true, /*是否启用 默认true 背景颜色变浅且不允许编辑*/
name: "复选框2", /*复选框名称 可不唯一*/
selected: true, /*是否选中 设置true则默认选中*/
text: "我是复选框2我是复选框2我是复选框2我是复选框2我是复选框2", /*复选框右边显示文本*/
valueState: sap.ui.core.ValueState.Information, /*"None", "Error", "Warning", "Success" and "Information" 默认None*/
//wrapping: true, /*设置为 (默认值) 时,标签的文本将在末尾用省略号截断 默认false 一般需配合width*/
width: "200px", /*宽度*/
select: [oCon.checkBoxChange, oCon], /*选中取消触发事件*/
});
oHbox.addItem(checkBox);
oHbox.addItem(checkBox2); /* 同时添加两个不一样的组件会在同一行中展示*/
oItem.addContent(oHbox);
dcList.addItem(oItem);
②复选框选中取消事件
MobileApi.controller.js
/*复选框选中取消事件*/
checkBoxChange : function(oControlEvent){
var oView = this.getView();
var bacodeInputPlaceholder = oView.byId("barcodeInput").getPlaceholder();
var checkBoxs = ["checkBox","checkBox2"];
var isTrue = this.validateData("barcodeInput");
checkBoxs.forEach(function(item,index,checkBoxs){
var checkBox = oView.byId(item); /*获取ID*/
var checkBoxGetEditable = checkBox.getEditable(); /*是否允许编辑*/
var checkBoxGetGetEnabled = checkBox.getEnabled(); /*是否启用*/
var checkBoxGetName = checkBox.getName(); /*名称*/
var checkBoxGetSelected = checkBox.getSelected(); /*是否选中*/
var checkBoxGetTabIndex = checkBox.getTabIndex(); /*选项卡索引*/
var checkBoxGetText = checkBox.getText(); /*文本*/
var checkBoxGetValueState = checkBox.getValueState(); /*属性值状态的当前值*/
var checkBoxGetWidth = checkBox.getWidth(); /*宽度*/
if(isTrue){
checkBox.setValueState(sap.ui.core.ValueState.None);
}else {
checkBox.setSelected(false);
checkBox.setValueState(sap.ui.core.ValueState.Error);
}
})
},
7.组合框
7.1 组合框(输入框+下拉框)
①注册
MobileApi.view.js
/* 组合框(输入框+下拉框) */
oItem = new sap.m.CustomListItem();
oHbox = new sap.m.HBox();
oHbox.setAlignItems(sap.m.FlexAlignItems.Center);
var comboBox = new sap.m.ComboBox({
id: this.createId("comboBox"),
//selectedKeys: "1", // 默认选中的Key
showSecondaryValues: true,// 是否展示两列数据
filterSecondaryValues: true,// 是否同时通过两列数据筛选 但是未生效,应该是版本过低不支持该属性
valueState: sap.ui.core.ValueState.Warning, /* 值显示状态"None", "Error", "Warning", "Success" and "Information" 默认None*/
width: "300px",
placeholder: "组合框(输入框+下拉框)",
change: [oCon.comboBoxSelectionChange, oCon], /*组合框(输入框+下拉框)选中事件*/
//selectionFinish: [oCon.multiComboBoxSelectionFinish, oCon], /*组合框(输入框+下拉框)选中完成事件*/
});
var comboBoxText = new sap.m.Text({
id :this.createId("comboBoxText"),
text: "组合框(输入框+下拉框):",
});
oHbox.addItem(comboBoxText);
oHbox.addItem(comboBox);
oItem.addContent(oHbox);
dcList.addItem(oItem);
②赋值
MobileApi.controller.js
var comboBoxControl = oView.byId('comboBox');// 组合框(输入框+下拉框)
for (var i = 0; i < oModel.oData.DATA_LIST.length; i++) {
// 给组合框(输入框+下拉框)赋值
comboBoxItem = new sap.ui.core.ListItem({
id: this.createId("comboBoxItem"+i),// 确保ID唯一
text: item.BARCODE,// 展示值
additionalText: item.HANDLE,// 展示值2(两列显示)
key: item.RN,
});
comboBoxControl.addItem(comboBoxItem);
}
③值改变事件
MobileApi.controller.js
/* 组合框(输入框+下拉框)选中事件 */
comboBoxSelectionChange : function(oControlEvent) {
var value = oControlEvent.getParameter("value");
this.showMessage(value);
},
8.开关控件
①注册
MobileApi.view.js
// 开关控件
oItem = new sap.m.CustomListItem();
oHbox = new sap.m.HBox();
oHbox.setAlignItems(sap.m.FlexAlignItems.Center);
var switchControl = new sap.m.Switch({
id: this.createId("switchControl"),
customTextOff: "关闭",
customTextOn: "打开",
//type: sap.m.SwitchType.AcceptReject,// 值 sap.m.SwitchType.Default开和关 sap.m.SwitchType.AcceptReject √和X
change: [oCon.switchControlChange, oCon],
});
oHbox.addItem(switchControl);
oItem.addContent(oHbox);
dcList.addItem(oItem);
② 开关控件的切换事件
MobileApi.controller.js
/* 开关控件的切换事件*/
switchControlChange : function(oControlEvent) {
var oView = this.getView();
var switchControl = oView.byId("switchControl");
var state = switchControl.getState(); // 当前状态 true false
},
9.滑块控件
①注册
MobileApi.view.js
// 数字滑块
oItem = new sap.m.CustomListItem();
oHbox = new sap.m.HBox();
oHbox.setAlignItems(sap.m.FlexAlignItems.Center);
var rangeSlider = new sap.m.RangeSlider({
id: this.createId("rangeSlider"),
min: 0,
max: 100,
width: "500px",
change: [oCon.rangeSliderChange, oCon],
})
oHbox.addItem(rangeSlider);
oItem.addContent(oHbox);
dcList.addItem(oItem);
② 滑块控件的切换事件
MobileApi.controller.js
/* 滑块控件的值改变事件*/
rangeSliderChange : function(oControlEvent) {
var oView = this.getView();
var rangeSlider = oView.byId("rangeSlider");
var range = rangeSlider.getRange();// 获取第一个控件和第二个控件的值
var value = rangeSlider.getValue();// 获取第一个控件的值
var value2 = rangeSlider.getValue2();// 获取第二个控件的值
},
三、弹框
1、忙碌对话框
MobileApi.view.js
/* 忙碌对话框*/
var busyDialog = new sap.m.BusyDialog({
id: this.createId("busyDialog"),
title: "忙碌对话框",
text: "我忙碌中",
cancelButtonText: "我要关闭你",
showCancelButton: true,
})
// 打开忙碌对话框
oItem = new sap.m.CustomListItem();
oHbox = new sap.m.HBox();
oHbox.setAlignItems(sap.m.FlexAlignItems.Center);
var openBusyDialogButton = new sap.m.Button({
id: this.createId("openBusyDialogButton"),
icon: "sap-icon://decision",
text: "打开忙碌对话框",
type: sap.m.ButtonType.Attention,/* 按钮类型*/
tap: [oCon.openBusyDialogButtonTap, oCon],
})
MobileApi.controller.js
// 忙碌对话框打开按钮
openBusyDialogButtonTap : function(oControlEvent) {
var busyDialog = this.getView().byId("busyDialog");
busyDialog.open();// 打开对话框
window.setTimeout(function(){
busyDialog.close(); // 定时自动关闭对话框
}, 5000);
},
2、确认框
MobileApi.view.js
// 打开确认框
var openConfirmDialogButton = new sap.m.Button({
id: this.createId("openConfirmDialogButton"),
icon: "sap-icon://decision",
text: "打开确认框",
type: sap.m.ButtonType.Attention,/* 按钮类型*/
tap: [oCon.openConfirmDialogButtonTap, oCon],
})
MobileApi.controller.js
// 确认对话框打开按钮
openConfirmDialogButtonTap : function(oControlEvent) {
if (!this.oApproveDialog) {
this.oApproveDialog = new sap.m.Dialog({
type: sap.m.DialogType.Message, // sap.m.DialogType.Standard
title: "Confirm",
content: new sap.m.Text({
id :this.createId("confirmText"),
text: "Do you want to submit this order?",
}),
beginButton: new sap.m.Button({
type: sap.m.ButtonType.Emphasized,
text: "Submit",
press: function () {
this.showMessage("Submit pressed!");
this.oApproveDialog.close();
}.bind(this)
}),
endButton: new sap.m.Button({
text: "Cancel",
press: function () {
this.oApproveDialog.close();
}.bind(this)
})
});
}
this.oApproveDialog.open();
},
3、提示框
MobileApi.view.js
// 打开提示框
var openAlertDialogButton = new sap.m.Button({
id: this.createId("openAlertDialogButton"),
icon: "sap-icon://decision",
text: "打开提示框",
type: sap.m.ButtonType.Accept,/* 按钮类型*/
tap: [oCon.openAlertDialogButtonTap, oCon],
})
MobileApi.controller.js
// 打开提示框
openAlertDialogButtonTap : function(oControlEvent) {
sap.m.MessageBox.alert("The quantity you have reported exceeds the quantity planed.");
},
4、错误提示框
MobileApi.view.js
// 打开错误提示框
var openErrorDialogButton = new sap.m.Button({
id: this.createId("openErrorDialogButton"),
icon: "sap-icon://decision",
text: "打开错误提示框",
type: sap.m.ButtonType.Accept,/* 按钮类型*/
tap: [oCon.openErrorDialogButtonTap, oCon],
})
MobileApi.controller.js
// 打开错误提示框
openErrorDialogButtonTap : function(oControlEvent) {
sap.m.MessageBox.error("The quantity you have reported exceeds the quantity planed.");
},
5、信息提示框
MobileApi.view.js
// 打开信息提示框
var openInfoDialogButton = new sap.m.Button({
id: this.createId("openInfoDialogButton"),
icon: "sap-icon://decision",
text: "打开信息提示框",
type: sap.m.ButtonType.Accept,/* 按钮类型*/
tap: [oCon.openInfoDialogButtonTap, oCon],
})
MobileApi.controller.js
// 打开信息提示框
openInfoDialogButtonTap : function(oControlEvent) {
sap.m.MessageBox.information("The quantity you have reported exceeds the quantity planed.");
},
6、警告提示框
MobileApi.view.js
// 打开警告提示框
var openWarningDialogButton = new sap.m.Button({
id: this.createId("openWarningDialogButton"),
icon: "sap-icon://decision",
text: "打开警告提示框",
type: sap.m.ButtonType.Accept,/* 按钮类型*/
tap: [oCon.openWarningDialogButtonTap, oCon],
})
MobileApi.controller.js
// 打开警告提示框
openWarningDialogButtonTap : function(oControlEvent) {
sap.m.MessageBox.warning("The quantity you have reported exceeds the quantity planed.");
},
7、成功提示框
MobileApi.view.js
// 打开成功提示框
var openSuccessDialogButton = new sap.m.Button({
id: this.createId("openSuccessDialogButton"),
icon: "sap-icon://decision",
text: "打开成功提示框",
type: sap.m.ButtonType.Accept,/* 按钮类型*/
tap: [oCon.openSuccessDialogButtonTap, oCon],
})
MobileApi.controller.js
// 打开成功提示框
openSuccessDialogButtonTap : function(oControlEvent) {
sap.m.MessageBox.success("The quantity you have reported exceeds the quantity planed.");
},
8、新增
MobileApi.view.js
// 打开新增框
var openAddDialogButton = new sap.m.Button({
id: this.createId("openAddDialogButton"),
icon: "sap-icon://add",
text: "新增",
type: sap.m.ButtonType.Accept,/* 按钮类型*/
tap: [oCon.openAddDialogButtonTap, oCon],
})
MobileApi.controller.js
// 新增对话框打开按钮
openAddDialogButtonTap : function(oControlEvent) {
var oView = this.getView();
if (!this.oAddDialog) { // 控件只能new一次 因为Id必须是唯一的(否则会提示duplicate错误)
this.oAddDialog = new sap.m.Dialog({
type: sap.m.DialogType.Standard, // sap.m.DialogType.Standard
title: "ADD",
content: [
new sap.m.Label({
id :this.createId("userNameLabel"),
text: "Username:",
}),
new com.sap.me.control.Input({
id: this.createId("userNameInput"),
maxLength: 20,
width: "200px",
type:sap.m.InputType.Text,
placeholder: "Enter username",
}),
new sap.m.Label({
id :this.createId("passwordLabel"),
text: "Password:",
}),
new com.sap.me.control.Input({
id: this.createId("passwordInput"),
maxLength: 10,
width: "200px",
type:sap.m.InputType.Password,
placeholder: "Enter Password",
}),
new sap.m.Label({
id :this.createId("emailLabel"),
text: "Email:",
}),
new com.sap.me.control.Input({
id: this.createId("emailInput"),
maxLength: 10,
width: "200px",
type:sap.m.InputType.Email,
placeholder: "Enter e-mail",
}),
],
beginButton: new sap.m.Button({
type: sap.m.ButtonType.Emphasized,
text: "Submit",
press: function () {
var userNameInput = oView.byId("userNameInput").getValue();
var passwordInput = oView.byId("passwordInput").getValue();
var emailInput = oView.byId("emailInput").getValue();
this.showMessage("Submit pressed!UserName:"+userNameInput+"Password:"+passwordInput+"Email:"+emailInput);
this.oApproveDialog.close();
}.bind(this)
}),
endButton: new sap.m.Button({
text: "Cancel",
press: function () {
this.oAddDialog.close();
}.bind(this)
}),
afterClose: function () {
oDialog.destroy();
}
});
}
this.oAddDialog.open();
},
四、列表
1.多列弹出框的制作
MobileApi.controller.js
// 多列弹出框制作
handleSearch : function () {
/* 效果:在当前页面弹出一个展示多列数据的弹框,
最上方输入框可以绑定列表中的数据列从而实现数据过滤
【var oFilter = new sap.ui.model.Filter("HANDLE", sap.ui.model.FilterOperator.Contains, sValue);】*/
var oView = this.getView();
var site = util.Model.getData(util.CommonKey.CurrentSite); // 站点
var handle = oView.byId("handleInput").getValue(); // SFC
var jsonParam = {
'SITE_V' : site,
'EXT_CODE' : 'CRYSTAL_0042_REPORT_CRUD_TEST_1',
'HANDLE' : handle
};
var oUrl = '/crystalmobile/mobile/data/core/exec_data_code';
var oModel = new sap.ui.model.json.JSONModel();
oModel.forceNoCache(true);
oModel.setSizeLimit(999999);
oModel.setDefaultBindingMode(sap.ui.model.BindingMode.OneWay);
oModel.loadData(oUrl, jsonParam, false, "POST");
if (oModel) {
var sMsg = oModel.oData.MSG;
oModel.oData = JSON.parse(oModel.oData.message);
if(sMsg){
this.showMessage(sMsg);
return;
}else{
var DATA_LIST = oModel.oData.DATA_LIST;
/** 开始制作弹出选中框进行选择 多列弹出框 BEGIN */
if (!this._oDialog) {
this._oDialog = new sap.m.TableSelectDialog({
search : function(oEvent) {
var sValue = oEvent.getParameter("value");
var oFilter = new sap.ui.model.Filter("HANDLE", sap.ui.model.FilterOperator.Contains, sValue);
var oBinding = oEvent.getSource().getBinding("items");
oBinding.filter([ oFilter ]);
},
confirm : function(oEvent) {
var aContexts = oEvent.getParameter("selectedContexts");
if (aContexts.length) {
oView.byId("handleInput").setValue(aContexts[0].getObject().HANDLE);
}
},
columns: [new sap.m.Column({
header: new sap.m.Label({
text: "主键"
})
}), new sap.m.Column({
header: new sap.m.Label({
text: "条码"
})
}), new sap.m.Column({
header: new sap.m.Label({
text: "创建时间"
})
})]
});
var itemTemplate = new sap.m.ColumnListItem({
cells: [new sap.m.Text({
text: "{HANDLE}"
}), new sap.m.Text({
text: "{BARCODE}"
}), new sap.m.Text({
text: "{CREATED_TIME}"
})]
});
if (this._oDialog.getBinding("items")) {
this._oDialog.getBinding("items").filter([]);
}
this._oDialog.setModel(oModel);
this._oDialog.bindAggregation("items", "/DATA_LIST", itemTemplate);
this._oDialog.open();
this._oDialog = null;
/** 开始制作弹出选中框进行选择 多列弹出框 END */
}
}
}
},
2.列表直接展示数据
MobileApi.view.js
/* oTable 页面列表*/
var oTable = new sap.m.Table("listTable", {
inset : true,
mode : sap.m.ListMode.None,
includeItemInSelection : true
});
oTable.addColumn(new sap.m.Column({
header : new sap.m.Text({
text : "主键"
})
}));
oTable.addColumn(new sap.m.Column({
header : new sap.m.Text({
text : "条码",
ColumnListItem: true,
})
}));
var oTemplate = new sap.m.ColumnListItem({
vAlign : "Middle",
type : "Active",
cells : [ new sap.m.Text({
text : "{HANDLE}",
wrapping : true,
maxlines : "2"
}), new sap.m.Text({
text : "{BARCODE}",
wrapping : true,
maxlines : "2",
ColumnListItem: true,
}) ]
});
// 先解除绑定,再重新绑定
oTable.unbindItems();
oTable.bindItems("/listData", oTemplate);
五、控件类型
1、输入框类型
sap.m.InputType.Number, // 值:固定前缀:sap.m.InputType. 可以的值有 Email Number Password Tel Text Url
2、按钮类型
sap.m.ButtonType.Accept, // 值:固定前缀:sap.m.ButtonType. 可以的值有 Attention Accept Back Critical Default Emphasized
Ghost Negative Neutral Reject Success Transparent Unstyled Up
六、Demo
1、MobileApi.view.js
jQuery.sap.require("com.sap.me.control.Input");// 引用外部JS
jQuery.sap.require("com.crystal.mobileApi.view.MobileApiSelectList");;// 引用外部JS
/**
* 移动端开发-API
*/
sap.ui.jsview("com.crystal.mobileApi.view.MobileApi", {
getControllerName: function() { // 返回相应控制层
return "com.crystal.mobileApi.view.MobileApi";
},
onBeforeShow : function(evt) {// 页面展示前执行代码
this.getController().onBeforeShow(evt);
},
onAfterShow : function(evt) {// 页面展示后执行代码
this.getController().onAfterShow(evt);
},
createContent : function(oCon) { // 创建组件
/** ------------------------------------------------------------按钮Begin------------------------------------------------------------*/
// 开始按钮
var startButton = new sap.m.Button({
id: this.createId("startButton"),/* ID*/
type: sap.m.ButtonType.Default,/* 按钮类型*/
icon: "sap-icon://accept",/* 按钮图标*/
text: util.I18NUtility.getLocaleSpecificText("START.DEFAULT.BUTTON"),/* 按钮显示文本(国际化)*/
//text: "开始",/* 按钮显示文本(非国际化)*/
enabled: true,/* 是否启用*/
tap : [ oCon.startButtonTap, oCon ]/* 按钮点击事件*/
});
startButton.addStyleClass("footerBarButtonPadding");/* 按钮添加CSS样式*/
//注销按钮
var signoffButton = new sap.m.Button({
id: this.createId("signoffButton"),
type: sap.m.ButtonType.Default,
icon: "sap-icon://error",
text: util.I18NUtility.getLocaleSpecificText("MOBILE_UNSUBSCRIBE.DEFAULT.BUTTON"),
text: "注销",
enabled: true,
tap : [ oCon.signoffButtonTap, oCon ]
});
// 装配按钮
var assembleButton = new sap.m.Button({
id: this.createId("assembleButton"),
type: sap.m.ButtonType.Default,
icon: "sap-icon://add",
text: "装配",
enabled: true,
tap : [ oCon.assembleButtonTap, oCon ]
});
// 完成按钮
var completeButton = new sap.m.Button({
id: this.createId("completeButton"),
type: sap.m.ButtonType.Default,
icon: "sap-icon://SAP-icons-TNT/content-enricher",
text: "完成",
enabled: true,
tap : [ oCon.completeButtonTap, oCon ]
});
// 清除按钮
var clearButton = new sap.m.Button({
id: this.createId("clearButton"),
type: sap.m.ButtonType.Default,
icon: "sap-icon://eraser",
enabled: true,
visible: true,
tap : [ oCon.clearButtonTap, oCon ]
});
var footerBar = new sap.m.Bar({
contentLeft: [],
contentMiddle: [startButton,signoffButton,assembleButton],
contentRight: []
});
/** ------------------------------------------------------------按钮END------------------------------------------------------------ */
/*create page*/
this.page = new sap.m.Page({
id: this.createId("mobileApiPage"),
title: "我生效了",
icon: "sap-icon://BusinessSuiteInAppSymbols/icon-3d",
showNavButton: true,
navButtonTap: [ oCon.navButtonTap, oCon ],
headerContent: [
clearButton
],
footer: footerBar
});
var dcList = new sap.m.List({inset : true});
/**------------------------------------------------------------ 输入框Begin ------------------------------------------------------------*/
/*条码输入框*/
oItem = new sap.m.CustomListItem();
oHbox = new sap.m.HBox();
var barcodeInputField = new com.sap.me.control.Input({
id: this.createId("barcodeInput"),// ID 必须唯一 不唯一会导致页面打不开,控制台会提示duplicate错误
maxLength: 40,// 最大字符长度
width: "310px",// 输入框宽度
placeholder: "BARCODE",// 缺省值
showClear: true,// 是否展示清除按钮 会在输入框右边展示
upperCase: true,// 是否转换为大写
showBrowse: true,// 是否展示页面跳转图标
browseTap: [ oCon.browseBarcodeTap, oCon ]// 点击页面跳转图标触发事件(对应Controller层browseBarcodeTap方法)
});
oHbox.addItem(barcodeInputField);
oItem.addContent(oHbox);
dcList.addItem(oItem);
/* 主键输入框*/
oItem = new sap.m.CustomListItem();
oHbox = new sap.m.HBox();
oHbox.setAlignItems(sap.m.FlexAlignItems.Center);
var handleInputField = new com.sap.me.control.Input({
id: this.createId("handleInput"),
maxLength: 20,
width: "310px",
placeholder: "Handle",
showClear: true,
upperCase: false,
showBrowse: true,
browseTap: [ oCon.browseHandleTap, oCon ]
});
oHbox.addItem(handleInputField);
oItem.addContent(oHbox);
dcList.addItem(oItem);
/*打印份数输入框*/
oItem = new sap.m.CustomListItem();
oHbox = new sap.m.HBox();
oHbox.setAlignItems(sap.m.FlexAlignItems.Center);
var printNumberInputField = new com.sap.me.control.Input({
id: this.createId("printNumberInput"),
maxLength: 2,
width: "310px",
placeholder: "printNumber",
type: sap.m.InputType.Number, // 值:固定前缀:sap.m.InputType. 可以的值有 Email Number Password Tel Text Url
liveChange: [oCon.printNumberChange, oCon],
showClear: true,
});
printNumberInputField.addEventDelegate({
onkeydown : function(e) {
var keyCode = ("which" in e) ? e.which : e.keyCode;
if( keyCode == 9 ) {
oCon.printNumberChange(e);
}
}
});
oHbox.addItem(printNumberInputField);
oItem.addContent(oHbox);
dcList.addItem(oItem);
/* 时间选择器输入框*/
oItem = new sap.m.CustomListItem();
oHbox = new sap.m.HBox();
oHbox.setAlignItems(sap.m.FlexAlignItems.Center);
var dataPicker = new sap.m.DatePicker({// 显示为2023年2月15日数据格式
id: this.createId("dataPicker"),
});
oHbox.addItem(dataPicker);
oItem.addContent(oHbox);
dcList.addItem(oItem);
/* 盘点日期输入框*/
oItem = new sap.m.CustomListItem();
oHbox = new sap.m.HBox();
oHbox.setAlignItems(sap.m.FlexAlignItems.Center);
var checkDate = new sap.m.DatePicker({// 显示为2023/2/15数据格式
id: this.createId("checkDate"),
maxLength: 40,
width: "256px",
placeholder: "盘点日期",
liveChange: [oCon.operationChange, oCon],
valueFormat:"yyyy-MM-dd",
displayFormat:"short",
dateValue:new Date(),
editable: true
});
oHbox.addItem(checkDate);
oItem.addContent(oHbox);
dcList.addItem(oItem);
/**------------------------------------------------------------ 输入框End------------------------------------------------------------*/
/**------------------------------------------------------------ 下拉框Begin------------------------------------------------------------*/
/* add the combobox 下拉框-后台查询*/
oItem = new sap.m.CustomListItem();
oItem.setType(sap.m.ListType.Inactive);
oHbox = new sap.m.HBox();
oHbox.setAlignItems(sap.m.FlexAlignItems.Center);
var selectField = new sap.m.Select({
id: this.createId("wipProcessType"),
// width: "100px",
enabled: true,
selectedKey: "",
autoAdjustWidth: true,// 自动调整宽度
change: [oCon.processTypeChange, oCon]
});
var oListItemDefault = new sap.ui.core.ListItem({
id: this.createId("wipProcessTypeDefault"),
text: "===请选择===",
key: "DefaultKey"
});
selectField.addItem(oListItemDefault);
selectField.setSelectedItem(oListItemDefault);
oHbox.addItem(selectField);
oItem.addContent(oHbox);
dcList.addItem(oItem);
/* 下拉框-外部类*/
oItem = new sap.m.CustomListItem();
oHbox = new sap.m.HBox();
oHbox.setAlignItems(sap.m.FlexAlignItems.Center);
var selectField = new sap.m.Select({
id: this.createId("collectionType"),
//width: "256px",
autoAdjustWidth: true,// 自动调整宽度
enabled: true,
change: [oCon.collectionTypeChange, oCon]
});
selectField.addItem(oListItemDefault);
selectField.setSelectedItem(oListItemDefault);
var sTypes = com.crystal.mobileApi.view.MobileApiSelectList; // 外部类(返回一个数组)
for (var i = 0; i < sTypes.length; i++) {
var oListItem = new sap.ui.core.ListItem({
id: this.createId("collectionType"+i),
text: sTypes[i].value,
key: sTypes[i].key
});
selectField.addItem(oListItem);
if (i == 1) {
// selectField.setSelectedItem(oListItem);// 设置默认选中
}
}
oHbox.addItem(selectField);
oItem.addContent(oHbox);
dcList.addItem(oItem);
/**------------------------------------------------------------ 下拉框END ------------------------------------------------------------*/
/* oTable 页面列表*/
var oTable = new sap.m.Table("listTable", {
inset : true,
mode : sap.m.ListMode.None,
includeItemInSelection : true
});
oTable.addColumn(new sap.m.Column({
header : new sap.m.Text({
text : "主键"
})
}));
oTable.addColumn(new sap.m.Column({
header : new sap.m.Text({
text : "条码",
ColumnListItem: true,
})
}));
var oTemplate = new sap.m.ColumnListItem({
vAlign : "Middle",
type : "Active",
cells : [ new sap.m.Text({
text : "{HANDLE}",
wrapping : true,
maxlines : "2"
}), new sap.m.Text({
text : "{BARCODE}",
wrapping : true,
maxlines : "2",
ColumnListItem: true,
}) ]
});
// 先解除绑定,再重新绑定
oTable.unbindItems();
oTable.bindItems("/listData", oTemplate);
oTable.setMode(sap.m.ListMode.MultiSelect);// 设置多选模式
/* 复选框*/
oItem = new sap.m.CustomListItem();
oHbox = new sap.m.HBox();
oHbox.setAlignItems(sap.m.FlexAlignItems.Center);
var checkBox = new sap.m.CheckBox({
id: this.createId("checkBox"),
editable: true, /*是否允许编辑 默认true 背景颜色不变且不允许编辑*/
enabled: true, /*是否启用 默认true 背景颜色变浅且不允许编辑*/
name: "复选框1", /*复选框名称 可不唯一*/
selected: true, /*是否选中 设置true则默认选中*/
text: "我是复选框1", /*复选框右边显示文本*/
valueState: sap.ui.core.ValueState.None, /*"None", "Error", "Warning", "Success" and "Information" 默认None*/
wrapping: false, /*确定标签的文本是否换行 设置为 (默认值) 时,标签的文本将在末尾用省略号截断 默认false*/
select: [oCon.checkBoxChange, oCon], /*选中取消触发事件*/
});
var checkBox2 = new sap.m.CheckBox({
id: this.createId("checkBox2"),
editable: true, /*是否允许编辑 默认true 背景颜色不变且不允许编辑*/
enabled: true, /*是否启用 默认true 背景颜色变浅且不允许编辑*/
name: "复选框2", /*复选框名称 可不唯一*/
selected: true, /*是否选中 设置true则默认选中*/
text: "我是复选框2我是复选框2我是复选框2我是复选框2我是复选框2", /*复选框右边显示文本*/
valueState: sap.ui.core.ValueState.Information, /*"None", "Error", "Warning", "Success" and "Information" 默认None*/
//wrapping: true, /*设置为 (默认值) 时,标签的文本将在末尾用省略号截断 默认false 一般需配合width*/
width: "200px", /*宽度*/
select: [oCon.checkBoxChange, oCon], /*选中取消触发事件*/
});
// 单选按钮
var radioButton = new sap.m.RadioButton({
id: this.createId("radioButton"),
groupName: "radioGroup",
editable: true,
text: "男",
valueState: sap.ui.core.ValueState.Information,
select: [oCon.radioButtonTap, oCon],
});
var radioButton2 = new sap.m.RadioButton({
id: this.createId("radioButton2"),
groupName: "radioGroup",
editable: true,
text: "女",
valueState: sap.ui.core.ValueState.Information,
select: [oCon.radioButtonTap, oCon],
});
oHbox.addItem(checkBox);
oHbox.addItem(checkBox2); /* 同时添加两个不一样的组件会在同一行中展示*/
oHbox.addItem(radioButton);
oHbox.addItem(radioButton2);
oItem.addContent(oHbox);
dcList.addItem(oItem);
/* 组合框(输入框+下拉框) */
oItem = new sap.m.CustomListItem();
oHbox = new sap.m.HBox();
oHbox.setAlignItems(sap.m.FlexAlignItems.Center);
var comboBox = new sap.m.ComboBox({
id: this.createId("comboBox"),
//selectedKeys: "1", // 默认选中的Key
showSecondaryValues: true,// 是否展示两列数据
filterSecondaryValues: true,// 是否同时通过两列数据筛选 但是未生效,应该是版本过低不支持该属性
valueState: sap.ui.core.ValueState.None, /* 值显示状态"None", "Error", "Warning", "Success" and "Information" 默认None*/
width: "300px",
// required: true,
placeholder: "组合框(输入框+下拉框)",
change: [oCon.comboBoxSelectionChange, oCon], /*组合框(输入框+下拉框)选中事件*/
//selectionFinish: [oCon.multiComboBoxSelectionFinish, oCon], /*组合框(输入框+下拉框)选中完成事件*/
});
var comboBoxText = new sap.m.Text({
id :this.createId("comboBoxText"),
text: "组合框(输入框+下拉框):",
});
oHbox.addItem(comboBoxText);
oHbox.addItem(comboBox);
oItem.addContent(oHbox);
dcList.addItem(oItem);
/* 组合框(输入框+下拉框+复选框)*/
oItem = new sap.m.CustomListItem();
oHbox = new sap.m.HBox();
oHbox.setAlignItems(sap.m.FlexAlignItems.Center);
var multiComboBox = new sap.m.MultiComboBox({
id: this.createId("multiComboBox"),
//selectedKeys: "1",// 默认选中的Key
placeholder: "组合框(输入框+下拉框+复选框)",
showSecondaryValues: true,// 是否展示两列数据
filterSecondaryValues: true,
width: "300px",
selectionChange: [oCon.multiComboBoxSelectionChange, oCon], /*组合框(输入框+下拉框+复选框)选中事件*/
selectionFinish: [oCon.multiComboBoxSelectionFinish, oCon], /*组合框(输入框+下拉框+复选框)选中完成事件*/
});
oHbox.addItem(multiComboBox);
oItem.addContent(oHbox);
dcList.addItem(oItem);
// 文本域
oItem = new sap.m.CustomListItem();
oHbox = new sap.m.HBox();
oHbox.setAlignItems(sap.m.FlexAlignItems.Center);
var checkRemark = new sap.m.TextArea({
id : this.createId("checkRemark"),
maxLength : 128,
width : "256px",
height: "128px",
placeholder : "文本域",
liveChange: [oCon.checkRemarkLiveChange, oCon],
});
oHbox.addItem(checkRemark);
oItem.addContent(oHbox);
dcList.addItem(oItem);
// 开关控件
oItem = new sap.m.CustomListItem();
oHbox = new sap.m.HBox();
oHbox.setAlignItems(sap.m.FlexAlignItems.Center);
var switchControl = new sap.m.Switch({
id: this.createId("switchControl"),
customTextOff: "关闭",
customTextOn: "打开",
//type: sap.m.SwitchType.AcceptReject,// 值 sap.m.SwitchType.Default开和关 sap.m.SwitchType.AcceptReject √和X
change: [oCon.switchControlChange, oCon],
});
oHbox.addItem(switchControl);
oItem.addContent(oHbox);
dcList.addItem(oItem);
// 数字滑块
var rangeSlider = new sap.m.RangeSlider({ // Slider单滑块
id: this.createId("rangeSlider"),
min: 0,
max: 97,
width: "500px",
change: [oCon.rangeSliderChange, oCon],
})
/**------------------------------------------------------------ 对话框Begin ------------------------------------------------------------*/
/* 忙碌对话框*/
var busyDialog = new sap.m.BusyDialog({
id: this.createId("busyDialog"),
title: "忙碌对话框",
text: "我忙碌中",
cancelButtonText: "我要关闭你",
showCancelButton: true,
})
// 打开忙碌对话框
oItem = new sap.m.CustomListItem();
oHbox = new sap.m.HBox();
oHbox.setAlignItems(sap.m.FlexAlignItems.Center);
var openBusyDialogButton = new sap.m.Button({
id: this.createId("openBusyDialogButton"),
icon: "sap-icon://decision",
text: "打开忙碌对话框",
type: sap.m.ButtonType.Attention,/* 按钮类型*/ // 值:固定前缀:sap.m.ButtonType. 可以的值有 Attention Accept Back Critical Default Emphasized Ghost Negative Neutral Reject Success Transparent Unstyled Up
tap: [oCon.openBusyDialogButtonTap, oCon],
})
// 打开确认框
var openConfirmDialogButton = new sap.m.Button({
id: this.createId("openConfirmDialogButton"),
icon: "sap-icon://decision",
text: "打开确认框",
type: sap.m.ButtonType.Attention,/* 按钮类型*/
tap: [oCon.openConfirmDialogButtonTap, oCon],
})
// 打开提示框
var openAlertDialogButton = new sap.m.Button({
id: this.createId("openAlertDialogButton"),
icon: "sap-icon://decision",
text: "打开提示框",
type: sap.m.ButtonType.Accept,/* 按钮类型*/
tap: [oCon.openAlertDialogButtonTap, oCon],
})
// 打开错误提示框
var openErrorDialogButton = new sap.m.Button({
id: this.createId("openErrorDialogButton"),
icon: "sap-icon://decision",
text: "打开错误提示框",
type: sap.m.ButtonType.Accept,/* 按钮类型*/
tap: [oCon.openErrorDialogButtonTap, oCon],
})
// 打开信息提示框
var openInfoDialogButton = new sap.m.Button({
id: this.createId("openInfoDialogButton"),
icon: "sap-icon://decision",
text: "打开信息提示框",
type: sap.m.ButtonType.Accept,/* 按钮类型*/
tap: [oCon.openInfoDialogButtonTap, oCon],
})
// 打开警告提示框
var openWarningDialogButton = new sap.m.Button({
id: this.createId("openWarningDialogButton"),
icon: "sap-icon://decision",
text: "打开警告提示框",
type: sap.m.ButtonType.Accept,/* 按钮类型*/
tap: [oCon.openWarningDialogButtonTap, oCon],
})
// 打开成功提示框
var openSuccessDialogButton = new sap.m.Button({
id: this.createId("openSuccessDialogButton"),
icon: "sap-icon://decision",
text: "打开成功提示框",
type: sap.m.ButtonType.Accept,/* 按钮类型*/
tap: [oCon.openSuccessDialogButtonTap, oCon],
})
// 打开新增框
var openAddDialogButton = new sap.m.Button({
id: this.createId("openAddDialogButton"),
icon: "sap-icon://add",
text: "新增",
type: sap.m.ButtonType.Accept,/* 按钮类型*/
tap: [oCon.openAddDialogButtonTap, oCon],
})
oHbox.addItem(openBusyDialogButton);
oHbox.addItem(openConfirmDialogButton);
oHbox.addItem(openAlertDialogButton);
oHbox.addItem(openErrorDialogButton);
oHbox.addItem(openInfoDialogButton);
oHbox.addItem(openWarningDialogButton);
oHbox.addItem(openSuccessDialogButton);
oHbox.addItem(openAddDialogButton);
oItem.addContent(oHbox);
dcList.addItem(oItem);
/**------------------------------------------------------------ 对话框End ------------------------------------------------------------*/
this.page.addContent(dcList);
this.page.addContent(rangeSlider);
this.page.addContent(oTable);
return this.page;
}
});
2、MobileApi.controller.js
jQuery.sap.require("sap.m.MessageToast");
jQuery.sap.require("sap.m.MessageBox");
jQuery.sap.require("util.CommonUtils");
jQuery.sap.require("util.I18NUtility");
jQuery.sap.require("sap.ui.layout.form.SimpleForm");
jQuery.sap.require("com.sap.me.security.view.SecurityUtility");
/**
* 在制品处理
*/
sap.ui.controller("com.crystal.mobileApi.view.MobileApi",
{
/*
* 请求Servlet,且有返回数据
*/
reqServletReturnModel: function(oUrl,jsonParam){
var oModel = new sap.ui.model.json.JSONModel();
oModel.forceNoCache(true);
oModel.setSizeLimit(99999);
oModel.setDefaultBindingMode(sap.ui.model.BindingMode.OneWay);
oModel.loadData(oUrl, jsonParam, false, "POST");
if (oModel) {
var sMsg = oModel.oData.MSG;
if(!sMsg){
return oModel.oData;
}
if(sMsg != ""){
sap.m.MessageToast.show(sMsg, {
duration : 3000,
animationDuration : 500
});
}
}
},
onInit : function() { // 执行顺序 onInit>onBeforeShow>onAfterShow
var oView = this.getView();
var formatOptions = {pattern: 'yyyy/MM/dd'};
var dateFormate = sap.ui.core.format.DateFormat.getDateInstance(formatOptions);
var tempDate = dateFormate.format(new Date(),false);
oView.byId("dataPicker").setValue(tempDate);
// 查询页面列表数据
this.queryBarcode();
var barcodeList = util.Model.getData("barcodeList");// 页面列表数据
// 给页面列表赋值
var oTable = sap.ui.getCore().byId('listTable');// 页面列表
oTable.setModel(sap.ui.getCore().getModel("CrudTestModel"));
// oTable.setModel(oModel);
var wipProcessTypeControl = oView.byId('wipProcessType');// 下拉框
var comboBoxControl = oView.byId('comboBox');// 组合框(输入框+下拉框)
var multiComboBoxControl = oView.byId('multiComboBox');// 组合框(输入框+下拉框+复选框)
var item = '';
var comboBoxItem = '';
for (var i = 0; i < barcodeList.length; i++) {
// 给下拉框赋值
item = barcodeList[i];
comboBoxItem = new sap.ui.core.ListItem({
id: this.createId("wipProcessComboBoxItem"+i),// 确保ID唯一
text: item.BARCODE,// 展示值
key: item.RN// 实际值
});
wipProcessTypeControl.addItem(comboBoxItem);
// 给组合框(输入框+下拉框)赋值
comboBoxItem = new sap.ui.core.ListItem({
id: this.createId("comboBoxItem"+i),// 确保ID唯一
text: item.BARCODE,// 展示值
additionalText: item.HANDLE,// 展示值2(两列显示)
key: item.RN,
});
comboBoxControl.addItem(comboBoxItem);
// 给组合框(输入框+下拉框+复选框)赋值
multiComboBoxItem = new sap.ui.core.ListItem({
id: this.createId("multiComboBoxItem"+i),
text: item.RN,
additionalText: item.BARCODE,// 展示值2(两列显示)
key: item.RN
});
multiComboBoxControl.addItem(multiComboBoxItem);
}
},
onBeforeShow : function(evt) {
var oView = this.getView();
var site = util.Model.getData(util.CommonKey.CurrentSite);
if (!evt.data) return;
//作业规则
if (evt.data.options && evt.data.options.length > 0) {
for (var i = 0; i < evt.data.options.length; i++) {
var option = evt.data.options[i];
util.Model.setData(option.key,option.value);
}
}
if (evt.fromId == "Home") {
if (!util.StringUtil.isBlank(evt.data.appName)) {
if (oView) {
oView.page.setTitle(evt.data.appName); // 设置当前页面标题
}
}
this.clearButtonTap();
this.setFieldFocus("barcodeInput");
}
if(evt.fromId == "CrudTestBrowse"){ // 页面跳转选中对应行给对应输入框赋值
var selectedValue = util.Model.getData("TEMP_BarcodeInputFilterValue");
if (selectedValue && selectedValue != "") {
var oInputControl = oView.byId("barcodeInput");
if (oInputControl) {
if(oInputControl.getValue() == selectedValue){
return;
}
oInputControl.setValue(selectedValue);
}
}
}
},
onAfterShow : function(evt) {
/* if (evt.fromId == "OperationBrowse") {
this.setFieldFocus("barcodeInput");
}else if(evt.fromId == "ResourceBrowse"){
this.setFieldFocus("barcodeInput");
}*/
},
/** ------------------------------------- Change Begin -----------------------------------------------*/
// 打印份数改变事件
printNumberChange : function(oControlEvent) {
var oView = this.getView();
var printNumber = oView.byId("printNumberInput").getValue();
var date = oView.byId("dataPicker").getValue();
this.setFieldFocus("printNumberInput");
this.showMessage(printNumber);
var oTable = sap.ui.getCore().byId('listTable');// 页面列表
},
// 下拉框-后台查询 改变事件
processTypeChange : function(oControlEvent){
var oView = this.getView();
var oSelectControl = oView.byId("wipProcessType");
if (oSelectControl) {
var oItem = oSelectControl.getSelectedItem();
if (oItem) {
var sKey = oItem.getKey();
var sText = oItem.getText();
this.showMessage(sKey + "-" + sText);
}
}
},
// 下拉框-外部类 改变事件
collectionTypeChange : function(oControlEvent){
var oView = this.getView();
var oSelectControl = oView.byId("collectionType");
if (oSelectControl) {
var oItem = oSelectControl.getSelectedItem();
if (oItem) {
var sKey = oItem.getKey();
var sText = oItem.getText();
this.showMessage(sKey + "-" + sText);
}
}
},
/*复选框选中取消事件*/
checkBoxChange : function(oControlEvent){
var oView = this.getView();
var bacodeInputPlaceholder = oView.byId("barcodeInput").getPlaceholder();
var checkBoxs = ["checkBox","checkBox2"];
var isTrue = this.validateData("barcodeInput");
checkBoxs.forEach(function(item,index,checkBoxs){
var checkBox = oView.byId(item); /*获取ID*/
var checkBoxGetEditable = checkBox.getEditable(); /*是否允许编辑*/
var checkBoxGetGetEnabled = checkBox.getEnabled(); /*是否启用*/
var checkBoxGetName = checkBox.getName(); /*名称*/
var checkBoxGetSelected = checkBox.getSelected(); /*是否选中*/
var checkBoxGetTabIndex = checkBox.getTabIndex(); /*选项卡索引*/
var checkBoxGetText = checkBox.getText(); /*文本*/
var checkBoxGetValueState = checkBox.getValueState(); /*属性值状态的当前值*/
var checkBoxGetWidth = checkBox.getWidth(); /*宽度*/
if(isTrue){
checkBox.setValueState(sap.ui.core.ValueState.None);
}else {
checkBox.setSelected(false);
checkBox.setValueState(sap.ui.core.ValueState.Error);
}
})
},
/* 组合框(输入框+下拉框)选中事件 */
comboBoxSelectionChange : function(oControlEvent) {
var value = oControlEvent.getParameter("value");
this.showMessage(value);
},
/* 组合框(输入框+下拉框+复选框)选中事件 */
multiComboBoxSelectionChange : function(oControlEvent) {
var changedItem = oControlEvent.getParameter("changedItem");
var isSelected = oControlEvent.getParameter("selected");
var state = "Selected";
if (!isSelected) {
state = "Deselected";
}
var messageText = "Event 'selectionChange': " + state + " '" + changedItem.getText() + "'";
this.showMessage(messageText);
},
/* 组合框(输入框+下拉框+复选框)选中完成事件 */
multiComboBoxSelectionFinish : function(oControlEvent) {
var selectedItems = oControlEvent.getParameter("selectedItems");
var messageText = "Event 'selectionFinished': [";
for (var i = 0; i < selectedItems.length; i++) {
messageText += "'" + selectedItems[i].getText() + "'";
// var text = selectedItems[i].mProperties.text; selectedItems[i].mProperties.text 等同于 selectedItems[i].getText()
if (i != selectedItems.length - 1) {
messageText += ",";
}
}
messageText += "]";
this.showMessage(messageText);
},
/* 文本域值实时改变事件*/
checkRemarkLiveChange : function(oControlEvent) {
var value = oControlEvent.getParameter("value"); // 获取文本域值
this.showMessage("文本域值:"+ value);
},
/* 开关控件的切换事件*/
switchControlChange : function(oControlEvent) {
var oView = this.getView();
var switchControl = oView.byId("switchControl");
var state = switchControl.getState(); // 当前状态 true false
},
/* 滑块控件的值改变事件*/
rangeSliderChange : function(oControlEvent) {
var oView = this.getView();
var rangeSlider = oView.byId("rangeSlider");
var range = rangeSlider.getRange();// 获取第一个控件和第二个控件的值
var value = rangeSlider.getValue();// 获取第一个控件的值
var value2 = rangeSlider.getValue2();// 获取第二个控件的值
},
/** ------------------------------------- Change END ----------------------------------------------- */
/** ------------------------------------- Tap Begin ----------------------------------------------- */
// 单选按钮
radioButtonTap : function(oControlEvent){
var oView = this.getView();
var oRadioControl = oView.byId("radioButton");
console.log(oRadioControl.getText());
},
// 主键输入框弹框
browseHandleTap : function(evt) {
this.handleSearch();
},
// 条码输入框跳转
browseBarcodeTap : function(evt) {
util.Model.removeData("TEMP_BarcodeInputFilterValue");
var oView = this.getView();
if (oView) {
util.Model.setData("TEMP_BarcodeInputFilterValue", oView.byId("barcodeInput").getValue());
}
var bus = sap.ui.getCore().getEventBus();
bus.publish("nav", "to", {// 视图跳转 to、back、home
id : "MobileApiBrowse",// 要跳转的视图ID
data : {
namespace : "com.sap.me.browse.view",// 要跳转的视图的命名空间。完整路径:com.sap.me.browse.view.MobileApiBrowse
fromId : "MobileApi",// 本视图ID
fromNamespace : "com.crystal.mobileApi.view"// 本视图的命名空间 。完整路径:com.crystal.mobileApi.view.MobileApi
}
});
},
// 开始按钮点击事件
startButtonTap:function(evt){
if(!this.validateData()){
return;
}
this.executeInstruction("sfcStart");
},
// 注销按钮点击事件
signoffButtonTap:function(evt){
if(!this.validateData()){
return;
}
this.executeInstruction("sfcSignoff");
},
// 装配按钮点击事件
assembleButtonTap:function(evt){
var oView = this.getView();
var bus = sap.ui.getCore().getEventBus();
bus.publish("nav", "to", {
id : "Assemble",
data : {
namespace : "com.crystal.wipProcess.view",
fromId : "MobileApi",// 本视图ID
fromNamespace : "com.crystal.mobileApi.view"// 本视图的命名空间 。完整路径:com.crystal.mobileApi.view.MobileApi
}
});
},
// 完成按钮点击事件
completeButtonTap:function(evt){
var oView = this.getView();
var fullyAssembled = false;
var site = util.Model.getData(util.CommonKey.CurrentSite);
var params = {"SITE":site,"OPERATION":operation,"SFC":sfc,"DATA_CODE":"DY_0117_WIP_PROCESS_ASSEMBLY_INFO"};
var me = this;
if (fullyAssembled == false) {
// 如果没有完全装配,提示
var oDialog = new sap.m.Dialog({
title : util.I18NUtility.getLocaleSpecificText("CONFIRM.DEFAULT.BUTTON"),
type:sap.m.DialogType.Message,
content:new sap.m.Text({ text: "库存批次没有全部装配,是否确认完成?" }),
beginButton: new sap.m.Button({
type: sap.m.ButtonType.Emphasized,
text: util.I18NUtility.getLocaleSpecificText("CONFIRM.DEFAULT.BUTTON"),
press: function(){
me.executeInstruction('sfcComplete');
oDialog.close();
}
}),
endButton: new sap.m.Button({
text: util.I18NUtility.getLocaleSpecificText("CANCEL.DEFAULT.BUTTON"),
press: function () {
oDialog.close();
}
}),
afterClose: function () {
oDialog.destroy();
}
});
this.oDialog=oDialog;
oDialog.open();
} else {
this.executeInstruction('sfcComplete');
}
},
// 忙碌对话框打开按钮
openBusyDialogButtonTap : function(oControlEvent) {
var busyDialog = this.getView().byId("busyDialog");
busyDialog.open();// 打开对话框
window.setTimeout(function(){
busyDialog.close(); // 定时自动关闭对话框
}, 5000);
},
// 确认对话框打开按钮
openConfirmDialogButtonTap : function(oControlEvent) {
if (!this.oApproveDialog) {
this.oApproveDialog = new sap.m.Dialog({
type: sap.m.DialogType.Message, // sap.m.DialogType.Standard
title: "Confirm",
content: new sap.m.Text({
id :this.createId("confirmText"),
text: "Do you want to submit this order?",
}),
beginButton: new sap.m.Button({
type: sap.m.ButtonType.Emphasized,
text: "Submit",
press: function () {
this.showMessage("Submit pressed!");
this.oApproveDialog.close();
}.bind(this)
}),
endButton: new sap.m.Button({
text: "Cancel",
press: function () {
this.oApproveDialog.close();
}.bind(this)
})
});
}
this.oApproveDialog.open();
},
// 打开提示框
openAlertDialogButtonTap : function(oControlEvent) {
sap.m.MessageBox.alert("The quantity you have reported exceeds the quantity planed.");
},
// 打开错误提示框
openErrorDialogButtonTap : function(oControlEvent) {
sap.m.MessageBox.error("The quantity you have reported exceeds the quantity planed.");
},
// 打开信息提示框
openInfoDialogButtonTap : function(oControlEvent) {
sap.m.MessageBox.information("The quantity you have reported exceeds the quantity planed.");
},
// 打开警告提示框
openWarningDialogButtonTap : function(oControlEvent) {
sap.m.MessageBox.warning("The quantity you have reported exceeds the quantity planed.");
},
// 打开成功提示框
openSuccessDialogButtonTap : function(oControlEvent) {
sap.m.MessageBox.success("The quantity you have reported exceeds the quantity planed.");
},
// 新增对话框打开按钮
openAddDialogButtonTap : function(oControlEvent) {
var oView = this.getView();
if (!this.oAddDialog) { // 控件只能new一次 因为Id必须是唯一的(否则会提示duplicate错误)
this.oAddDialog = new sap.m.Dialog({
type: sap.m.DialogType.Standard, // sap.m.DialogType.Standard
title: "ADD",
content: [
new sap.m.Label({
id :this.createId("userNameLabel"),
text: "Username:",
}),
new com.sap.me.control.Input({
id: this.createId("userNameInput"),
maxLength: 20,
width: "200px",
type:sap.m.InputType.Text,
placeholder: "Enter username",
}),
new sap.m.Label({
id :this.createId("passwordLabel"),
text: "Password:",
}),
new com.sap.me.control.Input({
id: this.createId("passwordInput"),
maxLength: 10,
width: "200px",
type:sap.m.InputType.Password,
placeholder: "Enter Password",
}),
new sap.m.Label({
id :this.createId("emailLabel"),
text: "Email:",
}),
new com.sap.me.control.Input({
id: this.createId("emailInput"),
maxLength: 10,
width: "200px",
type:sap.m.InputType.Email,
placeholder: "Enter e-mail",
}),
],
beginButton: new sap.m.Button({
type: sap.m.ButtonType.Emphasized,
text: "Submit",
press: function () {
var userNameInput = oView.byId("userNameInput").getValue();
var passwordInput = oView.byId("passwordInput").getValue();
var emailInput = oView.byId("emailInput").getValue();
this.showMessage("Submit pressed!UserName:"+userNameInput+"Password:"+passwordInput+"Email:"+emailInput);
this.oApproveDialog.close();
}.bind(this)
}),
endButton: new sap.m.Button({
text: "Cancel",
press: function () {
this.oAddDialog.close();
}.bind(this)
}),
afterClose: function () {
oDialog.destroy();
}
});
}
this.oAddDialog.open();
},
/** ------------------------------------- Tap END ----------------------------------------------- */
/** ------------------------------------- General method Begin ----------------------------------------------- */
// 多列弹出框制作
handleSearch : function () {
/* 效果:在当前页面弹出一个展示多列数据的弹框,
最上方输入框可以绑定列表中的数据列从而实现数据过滤
【var oFilter = new sap.ui.model.Filter("HANDLE", sap.ui.model.FilterOperator.Contains, sValue);】*/
var oView = this.getView();
var site = util.Model.getData(util.CommonKey.CurrentSite); // 站点
var handle = oView.byId("handleInput").getValue(); // SFC
var jsonParam = {
'SITE_V' : site,
'EXT_CODE' : 'CRYSTAL_0042_REPORT_CRUD_TEST_1',
'HANDLE' : handle
};
var oUrl = '/crystalmobile/mobile/data/core/exec_data_code';
var oModel = new sap.ui.model.json.JSONModel();
oModel.forceNoCache(true);
oModel.setSizeLimit(999999);
oModel.setDefaultBindingMode(sap.ui.model.BindingMode.OneWay);
oModel.loadData(oUrl, jsonParam, false, "POST");
if (oModel) {
var sMsg = oModel.oData.MSG;
oModel.oData = JSON.parse(oModel.oData.message);
if(sMsg){
this.showMessage(sMsg);
return;
}else{
var DATA_LIST = oModel.oData.DATA_LIST;
/** 开始制作弹出选中框进行选择 多列弹出框 BEGIN */
if (!this._oDialog) {
this._oDialog = new sap.m.TableSelectDialog({
draggable : true,
search : function(oEvent) {
var sValue = oEvent.getParameter("value");
var oFilter = new sap.ui.model.Filter("HANDLE", sap.ui.model.FilterOperator.Contains, sValue);
var oBinding = oEvent.getSource().getBinding("items");
oBinding.filter([ oFilter ]);
},
confirm : function(oEvent) {
var aContexts = oEvent.getParameter("selectedContexts");
if (aContexts.length) {
oView.byId("handleInput").setValue(aContexts[0].getObject().HANDLE);
}
},
columns: [new sap.m.Column({
header: new sap.m.Label({
text: "主键"
})
}), new sap.m.Column({
header: new sap.m.Label({
text: "条码"
})
}), new sap.m.Column({
header: new sap.m.Label({
text: "创建时间"
})
})]
});
var itemTemplate = new sap.m.ColumnListItem({
cells: [new sap.m.Text({
text: "{HANDLE}"
}), new sap.m.Text({
text: "{BARCODE}"
}), new sap.m.Text({
text: "{CREATED_TIME}"
})]
});
if (this._oDialog.getBinding("items")) {
this._oDialog.getBinding("items").filter([]);
}
this._oDialog.setModel(oModel);
this._oDialog.bindAggregation("items", "/DATA_LIST", itemTemplate);
this._oDialog.open();
this._oDialog = null;
/** 开始制作弹出选中框进行选择 多列弹出框 END */
}
}
}
},
executeInstruction:function(instruction){
var site = util.Model.getData(util.CommonKey.CurrentSite);
var oView = this.getView();
var operation = oView.byId("operation").getValue();
var resource = oView.byId("resource").getValue();
var sfc = oView.byId("sfc").getValue();
var handle = oView.byId("handleInput").getValue();
var printNumber = oView.byId("printNumberInput").getValue();
var params = {
"OPERATION":operation,
"RESOURCE":resource,
"SFC":sfc,
"HANDLE":handle,
"PRINT_NUMBER":printNumber,
"SITE_V":site,
"EXT_CODE":"CRYSTAL_0042_SAVE_CRUD_TEST"
};
var oModel = new sap.ui.model.json.JSONModel();
oModel.forceNoCache(true);
oModel.setSizeLimit(99999);
oModel.setDefaultBindingMode(sap.ui.model.BindingMode.OneWay);
//oModel.loadData("/crystalmobile/mobile/wipProcess/executeInstruction", params, false, "POST");
//oModel.loadData("/crystalmobile/mobile/data/core/exec_data_code", params, false, "POST");
oModel.loadData("/crystalmobile/mobile/crudTest/upsertTest", params, false, "POST");
if (oModel) {
var status = oModel.oData.status;
var sMsg = "";
if(status == 'true'){
sMsg = "操作成功";
if(instruction != "sfcStart"){
oView.byId("barcodeInput").setValue("");
this.setFieldFocus("barcodeInput");
}
}else{
sMsg = oModel.oData.message;
}
this.showMessage(sMsg);
}
},
// 查询页面数据
queryBarcode : function() {
var site = util.Model.getData(util.CommonKey.CurrentSite);
var barcode = util.Model.getData("TEMP_BarcodeInputFilterValue");
var oUrl = '/crystalmobile/mobile/data/core/exec_data_code';
var params = {"SITE_V":site,"BARCODE":barcode,"EXT_CODE":"CRYSTAL_0042_REPORT_CRUD_TEST_1"};
var oModel = new sap.ui.model.json.JSONModel();
oModel.forceNoCache(true);
oModel.setSizeLimit(99999);
oModel.setDefaultBindingMode(sap.ui.model.BindingMode.OneWay);
oModel.loadData(oUrl, params, false, "POST");
oModel.oData = JSON.parse(oModel.oData.message);
if (oModel) {
sap.ui.getCore().setModel(oModel,"CrudTestModel");
}
var listMapObj = oModel.getProperty("/DATA_LIST");
if (listMapObj) {
oModel.setProperty("/listData", listMapObj);
} var site = util.Model.getData(util.CommonKey.CurrentSite);
var barcode = util.Model.getData("TEMP_BarcodeInputFilterValue");
var oUrl = '/crystalmobile/mobile/data/core/exec_data_code';
var params = {"SITE_V":site,"BARCODE":barcode,"EXT_CODE":"CRYSTAL_0042_REPORT_CRUD_TEST_1"};
var oModel = new sap.ui.model.json.JSONModel();
oModel.forceNoCache(true);
oModel.setSizeLimit(99999);
oModel.setDefaultBindingMode(sap.ui.model.BindingMode.OneWay);
oModel.loadData(oUrl, params, false, "POST");
oModel.oData = JSON.parse(oModel.oData.message);
if (oModel) {
sap.ui.getCore().setModel(oModel,"CrudTestModel");
}
var listMapObj = oModel.getProperty("/DATA_LIST");
if (listMapObj) {
oModel.setProperty("/listData", listMapObj);
}
util.Model.setData("barcodeList",listMapObj);
},
validateData:function(id){
var oView = this.getView();
if (!oView) return;
var idInputValue = oView.byId(id).getValue();
var idInputPlaceholder = oView.byId(id).getPlaceholder();
if(util.StringUtil.isBlank(idInputValue)){
this.showMessage(idInputPlaceholder+"不能为空");
return false;
}
return true;
},
showMessage : function(msg){
sap.m.MessageToast.show(msg, {
duration : 3000,
animationDuration : 500
});
},
/*
* 标题清空按钮tap事件
*/
clearButtonTap : function(){
// 清除数据
this.clearModel();
},
/*
* 导航按钮tap事件
*/
navButtonTap : function(){
this.clearModel();
var bus = sap.ui.getCore().getEventBus();
bus.publish("nav", "to", {
id : "Home"
});
},
/*
* Set the field focus
*/
setFieldFocus : function(focusField) {
jQuery.sap.delayedCall(800, this,util.StringUtil.setFocus, [ this.getView(),focusField ]);
},
/**
* 清除Model中的数据
*/
clearModel : function() {
var oView = this.getView();
if (!oView) return;
var oInputArray = ["barcodeInput", "handleInput", "printNumberInput"];
$(oInputArray).each(function (i, value) {
var oInputControl = oView.byId(value);
if (oInputControl) {
oInputControl.setValue("");
}
});
},
/** ------------------------------------- General method END ----------------------------------------------- */
});