123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521 |
- BemsWebApplication.setprice2 = function (params, viewInfo) {
- //탭 표시 요금제 Array 데이터 초기화
- var tabsData = [
- {
- id: "0",
- text: "test1"
- },
- {
- id: "1",
- text: "test2"
- },
- {
- id: "2",
- text: "test3"
- }
- ];
- //권한설정
- var hasnotModificationPermission = ko.observable(true);
- var old = false;
- //요금제 선택 SelectBox Array데이터 초기화
- var priceTypeDataSource = [{
- FuelTypeId: 1,
- PriceTypeId: 1,
- PriceTypeIdDesc: ""
- }];
- //요금제 항목 데이터 소스 변수 선언
- var priceCodeDataSource;
- //요금제 업데이트 시 변경전 조건과 변경후 변경값이 다르기 때문에 변경전 요금제를 저장할 용도로 변수 선언
- var beforeSelectPriceTypeId;
- //에너지원 선택 전역 변수 초기화
- var energySelectButton = "power";
- var selectFacilityTypeId;
- var selectFacilityCode;
- var selectFormulaId;
- var init = false;
- var endpointSelector = "";
- if (BemsWebApplication.config.mode == "production") {
- endpointSelector = new DevExpress.EndpointSelector(BemsWebApplication.config.endpoints).config.db.production;
- } else {
- endpointSelector = new DevExpress.EndpointSelector(BemsWebApplication.config.endpoints).config.db.local;
- }
- function getSitePrice(SiteID, FuelTypeId, PriceCode) { //현재 요금제 선택된 항목
- var dataSource = new DevExpress.data.DataSource({
- store: new DevExpress.data.ODataStore({
- url: endpointSelector + "/BemsSitePrice"
- }),
- expand: 'BemsPriceType',
- requireTotalCount: true,
- pageSize: 100
- });
- dataSource.filter([
- ["SiteID", "=", SiteID],
- "and",
- ["FuelTypeId", "=", FuelTypeId],
- "and",
- ["BemsPriceType.PriceTypeIdDesc", "=", $("#tabOptions").dxTabs("instance").option('selectedItem').text]
- ]);
- dataSource.load()
- .done(function (result) {
- $("#priceSelect").dxSelectBox("instance").option('value', result[0].BemsPriceType.PriceTypeId);
- beforeSelectPriceTypeId = result[0].BemsPriceType.PriceTypeId;
- })
- .fail(function (error) {
- alert(error);
- });
- }
- function getPriceType(FuelTypeId) {//요금제 종류
- var dataSource = new DevExpress.data.DataSource({
- store: {
- type: "odata",
- url: endpointSelector + "/BemsPriceType"
- },
- //map: function (itemData) {
- // return {
- // PriceTypeId: itemData.PriceTypeId,
- // PriceTypeIdDesc: itemData.PriceTypeIdDesc,
- // FuelTypeId: itemData.FuelTypeId
- // }
- //},
- requireTotalCount: true,
- pageSize: 100
- });
- dataSource.filter(["FuelTypeId", "=", FuelTypeId]);
- dataSource.sort({ getter: "PriceTypeId", asc: true });
- dataSource.load()
- .done(function (result) {
- priceTypeDataSource = result;
- $("#priceSelect").dxSelectBox("instance").option('dataSource', priceTypeDataSource);
- $("#priceSelect").dxSelectBox("instance").option('displayExpr', 'PriceTypeIdDesc');
- $("#priceSelect").dxSelectBox("instance").option('valueExpr', "PriceTypeId");
- getSitePrice(BWA.UserInfo.SiteId(), result[0].FuelTypeId);//PriceCode P038 청구요금
- })
- .fail(function (error) {
- alert(error);
- });
- }
- function PriceTypeDataSourceToArray(dataSource) {
- var resultArray = new Array(dataSource._items.length);
- for (var i = 0; i < dataSource._items.length; i++) {
- resultArray[i] = dataSource._items[i].PriceTypeIdDesc;
- }
- return resultArray;
- }
- function getPriceCode(FuelTypeId) { //요금제 항목 종류
- var dataSource = new DevExpress.data.DataSource({
- store: {
- type: "odata",
- url: endpointSelector + "/BemsPriceCode"
- },
- map: function (itemData) {
- return {
- PriceCode: itemData.PriceCode,
- PriceCodeDesc: itemData.PriceCodeDesc,
- FuelTypeId: itemData.FuelTypeId,
- Unit: itemData.Unit
- }
- },
- requireTotalCount: true,
- pageSize: 100
- });
- dataSource.filter(["FuelTypeId", "=", FuelTypeId]);
- dataSource.sort({ getter: "PriceCode", asc: true });
- dataSource.load()
- .done(function (result) {
- priceCodeDataSource = result;
- var $PriceCodeLayOut = $('#PriceCodeLayOut'); // finds the <PriceCodeLayOut> element
- $('#PriceCodeLayOut').empty();
- for (var i = 0; i < result.length; i++) {
- $('<input type="text" class="fl setInputId" style="width:150px;height:24px;" readonly>') // creates a new HTML element
- .appendTo($PriceCodeLayOut) // appends a new HTML element to the <body> element
- $('<div class="fl setSwitchId" style="margin-right:22px;">')
- .appendTo($PriceCodeLayOut)
- .dxSwitch();
- if (i % 5 == 4) {
- $('<br>').appendTo($PriceCodeLayOut)
- $('<br>').appendTo($PriceCodeLayOut)
- $('<br>').appendTo($PriceCodeLayOut)
- }
- }
- var setInputIds = document.querySelectorAll('.setInputId');
- var setSwitchIds = document.querySelectorAll('.setSwitchId');
- for (var i = 0; i < result.length; i++) {
- setInputIds[i].id = 'input' + i;
- setInputIds[i].value = result[i].PriceCodeDesc;
- setSwitchIds[i].id = 'switch' + i;
- $('#switch' + i).dxSwitch("instance").option('onText', 'On');
- $('#switch' + i).dxSwitch("instance").option('offText', 'Off');
- $('#switch' + i).dxSwitch("instance").option('value', true);
- }
- getPriceCodeYN(BWA.UserInfo.SiteId(), FuelTypeId);
- })
- .fail(function (error) {
- alert(error);
- });
- }
- function getPriceCodeYN(SiteID, FuelTypeId) { //현재 요금제 선택된 항목
- var dataSource = new DevExpress.data.DataSource({
- store: new DevExpress.data.ODataStore({
- url: endpointSelector + "/BemsSitePrice"
- }),
- expand: 'BemsPriceType',
- requireTotalCount: true,
- pageSize: 100
- });
- dataSource.filter([
- ["SiteID", "=", SiteID],
- "and",
- ["FuelTypeId", "=", FuelTypeId],
- "and",
- ["BemsPriceType.PriceTypeIdDesc", "=", $("#tabOptions").dxTabs("instance").option('selectedItem').text]
- ]);
- dataSource.sort({ getter: "PriceCode", asc: true });
- dataSource.load()
- .done(function (result) {
- for (var i = 0; i < result.length; i++) {
- var tmpYN;
- if (result[i].UseYN == "Y") {
- tmpYN = true;
- } else {
- tmpYN = false;
- }
- $("#switch" + i).dxSwitch("instance").option('value', tmpYN);
- }
- })
- .fail(function (error) {
- alert(error);
- });
- }
- function saveSettings() {
- var newmenus = [];
- var FuelTypeId;
- var priceTypeId = parseInt($("#priceSelect").dxSelectBox("instance").option('value'));
- if (energySelectButton == "power") {
- FuelTypeId = 1;
- } else if (energySelectButton == "gas") {
- FuelTypeId = 2;
- } else {
- FuelTypeId = 3;
- }
- var tmp = parseInt($("#tabOptions").dxTabs("instance").option('selectedIndex'));
- var seletctedTabItem = $("#tabOptions").dxTabs("instance").option('selectedItem');
- var selectPriceTypeId = parseInt($("#priceSelect").dxSelectBox("instance").option('value'));
- var selectPriceTypeIdDesc = $("#priceSelect").dxSelectBox("instance").option('text');
- if (selectPriceTypeId == 0) {
- utils.toast.show("요금제를 선택해 주세요.");
- return;
- }
- var dataSource = new DevExpress.data.DataSource({
- store: new DevExpress.data.ODataStore({
- url: endpointSelector + "/BemsSitePrice"
- }),
- expand: 'BemsPriceType',
- requireTotalCount: true,
- pageSize: 100
- });
- dataSource.filter([
- ["SiteID", "=", BWA.UserInfo.SiteId()],
- "and",
- ["FuelTypeId", "=", FuelTypeId]
- ]);
- dataSource.sort({ getter: "PriceCode", asc: true });
- dataSource.load()
- .done(function (result) {
- for (var i = 0; i < result.length; i++) {
- if (result[i].PriceTypeId == priceTypeId) {
- old = true;
- break;
- }
- }
- if (old)// 기존에 있는 요금표 변경 -> 기존꺼 N
- {
- BWA.api.post('BemsPriceFormula/Update', { SiteId: BWA.UserInfo.SiteId(), PriceTypeId: selectPriceTypeId, FacilityTypeId: selectFacilityTypeId, FormulaId: selectFormulaId, FacilityCode: selectFacilityCode, UseYN: 'N' }).done(function () {
- saving_PriceFormula = true;
- if (saving_PriceFormula) {
- BWA.api.post('BemsPriceFormula/Update', { SiteId: BWA.UserInfo.SiteId(), PriceTypeId: priceTypeId, FacilityTypeId: selectFacilityTypeId, FormulaId: selectFormulaId, FacilityCode: selectFacilityCode, UseYN: 'Y' }).done(function () {
- saving_PriceFormula = false;
- }).fail(function (error) {
- utils.toast.show(error);
- });
- }
- });
- old = false;
- }
- else {// 새로운 요금표 생성 -> 기존꺼 Y
- BWA.api.post('BemsPriceFormula/Update', { SiteId: BWA.UserInfo.SiteId(), PriceTypeId: priceTypeId, FacilityTypeId: selectFacilityTypeId, FormulaId: selectFormulaId, FacilityCode: selectFacilityCode, UseYN: 'Y' }).done(function () { });
- }
- })
- .fail(function (error) {
- alert(error);
- });
- for (var i = 0; i < priceCodeDataSource.length; i++) { //삭제후 저장
- var UseYN = $("#switch" + i).dxSwitch("instance").option('value');
- if (UseYN == true) {
- UseYN = 'Y';
- } else {
- UseYN = 'N';
- }
- newmenus.push({
- SiteId: BWA.UserInfo.SiteId(),
- FuelTypeId: FuelTypeId,
- PriceTypeId: selectPriceTypeId,
- PriceCode: priceCodeDataSource[i].PriceCode,
- UseYN: UseYN,
- });
- }
- for (var i = 0; i < tabsData.length; i++) {
- if (selectPriceTypeId == tabsData[i].id) {
- if (seletctedTabItem.id != selectPriceTypeId) {
- utils.toast.show("존재하고 있는 요금제입니다.");
- return;
- }
- }
- }
- if (seletctedTabItem.id != 0) {
- BWA.api.post('BemsSitePrice/DeleteAll', { SiteID: BWA.UserInfo.SiteId(), PriceTypeId: seletctedTabItem.id }).done(function () {
- BWA.api.post('BemsSitePrice/InsertAll', newmenus).done(function () {
- newmenus = [];
- }).fail(function (error) {
- utils.toast.show(error);
- });
- });
- }
- else {
- BWA.api.post('BemsSitePrice/InsertAll', newmenus).done(function () {
- }).fail(function (error) {
- utils.toast.show(error);
- });
- }
- tabsData[tmp].id = selectPriceTypeId;
- tabsData[tmp].text = selectPriceTypeIdDesc;
- $("#tabOptions").dxTabs("instance").option('dataSource', tabsData);
- setTimeout(function () { $("#tabOptions").dxTabs("instance").option('selectedIndex', 0) }, 2000);
- $("#tabOptions").dxTabs("instance").option('selectedIndex', 0);
- utils.toast.show("요금제가 저장 되었습니다.");
- }
- function getSitePriceData(SiteID, FuelTypeId) {
- var dataSource = new DevExpress.data.DataSource({
- store: new DevExpress.data.ODataStore({
- url: endpointSelector + "/BemsSitePrice"
- }),
- expand: 'BemsPriceType',
- requireTotalCount: true,
- pageSize: 1000
- });
- dataSource.filter([
- ["SiteID", "=", SiteID],
- "and",
- ["FuelTypeId", "=", FuelTypeId]
- ]);
- dataSource.sort({ getter: "PriceTypeId", asc: true });
- dataSource.load()
- .done(function (result) {
- if (result.length != 0) {
- var tmp = [];
- var tmpCnt = 0;
- tmp.push({ id: result[0].BemsPriceType.PriceTypeId, text: result[0].BemsPriceType.PriceTypeIdDesc });
- for (var i = 0; i < result.length; i++) {
- if (tmp[tmpCnt].text != result[i].BemsPriceType.PriceTypeIdDesc) {
- tmp.push({ id: result[i].BemsPriceType.PriceTypeId, text: result[i].BemsPriceType.PriceTypeIdDesc });
- tmpCnt++;
- }
- }
- }
- else {
- utils.toast.show("작성된 요금제가 없습니다.");
- }
- tabsData = tmp;
- $("#tabOptions").dxTabs("instance").option('dataSource', tabsData);
- $("#tabOptions").dxTabs("instance").option('selectedIndex', 0);
- getPriceType(FuelTypeId);
- getPriceCode(FuelTypeId);
- })
- .fail(function (error) {
- utils.toast.show(error);
- });
- }
- function deletePrice() {
- var FuelTypeId;
- if (energySelectButton == "power") {
- FuelTypeId = 1;
- } else if (energySelectButton == "gas") {
- FuelTypeId = 2;
- } else if (energySelectButton == "water") {
- FuelTypeId = 3;
- } else {
- utils.toast.show("에너지원이 선택되지 않았습니다.");
- }
- if (tabsData.length == 1) {
- utils.toast.show("요금제가 최소 하나 이상이어야 합니다.");
- return;
- }
- var selectPriceTypeId = parseInt($("#priceSelect").dxSelectBox("instance").option('value'));
- BWA.api.post('BemsPriceFormula/Update', { SiteId: BWA.UserInfo.SiteId(), PriceTypeId: selectPriceTypeId, FacilityTypeId: selectFacilityTypeId, FormulaId: selectFormulaId, FacilityCode: selectFacilityCode, UseYN: 'N' }).done(function () { });
- BWA.api.post('BemsSitePrice/DeleteAll', { SiteID: BWA.UserInfo.SiteId(), PriceTypeId: selectPriceTypeId }).done(function () {
- }).fail(function (error) {
- utils.toast.show(error);
- });
- utils.toast.show("요금제가 삭제 되었습니다.");
- tabsData.splice(parseInt($("#tabOptions").dxTabs("instance").option('selectedIndex')), 1);
- $("#tabOptions").dxTabs("instance").option('dataSource', tabsData);
- $("#tabOptions").dxTabs("instance").option('selectedIndex', 0);
- }
- function SelectBemsPriceFormula() {
- var dataSource = new DevExpress.data.DataSource({
- store: new DevExpress.data.ODataStore({
- url: endpointSelector + "/BemsPriceFormula"
- }),
- requireTotalCount: true,
- pageSize: 100
- });
- var priceTypeId = $("#priceSelect").dxSelectBox("instance").option('value');
- if (priceTypeId == null)
- return;
- dataSource.filter([
- ["SiteId", "=", BWA.UserInfo.SiteId()],
- "and",
- ["PriceTypeId", "=", priceTypeId]
- ]);
- dataSource.load()
- .done(function (result) {
- selectFacilityTypeId = result[0].FacilityTypeId
- selectFacilityCode = result[0].FacilityCode
- selectFormulaId = result[0].FormulaId
- })
- .fail(function (error) {
- utils.toast.show(error);
- });
- }
- function handleViewShown() {
- getSitePriceData(BWA.UserInfo.SiteId(), 1);
- $("#powerBtn").css("background-image", "linear-gradient(rgb(155,171,195) 0%,rgb(65,97,140) 100%)");
- $("#gasBtn").css("background-image", "linear-gradient(rgb(56,88,130) 0%, rgb(44,68,101)100%)");
- $("#waterBtn").css("background-image", "linear-gradient(rgb(56,88,130) 0%, rgb(44,68,101)100%)");
- init = true;
- }
- var searchViewOptions = {
- //templete function
- };
- function handleSearchInSearchView() {
- //templete function
- }
- function handleViewShowing() {
- //권한설정
- hasnotModificationPermission(!BWA.UserInfo.hasPermissionOfModification(viewInfo.viewName));
- }
- var viewModel = $.extend(BWA.CommonView.create(params, viewInfo, searchViewOptions, ko.observable(null), handleViewShown, null, handleSearchInSearchView),
- {
- viewShowing: handleViewShowing,
- powerButtonClicked: function () {
- energySelectButton = "power";
- $("#powerBtn").css("background-image", "linear-gradient(rgb(155,171,195) 0%,rgb(65,97,140) 100%)");//(180deg,#9babc3 0%,#41618c 100%)
- $("#gasBtn").css("background-image", "linear-gradient(rgb(56,88,130) 0%, rgb(44,68,101)100%)");
- $("#waterBtn").css("background-image", "linear-gradient(rgb(56,88,130) 0%, rgb(44,68,101)100%)");
- getSitePriceData(BWA.UserInfo.SiteId(), 1);
- },
- gasButtonClicked: function () {
- energySelectButton = "gas";
- $("#gasBtn").css("background-image", "linear-gradient(rgb(155,171,195) 0%,rgb(65,97,140) 100%)");
- $("#powerBtn").css("background-image", "linear-gradient(rgb(56,88,130) 0%, rgb(44,68,101)100%)");
- $("#waterBtn").css("background-image", "linear-gradient(rgb(56,88,130) 0%, rgb(44,68,101)100%)");
- getSitePriceData(BWA.UserInfo.SiteId(), 2);
- },
- waterButtonClicked: function () {
- energySelectButton = "water";
- $("#waterBtn").css("background-image", "linear-gradient(rgb(155,171,195) 0%,rgb(65,97,140) 100%)");
- $("#gasBtn").css("background-image", "linear-gradient(rgb(56,88,130) 0%, rgb(44,68,101)100%)");
- $("#powerBtn").css("background-image", "linear-gradient(rgb(56,88,130) 0%, rgb(44,68,101)100%)");
- getSitePriceData(BWA.UserInfo.SiteId(), 3);
- },
- saveButtonClicked: function () {
- DevExpress.ui.dialog.confirm("요금제를 저장 하시겠습니까?", "저장").done(function (dialogResult) {
- if (dialogResult)
- saveSettings();
- });
- },
- tabOptions: {
- dataSource: tabsData,
- height: 20,
- selectedIndex: 0,
- onSelectionChanged: function (e) {
- $("#priceSelect").dxSelectBox("instance").option('value', e.addedItems[0].id);
- if (e.addedItems[0].id != 0)
- SelectBemsPriceFormula();
- var FuelTypeId;
- if (energySelectButton == "power") {
- FuelTypeId = 1;
- } else if (energySelectButton == "gas") {
- FuelTypeId = 2;
- } else if (energySelectButton == "water") {
- FuelTypeId = 3;
- } else {
- utils.toast.show("에너지원이 선택되지 않았습니다.");
- }
- getPriceCode(FuelTypeId);
- }
- },
- addButtonClicked: function () {
- if ((tabsData.length == 5) && (tabsData == null)) {
- utils.toast.show("요금제는 추가는 최대 5개까지만 가능합니다.");
- } else {
- tabsData.push({ id: 0, text: "신규 요금제" });
- $("#tabOptions").dxTabs("instance").option('dataSource', tabsData);
- $("#tabOptions").dxTabs("instance").option('selectedIndex', tabsData.length - 1);
- setTimeout(function () {
- $("#tabOptions").dxTabs("instance").option('selectedIndex', tabsData.length - 1);
- }, 1000);
- }
- },
- removeButtonClicked: function () {
- if (tabsData[tabsData.length - 1].id != 0) {
- utils.toast.show("기존 요금제는 요금제 세부설정에서 삭제 가능합니다.");
- } else {
- tabsData.splice(tabsData.length - 1, 1);
- $("#tabOptions").dxTabs("instance").option('dataSource', tabsData);
- $("#tabOptions").dxTabs("instance").option('selectedIndex', 0);
- }
- },
- priceSelect: {
- dataSource: priceTypeDataSource,
- onSelectionChanged: function () {
- if (init)
- if ($("#priceSelect").dxSelectBox("instance").option('value') != 0)
- SelectBemsPriceFormula();
- }
- },
- delButtonClicked: function () {
- DevExpress.ui.dialog.confirm("요금제를 삭제 하시겠습니까?", "삭제").done(function (dialogResult) {
- if (dialogResult) {
- deletePrice();
- }
- });
- },
- hasnotModificationPermission: hasnotModificationPermission //권한설정
- });
- return viewModel;
- };
|