在这里通过SAPUI5创建一个采购收货的FIORI APP,此SAPUI5的运用,使用的是前一文章生成的ODATA来做的,ODATA的具体生成请看这里。最终的APP,使用上与SAP标准采购收货的APP有很大的相似性(其实我一开始并不是参考标准的程序做的,只是发现我做的与标准的有很大的相似性,标准采购收货看这里)
看这文章之前最好是先准备好ODATA,此SAPUI5是在在SAP Web IDE本地个人版本上进行开发的,如你还没有的话,你需要先安装SAP Web IDE本地个人版本,或者是直接使用我的在线版本(SAP WEB IDE在LINUX上的服务器多用版本安装看这里),
账号: ZTEST01
密码:Ut163.com
注:密码第一位是大写
测试时可以使用4500000700左右的订单,可能数据要完整些,其它的可能不一定能收货。
1.使用模板向导生成APP
此APP的程序主内容是基于WEB IDE 中的CRUD Master-Detail来修改实现的,只是修改了其中的一部份功能。在SAP WEB IDE中 菜单中选择File->New->Project from Template ,并选择CRUD Master-Detail,
在后面的步骤中需要选择使用的ODATA服务器,并选择已做好的ODATA服务,其它的按你需填写就成,在后面是要进行修改的,我生成的APP名字为:ZMIGO,APPID:zsap.mm.migo。
2.修改页面
默认向导生成的是创建行功能,与修改功能,而这两个功能在采购收货中我们都不需要,所以我们删除了相关的增加保存按钮,而我们需要在主界面中增加“收货过账”,而在明细页中我们是用户修改数据后直接就修改了ODATA中的值(还没保存),所以在明细中我们增加一个“还原”按钮(SAP标准程序通常是要保存才会修改ODATA的值,这与标准的应该是最大的差异,不过感觉这种试应该用户会更喜欢),
2.1.修改Master.view.xml
这里主要是增加“确认过账”按钮,及ObjectListItem的一些内容
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
<mvc:View xmlns:form="sap.ui.layout.form" xmlns:mvc="sap.ui.core.mvc" xmlns:core="sap.ui.core" xmlns="sap.m" xmlns:semantic="sap.m.semantic" controllerName="zsap.mm.migo.controller.Master"> <semantic:MasterPage id="page" title="{masterView>/title}" navButtonPress="onNavBack" semanticRuleSet="Optimized" showNavButton="true" titleLevel="H4"> <semantic:subHeader> <Bar id="headerBar"> <contentMiddle> <SearchField id="searchField" showRefreshButton="{= !${device>/support/touch} }" tooltip="{i18n>masterSearchTooltip}" width="100%" search="onSearch" liveChange="onLivePressSearch"/> </contentMiddle> </Bar> </semantic:subHeader> <semantic:content> <PullToRefresh xmlns:form="sap.ui.layout.form" xmlns:mvc="sap.ui.core.mvc" xmlns:core="sap.ui.core" xmlns:semantic="sap.m.semantic" xmlns="sap.m" id="pullToRefresh" visible="{device>/support/touch}" refresh="onRefresh"/> <FlexBox xmlns:form="sap.ui.layout.form" xmlns:mvc="sap.ui.core.mvc" xmlns:core="sap.ui.core" xmlns:semantic="sap.m.semantic" xmlns="sap.m" width="100%" id="__box0" alignItems="Center" alignContent="Inherit"> <items> <Text text="过账日期:" id="__budatt"/> <Input placeholder="YYYY-MM-dd" type="Date" id="__budat" valueState="Success"/> <CheckBox id="__print" text="立即打印" selected="true"/> </items> </FlexBox> <!-- For client side filtering add this to the items attribute: parameters: {operationMode: 'Client'}}" --> <List id="list" busyIndicatorDelay="{masterView>/delay}" noDataText="{masterView>/noDataText}" growing="true" updateFinished="onUpdateFinished" items="{ path: '/ZMM_C_POEKPO2', sorter: { path: 'ebeln,ebelp', descending: false }, groupHeaderFactory: '.createGroupHeader' }" rememberSelections="false" mode="MultiSelect"> <infoToolbar> <Toolbar active="true" id="filterBar" visible="{masterView>/isFilterBarVisible}" press="onOpenViewSettings"> <Title id="filterBarLabel" text="{masterView>/filterBarLabel}"/> </Toolbar> </infoToolbar> <items> <ObjectListItem title="{maktx}" number="{ path: 'zshsl', formatter: '.formatter.currencyValue' }" numberUnit="{meins}" intro="{ebelp}-{matnr}" highlight="{= parseFloat(${zshsl}) < parseFloat(${obmng}) ? 'Error': 'None'}" press="onSelectionChange" type="Navigation"> </ObjectListItem> </items> </List> </semantic:content> <semantic:multiSelectAction> <semantic:MultiSelectAction tooltip="多重选择" id="__action0" press="onMultiSelectPress"/> </semantic:multiSelectAction> <semantic:positiveAction> <semantic:PositiveAction text="确认过账" id="gr_migo" press="onGRMigo"/> </semantic:positiveAction> </semantic:MasterPage> </mvc:View> |
2.2.修改Master.controller.js
这里住要是增加收货过账的功能,在onGRMigo事件中实现,在其中,调用ODATA的ZFM_GR_MIGO 函数,使用omodel.callFunction(“/ZFM_GR_MIGO” 来实现,此需要先在ODATA中做好相关的功能,可参看这里在ODATA实现。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 |
/*global history */ sap.ui.define([ "zsap/mm/migo/controller/BaseController", "sap/ui/model/json/JSONModel", "sap/ui/model/Filter", "sap/ui/model/FilterOperator", "sap/m/GroupHeaderListItem", "sap/ui/Device", "zsap/mm/migo/model/formatter", "sap/m/MessageBox", "zsap/mm/migo/model/grouper", "zsap/mm/migo/model/GroupSortState", "sap/ui/core/format/DateFormat", "sap/m/MessageToast" ], function(BaseController, JSONModel, Filter, FilterOperator, GroupHeaderListItem, Device, formatter, MessageBox, grouper, GroupSortState,DateFormat,MessageToast) { "use strict"; return BaseController.extend("zsap.mm.migo.controller.Master", { formatter: formatter, /* =========================================================== */ /* lifecycle methods */ /* =========================================================== */ /** * Called when the master list controller is instantiated. It sets up the event handling for the master/detail communication and other lifecycle tasks. * @public */ onInit: function() { // Control state model var oFormatYyyymmdd = DateFormat.getInstance({pattern: "yyyy-MM-dd"}); var toDay = oFormatYyyymmdd.format(new Date()); this.byId("__budat").setValue(toDay); // this.byId("__test").setValue(new Date()); var oList = this.byId("list"), oViewModel = this._createViewModel(), // Put down master list's original value for busy indicator delay, // so it can be restored later on. Busy handling on the master list is // taken care of by the master list itself. iOriginalBusyDelay = oList.getBusyIndicatorDelay(); this._oListSelector = this.getOwnerComponent().oListSelector; this._oGroupSortState = new GroupSortState(oViewModel, grouper.zshsl(this.getResourceBundle())); this._oList = oList; // keeps the filter and search state this._oListFilterState = { aFilter: [], aSearch: [] }; this.setModel(oViewModel, "masterView"); // Make sure, busy indication is showing immediately so there is no // break after the busy indication for loading the view's meta data is // ended (see promise 'oWhenMetadataIsLoaded' in AppController) oList.attachEventOnce("updateFinished", function() { // Restore original busy indicator delay for the list oViewModel.setProperty("/delay", iOriginalBusyDelay); }); this.getView().addEventDelegate({ onBeforeFirstShow: function() { this._oListSelector.setBoundMasterList(oList); }.bind(this) }); //不是手机操作时,初始化时打开明细页 //否则不显示明细页!Device.system.phone if (!Device.system.phone){ this.getRouter().getRoute("master").attachPatternMatched(this._onMasterMatched, this); this.getRouter().attachBypassed(this.onBypassed, this); } this._oODataModel = this.getOwnerComponent().getModel(); this._oResourceBundle = this.getResourceBundle(); }, /* =========================================================== */ /* event handlers */ /* =========================================================== */ /** * After list data is available, this handler method updates the * master list counter and hides the pull to refresh control, if * necessary. * @param {sap.ui.base.Event} oEvent the update finished event * @public */ onUpdateFinished: function(oEvent) { // update the master list object counter after new data is loaded var _olist = this.byId("list"); var items = _olist.getItems(); var sFirstEbeln = ''; if(items.length > 0){ var odata = items[0].getBindingContext(); sFirstEbeln = odata.getProperty("ebeln"); this._updateListItemCount(sFirstEbeln); } //this._updateListItemCount(oEvent.getParameter("total")); // hide pull to refresh if necessary this.byId("pullToRefresh").hide(); //不是手机操作时,才打开明细页 if (!Device.system.phone){ this._findItem(); } this.getModel("appView").setProperty("/addEnabled", true); }, /** * Event handler for the master search field. Applies current * filter value and triggers a new search. If the search field's * 'refresh' button has been pressed, no new search is triggered * and the list binding is refresh instead. * @param {sap.ui.base.Event} oEvent the search event * @public */ onSearch: function(oEvent) { if (oEvent.getParameters().refreshButtonPressed) { // Search field's 'refresh' button has been pressed. // This is visible if you select any master list item. // In this case no new search is triggered, we only // refresh the list binding. this.onRefresh(); return; } var sQuery = oEvent.getParameter("query"); if (sQuery) { this._oListFilterState.aSearch = [new Filter("ebeln", FilterOperator.EQ, sQuery)]; this._applyFilterSearch(); } else { // this._oListFilterState.aSearch = []; } }, onLivePressSearch : function(oEvent) { var Ebeln = oEvent.getParameter("newValue"); if (Ebeln.length < 10) { return; } this._oListFilterState.aSearch = [new Filter("ebeln", FilterOperator.EQ, Ebeln)]; this._applyFilterSearch(); // 判断是否有查询到数据数据。 var _olist = this.byId("list"); if(_olist.getItems().length > 0){ // 清除查询条件 var _searchField = this.byId("searchField"); _searchField.clear(); } }, /** * Event handler for refresh event. Keeps filter, sort * and group settings and refreshes the list binding. * @public */ onRefresh: function() { this._oList.getBinding("items").refresh(); }, /** * Event handler for the sorter selection. * @param {sap.ui.base.Event} oEvent the select event * @public */ onSort: function(oEvent) { var sKey = oEvent.getSource().getSelectedItem().getKey(), aSorters = this._oGroupSortState.sort(sKey); this._applyGroupSort(aSorters); }, /** * Event handler for the grouper selection. * @param {sap.ui.base.Event} oEvent the search field event * @public */ onGroup: function(oEvent) { var sKey = oEvent.getSource().getSelectedItem().getKey(), aSorters = this._oGroupSortState.group(sKey); this._applyGroupSort(aSorters); }, /** * Event handler for the filter button to open the ViewSettingsDialog. * which is used to add or remove filters to the master list. This * handler method is also called when the filter bar is pressed, * which is added to the beginning of the master list when a filter is applied. * @public */ onOpenViewSettings: function() { if (!this._oViewSettingsDialog) { this._oViewSettingsDialog = sap.ui.xmlfragment("zsap.mm.migo.view.ViewSettingsDialog", this); this.getView().addDependent(this._oViewSettingsDialog); // forward compact/cozy style into Dialog this._oViewSettingsDialog.addStyleClass(this.getOwnerComponent().getContentDensityClass()); } this._oViewSettingsDialog.open(); }, /** * Event handler called when ViewSettingsDialog has been confirmed, i.e. * has been closed with 'OK'. In the case, the currently chosen filters * are applied to the master list, which can also mean that the currently * applied filters are removed from the master list, in case the filter * settings are removed in the ViewSettingsDialog. * @param {sap.ui.base.Event} oEvent the confirm event * @public */ onConfirmViewSettingsDialog: function(oEvent) { var aFilterItems = oEvent.getParameters().filterItems, aFilters = [], aCaptions = []; // update filter state: // combine the filter array and the filter string aFilterItems.forEach(function(oItem) { switch (oItem.getKey()) { case "Filter1": aFilters.push(new Filter("zshsl", FilterOperator.LE, 100)); break; case "Filter2": aFilters.push(new Filter("zshsl", FilterOperator.GT, 100)); break; default: break; } aCaptions.push(oItem.getText()); }); this._oListFilterState.aFilter = aFilters; this._updateFilterBar(aCaptions.join(", ")); this._applyFilterSearch(); }, /** * Event handler for the list selection event * @param {sap.ui.base.Event} oEvent the list selectionChange event * @public */ onSelectionChange: function(oEvent) { var that = this; var oItem = oEvent.getParameter("listItem") || oEvent.getSource(); var fnLeave = function() { that._oODataModel.resetChanges(); that._showDetail(oItem); }; this._showDetail(oItem); /*if (this._oODataModel.hasPendingChanges()) { this._leaveEditPage(fnLeave); } else { this._showDetail(oItem); }*/ that.getModel("appView").setProperty("/addEnabled", true); }, /** * Event handler for the bypassed event, which is fired when no routing pattern matched. * If there was an object selected in the master list, that selection is removed. * @public */ onBypassed: function() { this._oList.removeSelections(true); }, /** * Used to create GroupHeaders with non-capitalized caption. * These headers are inserted into the master list to * group the master list's items. * @param {Object} oGroup group whose text is to be displayed * @public * @returns {sap.m.GroupHeaderListItem} group header with non-capitalized caption. */ createGroupHeader: function(oGroup) { return new GroupHeaderListItem({ title: oGroup.text, upperCase: false }); }, /** * Navigates back in the browser history, if the entry was created by this app. * If not, it navigates to the Fiori Launchpad home page * @override * @public */ onNavBack: function() { var oHistory = sap.ui.core.routing.History.getInstance(), sPreviousHash = oHistory.getPreviousHash(), oCrossAppNavigator = sap.ushell.Container.getService("CrossApplicationNavigation"); if (sPreviousHash !== undefined) { // The history contains a previous entry history.go(-1); } else { // Navigate back to FLP home oCrossAppNavigator.toExternal({ target: { shellHash: "#Shell-home" } }); } }, /** * Event handler (attached declaratively) called when the add button in the master view is pressed. it opens the create view. * @public */ onAdd: function() { this.getModel("appView").setProperty("/addEnabled", false); this.getRouter().getTargets().display("create"); }, /* =========================================================== */ /* begin: internal methods */ /* =========================================================== */ /** * Creates the model for the view * @private */ _createViewModel: function() { return new JSONModel({ isFilterBarVisible: false, filterBarLabel: "", delay: 0, title: this.getResourceBundle().getText("masterTitleCount", [0]), noDataText: this.getResourceBundle().getText("masterListNoDataText"), sortBy: "ebeln,ebelp", groupBy: "None" }); }, /** * Ask for user confirmation to leave the edit page and discard all changes * @param {object} fnLeave - handles discard changes * @param {object} fnLeaveCancelled - handles cancel * @private */ _leaveEditPage: function(fnLeave, fnLeaveCancelled) { var sQuestion = this.getResourceBundle().getText("warningConfirm"); var sTitle = this.getResourceBundle().getText("warning"); MessageBox.show(sQuestion, { icon: MessageBox.Icon.WARNING, title: sTitle, actions: [MessageBox.Action.OK, MessageBox.Action.CANCEL], onClose: function(oAction) { if (oAction === MessageBox.Action.OK) { fnLeave(); } else if (fnLeaveCancelled) { fnLeaveCancelled(); } } }); }, /** * If the master route was hit (empty hash) we have to set * the hash to to the first item in the list as soon as the * listLoading is done and the first item in the list is known * @private */ _onMasterMatched: function() { this._oListSelector.oWhenListLoadingIsDone.then( function(mParams) { if (mParams.list.getMode() === "None") { return; } this.getModel("appView").setProperty("/addEnabled", true); if (!mParams.list.getSelectedItem()) { this.getRouter().navTo("object", { ebeln: encodeURIComponent(mParams.firstListitem.getBindingContext().getProperty("ebeln")), ebelp: encodeURIComponent(mParams.firstListitem.getBindingContext().getProperty("ebelp")) }, true); } }.bind(this), function(mParams) { if (mParams.error) { return; } // this.getRouter().getTargets().display("detailNoObjectsAvailable"); // MessageToast.show( "请输入采购订单进行收货"); }.bind(this) ); }, /** * Shows the selected item on the detail page * On phones a additional history entry is created * @param {sap.m.ObjectListItem} oItem selected Item * @private */ _showDetail: function(oItem) { var bReplace = !Device.system.phone; this.getRouter().navTo("object", { ebeln: encodeURIComponent(oItem.getBindingContext().getProperty("ebeln")), ebelp: encodeURIComponent(oItem.getBindingContext().getProperty("ebelp")) }, bReplace); }, /** * Sets the item count on the master list header * @param {integer} iTotalItems the total number of items in the list * @private */ _updateListItemCount: function(iTotalItems) { var sTitle; // only update the counter if the length is final if (this._oList.getBinding("items").isLengthFinal()) { sTitle = this.getResourceBundle().getText("masterTitleCount", [iTotalItems]); this.getModel("masterView").setProperty("/title", sTitle); } }, /** * Internal helper method to apply both filter and search state together on the list binding * @private */ _applyFilterSearch: function() { var aFilters = this._oListFilterState.aSearch.concat(this._oListFilterState.aFilter), oViewModel = this.getModel("masterView"); this._oList.getBinding("items").filter(aFilters, "Application"); // changes the noDataText of the list in case there are no filter results if (aFilters.length !== 0) { oViewModel.setProperty("/noDataText", this.getResourceBundle().getText("masterListNoDataWithFilterOrSearchText")); } else if (this._oListFilterState.aSearch.length > 0) { // only reset the no data text to default when no new search was triggered oViewModel.setProperty("/noDataText", this.getResourceBundle().getText("masterListNoDataText")); } }, /** * Internal helper method to apply both group and sort state together on the list binding * @private */ _applyGroupSort: function(aSorters) { this._oList.getBinding("items").sort(aSorters); }, /** * Internal helper method that sets the filter bar visibility property and the label's caption to be shown * @param {string} sFilterBarText the selected filter value * @private */ _updateFilterBar: function(sFilterBarText) { var oViewModel = this.getModel("masterView"); oViewModel.setProperty("/isFilterBarVisible", (this._oListFilterState.aFilter.length > 0)); oViewModel.setProperty("/filterBarLabel", this.getResourceBundle().getText("masterFilterBarText", [sFilterBarText])); }, /** * Internal helper method that adds "/" to the item's path * @private */ _fnGetPathWithSlash: function(sPath) { return (sPath.indexOf("/") === 0 ? "" : "/") + sPath; }, /** * It navigates to the saved itemToSelect item. After delete it navigate to the next item. * After add it navigates to the new added item if it is displayed in the tree. If not it navigates to the first item. * @private */ _findItem: function() { var itemToSelect = this.getModel("appView").getProperty("/itemToSelect"); if (itemToSelect) { var sPath = this._fnGetPathWithSlash(itemToSelect); var oItem = this._oListSelector.findListItem(sPath); if (!oItem) { //item is not viewable in the tree. not in the current tree page. oItem = this._oListSelector.findFirstItem(); if (oItem) { sPath = oItem.getBindingContext().getPath(); } else { // this.getRouter().getTargets().display("detailNoObjectsAvailable"); // MessageToast.show( "项目出错1"); return; } } this._oListSelector.selectAListItem(sPath); this._showDetail(oItem); } }, onMultiSelectPress: function(oEvent) { var _olist = this.byId("list"); if (oEvent.getSource().getPressed()) { _olist.selectAll(); //MessageToast.show("MultiSelect Pressed"); } else { _olist.removeSelections(); // MessageToast.show("MultiSelect Unpressed"); } }, onGRMigo:function(){ // var L_BUDAT = '2020' var that = this; var _omodel = this.getModel(); var odata = []; var _sBudat = this.byId("__budat"); var _olist = this.byId("list"); var items = _olist.getSelectedItems(); if(items.length < 1){ MessageToast.show( "请选择要收货的行"); return; } // 在这里组装出需要确认收货的数据。 var sBudat = _sBudat.getValue(); for (var i = 0; i < items.length; i++) { var item = items[i]; var context = item.getBindingContext(); var obj = context.getProperty(null, context); odata[i]= obj; odata[i].budat = sBudat; } var ParaData = JSON.stringify(odata); this.getModel("appView").setProperty("/busy", true); _omodel.callFunction("/ZFM_GR_MIGO",{ "method": "GET", urlParameters: {"data1": ParaData }, // function import parameters success: function(oData, response) { //MessageToast.show("收货成功"); that._fnProessSucc(oData); }, // callback function for success error: function(oError){ that._fnProessError(oError); } }); // callback function for error }, _checkIfBatchRequestSucceeded: function(oData) { return true; }, _fnProessSucc: function(oData) { //this.getModel("appView").setProperty("/busy", false); var oModel = this.getModel(); var oRequest; var oError; for (var i = 0; i < oData.results.length; i++) { oRequest = oData.results[i]; if (oRequest.Type === "E" ) { oError = "X"; break; } } var Mblnr = oRequest.Mblnr; //MessageToast.show("收货成功:" + Mblnr); if (oError === "X" || !Mblnr) { var oResults = JSON.stringify(oData.results); MessageBox.error(oResults ); } else{ // this.getView().unbindObject(); // this._oODataModel.resetChanges(); oModel._refresh(); MessageToast.show( "收货成功:" + Mblnr ); } this.getModel("appView").setProperty("/busy", false); }, _fnProessError: function(oError) { this.getModel("appView").setProperty("/busy", false); MessageBox.error(oError); } }); }); |
2.3.修改明细页Detail.view.xml
在这里主要增加“还原”按钮功能,及当用户修改收货数据时显示数量完整度(进度条),及设置相关的颜色,以便于用户从颜色视觉上发现修改了收货数据及数量的不完整性。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
<mvc:View xmlns="sap.m" xmlns:micr="sap.suite.ui.microchart" xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc" xmlns:semantic="sap.m.semantic" xmlns:footerbar="sap.ushell.ui.footerbar" controllerName="zsap.mm.migo.controller.Detail"> <semantic:DetailPage id="page" navButtonPress="onNavBack" showNavButton="{device>/system/phone}" title="{ebeln}-{ebelp}" busy="{detailView>/busy}" busyIndicatorDelay="{detailView>/delay}"> <semantic:content> <ObjectHeader id="objectHeader" number="{ path: 'obmng', formatter: '.formatter.currencyValue' }" numberUnit="{meins}" intro="{ebeln}-{ebelp}-{matnr}" numberState="{= parseFloat(${zshsl}) < parseFloat(${obmng}) ? 'Error': 'None'}" titleLevel="H4" title="{maktx}" tooltip="{name1}"> <attributes> <ObjectAttribute text="{lifnr}-{name1}" id="__attribute33"/> </attributes> <statuses> <ProgressIndicator id="__indicator0" percentValue="20" displayAnimation="true" state="Success"/> </statuses> </ObjectHeader> <HBox width="100%" id="__hbox0" alignItems="Center"> <items> <Label text="数量:" width="100%" id="__label1"/> <Input xmlns="sap.m" width="100%" id="__zshsl" value="{zshsl}" required="true" type="Number" change="onCheckZshsl" valueStateText="请输入0-{obmng}的数量" fieldWidth="70%"/> <Input width="100%" id="__input1" value="{meins}" editable="false" enabled="false"/> </items> <micr:RadialMicroChart id="__radial1" size="S" percentage="100" valueColor="Good" class="sapUiSmallMargin"/> </HBox> <HBox width="100%" id="__hbox2" alignItems="Center"> <items> <Label text="地点:" width="100%" id="__label2"/> <Select id="__werks1" items="{ path: '/I_Plant', sorter: { path: 'Plant' } }" selectedKey="{werks1}" showSecondaryValues="true" maxWidth="300px" change="onSelctLgort"> <core:ListItem key="{Plant}" text="{Plant}" additionalText="{PlantName}"/> </Select> <Input width="100%" id="_werks2" value="{werks2}" editable="false" enabled="false"/> </items> </HBox> <HBox width="100%" id="__hbox3" alignItems="Center"> <items> <Label text="存储:" width="100%" id="__label3"/> <Select id="__lgort1" forceSelection="true" items="{ path: '/I_StorageLocation', sorter: { path: 'StorageLocation' } }" selectedKey="{lgort1}" showSecondaryValues="true" maxWidth="300px"> <core:ListItem key="{StorageLocation}" text="{StorageLocation}" additionalText="{StorageLocationName}"/> </Select> <Input width="100%" id="_lgort2" value="{lgort2}" editable="false" enabled="false"/> </items> </HBox> </semantic:content> <semantic:mainAction> <semantic:MainAction text="还原" id="_return_sh" press="onRetunrData"/> </semantic:mainAction> </semantic:DetailPage> </mvc:View> |
3.修改明细页Detail.controller.js
当用户点击“还原”时,调用事件onRetunrData,在代码中把收货数据修改在默认的全量收货状态。当用户修改收货数量时使用事件onCheckZshsl来检查收货数据的完整度,并调用this._setProgress来更新收货完整度状态条,在其中还通过Device.system.phone来判断是手机还是电脑操作,来进行一些差异的显示操作(主要是电脑屏幕大,显示时是主从屏幕都显示,但手机只会显示一个)。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 |
/*global location */ sap.ui.define([ "zsap/mm/migo/controller/BaseController", "sap/ui/model/json/JSONModel", "zsap/mm/migo/model/formatter", "sap/m/MessageBox", "sap/ui/model/Filter", "sap/ui/model/FilterOperator", "sap/m/MessageToast", "sap/ui/Device" ], function(BaseController, JSONModel, formatter, MessageBox,Filter,FilterOperator, MessageToast,Device) { "use strict"; return BaseController.extend("zsap.mm.migo.controller.Detail", { formatter: formatter, /* =========================================================== */ /* lifecycle methods */ /* =========================================================== */ onInit: function() { // Model used to manipulate control states. The chosen values make sure, // detail page is busy indication immediately so there is no break in // between the busy indication for loading the view's meta data var oViewModel = new JSONModel({ busy: false, delay: 0 }); this.getRouter().getRoute("object").attachPatternMatched(this._onObjectMatched, this); this.setModel(oViewModel, "detailView"); this.getOwnerComponent().getModel().metadataLoaded().then(this._onMetadataLoaded.bind(this)); this._oODataModel = this.getOwnerComponent().getModel(); this._oResourceBundle = this.getResourceBundle(); this.onCheckZshsl(); }, /* =========================================================== */ /* event handlers */ /* =========================================================== */ /** * Event handler when the share by E-Mail button has been clicked * @public */ onShareEmailPress: function() { var oViewModel = this.getModel("detailView"); sap.m.URLHelper.triggerEmail( null, oViewModel.getProperty("/shareSendEmailSubject"), oViewModel.getProperty("/shareSendEmailMessage") ); }, /** * Event handler when the share in JAM button has been clicked * @public */ onShareInJamPress: function() { var oViewModel = this.getModel("detailView"), oShareDialog = sap.ui.getCore().createComponent({ name: "sap.collaboration.components.fiori.sharing.dialog", settings: { object: { id: location.href, share: oViewModel.getProperty("/shareOnJamTitle") } } }); oShareDialog.open(); }, /** * Event handler (attached declaratively) for the view delete button. Deletes the selected item. * @function * @public */ onDelete: function() { var that = this; var oViewModel = this.getModel("detailView"), sPath = oViewModel.getProperty("/sObjectPath"), sObjectHeader = this._oODataModel.getProperty(sPath + "/ebelp"), sQuestion = this._oResourceBundle.getText("deleteText", sObjectHeader), sSuccessMessage = this._oResourceBundle.getText("deleteSuccess", sObjectHeader); var fnMyAfterDeleted = function() { MessageToast.show(sSuccessMessage); oViewModel.setProperty("/busy", false); var oNextItemToSelect = that.getOwnerComponent().oListSelector.findNextItem(sPath); that.getModel("appView").setProperty("/itemToSelect", oNextItemToSelect.getBindingContext().getPath()); //save last deleted }; this._confirmDeletionByUser({ question: sQuestion }, [sPath], fnMyAfterDeleted); }, /** * Event handler (attached declaratively) for the view edit button. Open a view to enable the user update the selected item. * @function * @public */ onEdit: function() { this.getModel("appView").setProperty("/addEnabled", false); var sObjectPath = this.getView().getElementBinding().getPath(); this.getRouter().getTargets().display("create", { mode: "update", objectPath: sObjectPath }); }, /* =========================================================== */ /* begin: internal methods */ /* =========================================================== */ /** * Binds the view to the object path and expands the aggregated line items. * @function * @param {sap.ui.base.Event} oEvent pattern match event in route 'object' * @private */ _onObjectMatched: function(oEvent) { var oParameter = oEvent.getParameter("arguments"); for (var value in oParameter) { oParameter[value] = decodeURIComponent(oParameter[value]); } this.getModel().metadataLoaded().then(function() { var sObjectPath = this.getModel().createKey("ZMM_C_POEKPO2", oParameter); this._bindView("/" + sObjectPath); }.bind(this)); }, /** * Binds the view to the object path. Makes sure that detail view displays * a busy indicator while data for the corresponding element binding is loaded. * @function * @param {string} sObjectPath path to the object to be bound to the view. * @private */ _bindView: function(sObjectPath) { // Set busy indicator during view binding var oViewModel = this.getModel("detailView"); // If the view was not bound yet its not busy, only if the binding requests data it is set to busy again oViewModel.setProperty("/busy", false); this.getView().bindElement({ path: sObjectPath, events: { change: this._onBindingChange.bind(this), dataRequested: function() { oViewModel.setProperty("/busy", true); }, dataReceived: function() { oViewModel.setProperty("/busy", false); } } }); }, /** * Event handler for binding change event * @function * @private */ _onBindingChange: function() { var oView = this.getView(), oElementBinding = oView.getElementBinding(), oViewModel = this.getModel("detailView"), oAppViewModel = this.getModel("appView"); // No data for the binding if (!oElementBinding.getBoundContext()) { // 没找到明细时,不显示 // this.getRouter().getTargets().display("detailObjectNotFound"); // if object could not be found, the selection in the master list // does not make sense anymore. this.getOwnerComponent().oListSelector.clearMasterListSelection(); return; } var sPath = oElementBinding.getBoundContext().getPath(), oResourceBundle = this.getResourceBundle(), oObject = oView.getModel().getObject(sPath), sObjectId = oObject.ebeln, sObjectName = oObject.ebelp; oViewModel.setProperty("/sObjectId", sObjectId); oViewModel.setProperty("/sObjectPath", sPath); oAppViewModel.setProperty("/itemToSelect", sPath); this.getOwnerComponent().oListSelector.selectAListItem(sPath); oViewModel.setProperty("/saveAsTileTitle", oResourceBundle.getText("shareSaveTileAppTitle", [sObjectName])); oViewModel.setProperty("/shareOnJamTitle", sObjectName); oViewModel.setProperty("/shareSendEmailSubject", oResourceBundle.getText("shareSendEmailObjectSubject", [sObjectId])); oViewModel.setProperty("/shareSendEmailMessage", oResourceBundle.getText("shareSendEmailObjectMessage", [sObjectName, sObjectId, location.href])); this.onCheckZshsl(); }, /** * Event handler for metadata loaded event * @function * @private */ _onMetadataLoaded: function() { // Store original busy indicator delay for the detail view var iOriginalViewBusyDelay = this.getView().getBusyIndicatorDelay(), oViewModel = this.getModel("detailView"); // Make sure busy indicator is displayed immediately when // detail view is displayed for the first time oViewModel.setProperty("/delay", 0); // Binding the view will set it to not busy - so the view is always busy if it is not bound oViewModel.setProperty("/busy", true); // Restore original busy indicator delay for the detail view oViewModel.setProperty("/delay", iOriginalViewBusyDelay); }, /** * Opens a dialog letting the user either confirm or cancel the deletion of a list of entities * @param {object} oConfirmation - Possesses up to two attributes: question (obligatory) is a string providing the statement presented to the user. * title (optional) may be a string defining the title of the popup. * @param {object} oConfirmation - Possesses up to two attributes: question (obligatory) is a string providing the statement presented to the user. * @param {array} aPaths - Array of strings representing the context paths to the entities to be deleted. Currently only one is supported. * @param {callback} fnAfterDeleted (optional) - called after deletion is done. * @param {callback} fnDeleteCanceled (optional) - called when the user decides not to perform the deletion * @param {callback} fnDeleteConfirmed (optional) - called when the user decides to perform the deletion. A Promise will be passed * @function * @private */ /* eslint-disable */ // using more then 4 parameters for a function is justified here _confirmDeletionByUser: function(oConfirmation, aPaths, fnAfterDeleted, fnDeleteCanceled, fnDeleteConfirmed) { /* eslint-enable */ // Callback function for when the user decides to perform the deletion var fnDelete = function() { // Calls the oData Delete service this._callDelete(aPaths, fnAfterDeleted); }.bind(this); // Opens the confirmation dialog MessageBox.show(oConfirmation.question, { icon: oConfirmation.icon || MessageBox.Icon.WARNING, title: oConfirmation.title || this._oResourceBundle.getText("delete"), actions: [MessageBox.Action.OK, MessageBox.Action.CANCEL], onClose: function(oAction) { if (oAction === MessageBox.Action.OK) { fnDelete(); } else if (fnDeleteCanceled) { fnDeleteCanceled(); } } }); }, /** * Performs the deletion of a list of entities. * @param {array} aPaths - Array of strings representing the context paths to the entities to be deleted. Currently only one is supported. * @param {callback} fnAfterDeleted (optional) - called after deletion is done. * @return a Promise that will be resolved as soon as the deletion process ended successfully. * @function * @private */ _callDelete: function(aPaths, fnAfterDeleted) { var oViewModel = this.getModel("detailView"); oViewModel.setProperty("/busy", true); var fnFailed = function() { this._oODataModel.setUseBatch(true); }.bind(this); var fnSuccess = function() { if (fnAfterDeleted) { fnAfterDeleted(); this._oODataModel.setUseBatch(true); } oViewModel.setProperty("/busy", false); }.bind(this); return this._deleteOneEntity(aPaths[0], fnSuccess, fnFailed); }, /** * Deletes the entity from the odata model * @param {array} aPaths - Array of strings representing the context paths to the entities to be deleted. Currently only one is supported. * @param {callback} fnSuccess - Event handler for success operation. * @param {callback} fnFailed - Event handler for failure operation. * @function * @private */ _deleteOneEntity: function(sPath, fnSuccess, fnFailed) { var oPromise = new Promise(function(fnResolve, fnReject) { this._oODataModel.setUseBatch(false); this._oODataModel.remove(sPath, { success: fnResolve, error: fnReject, async: true }); }.bind(this)); oPromise.then(fnSuccess, fnFailed); return oPromise; }, onRetunrData:function(){ // 数据 还原 var oViewModel = this.getModel("detailView"), sPath = oViewModel.getProperty("/sObjectPath"), sobmng = this._oODataModel.getProperty(sPath + "/obmng"), swerks2 = this._oODataModel.getProperty(sPath + "/werks2"), slgort2 = this._oODataModel.getProperty(sPath + "/lgort2"); this._oODataModel.setProperty(sPath + "/zshsl",sobmng); this._oODataModel.setProperty(sPath + "/werks1",swerks2); this._oODataModel.setProperty(sPath + "/lgort1",slgort2); this.onCheckZshsl(); }, onSelctLgort:function(){ var oViewModel = this.getModel("detailView"), sPath = oViewModel.getProperty("/sObjectPath"), sWerks = this._oODataModel.getProperty(sPath + "/werks1"); var aFilter = []; if (!sWerks) { return; } aFilter.push(new Filter("Plant", FilterOperator.EQ , sWerks)); // filter binding var oList = this.byId("__lgort1"); var oBinding = oList.getBinding("items"); oBinding.filter(aFilter); }, onCheckZshsl:function(oEvent){ var sReturn = false; var _zshsl = this.byId("__zshsl"); var oViewModel = this.getModel("detailView"), sPath = oViewModel.getProperty("/sObjectPath"), sZshsl = this._oODataModel.getProperty(sPath + "/zshsl"), sobmng = this._oODataModel.getProperty(sPath + "/obmng"); if ( parseFloat(sZshsl) < 0 || parseFloat(sZshsl) > parseFloat(sobmng) ) { //{device>/support/touch} //如果为电脑直接取最大值,并报错, //否则手机报红this.getModel("device").oData.system.phone if(Device.system.phone){ _zshsl.setProperty("valueState","Error"); } else{ this._oODataModel.setProperty(sPath + "/zshsl",sobmng); sZshsl = sobmng; } MessageToast.show( "最大收货量为:" + sobmng ); sReturn = false; } else{ _zshsl.setProperty("valueState","None"); sReturn = true; } this._setProgress(sZshsl,sobmng);//显示收货进度条 return sReturn; }, onReturCheck:function(){ this.ableReturn = this.onCheckZshsl(); return this.ableReturn; }, _setProgress:function(sZshsl,sobmng){ //显示收货进度条 if (!(sZshsl > 0 && sobmng > 0)) { return; } var _radial1 = this.byId("__radial1"); var _indicator0 = this.byId("__indicator0"); var lPercentage = 0; lPercentage = parseInt(100 * (parseFloat(sZshsl) / parseFloat(sobmng))); _radial1.setProperty("percentage",lPercentage); _indicator0.setPercentValue(lPercentage); _indicator0.setDisplayValue(lPercentage + '%'); if(lPercentage > 80 ){ _radial1.setProperty("valueColor","Good"); _indicator0.setState("Success"); } else{ _radial1.setProperty("valueColor","Error"); _indicator0.setState("Error"); } } }); }); |
其它还有一些细节的修改,其中BaseController.js中也进行了点小修改,可在完整源码中查看。
4.完整源码下载(收费下载源码)
任何问题请联系yan252@163.com
下一步就是把测试正常的FIORI APP ,发布到SAP Gateway 服务器上,并配置到 LUNCHPAD,最后实现如我们演示的效果(账号: ZTEST01,密码:Ut163.com),注:密码第一位是大写