0
1
Fork 0
hedera-web-mindshore/forms/ecomerce/confirm/index.js

155 lines
3.1 KiB
JavaScript
Raw Normal View History

2022-11-16 01:44:39 +00:00
import './style.scss';
2015-07-07 15:27:47 +00:00
2022-11-16 01:44:39 +00:00
export default new Class({
2019-03-13 08:57:18 +00:00
Extends: Hedera.Form,
2022-11-16 01:44:39 +00:00
Template: require('./ui.xml'),
2015-12-10 13:48:43 +00:00
2022-11-16 01:46:44 +00:00
open() {
2019-03-13 08:57:18 +00:00
this.close();
2015-12-10 13:48:43 +00:00
this.isOpen = true;
2022-05-30 01:30:33 +00:00
Hedera.BasketChecker.check(this.conn, this.hash,
2019-03-13 08:57:18 +00:00
this.onBasketCheck.bind(this));
},
2015-12-10 13:48:43 +00:00
2022-11-16 01:46:44 +00:00
onBasketCheck(isOk) {
2015-12-10 13:48:43 +00:00
if (isOk)
2019-03-13 08:57:18 +00:00
this.loadUi();
},
2015-07-07 15:27:47 +00:00
2022-11-16 01:46:44 +00:00
onOrderReady(form) {
2015-07-17 14:34:42 +00:00
if (form.row < 0)
return;
2022-05-28 15:49:46 +00:00
if (form.$.method != 'PICKUP') {
2022-05-28 01:18:06 +00:00
Vn.Node.show(this.$.address);
Vn.Node.setText(this.$.method, _('Agency'));
2019-03-13 08:57:18 +00:00
} else {
2022-05-28 01:18:06 +00:00
Vn.Node.hide(this.$.address);
Vn.Node.setText(this.$.method, _('Warehouse'));
2015-07-17 14:34:42 +00:00
}
2022-05-28 15:49:46 +00:00
var total = form.$.taxableBase + form.$.tax;
if (total === null)
total = 0;
2022-05-28 15:49:46 +00:00
var credit = form.$.credit;
var debt = form.$.debt;
var totalDebt = debt + total;
var exceededCredit = totalDebt - credit;
var creditExceededCond = exceededCredit > 0;
if (creditExceededCond)
2019-03-13 08:57:18 +00:00
Htk.Toast.showWarning(
_('You have exceeded your credit.'));
2022-05-28 01:18:06 +00:00
this.$.debt.value = debt;
this.$.totalDebt.value = totalDebt;
this.$.totalAmount.value = totalDebt;
this.$.creditExcess.value = exceededCredit;
this.$.excessAmount.value = exceededCredit;
2022-05-28 01:18:06 +00:00
this.$.payAmount.value = 'ALL';
2019-03-13 08:57:18 +00:00
if (credit > 0) {
2022-05-28 01:18:06 +00:00
this.$.creditInfo.style.display = 'table-row';
2019-03-13 08:57:18 +00:00
if (creditExceededCond) {
2022-05-28 01:18:06 +00:00
this.$.amountSelector.style.display = 'block';
this.$.exceededInfo.style.display = 'table-row';
this.$.payAmount.value = 'EXCEEDED';
}
}
var methods = [];
let selectedMethod;
2019-03-13 08:57:18 +00:00
if (totalDebt <= 0) {
methods = ['balance'];
selectedMethod = 'BALANCE';
2019-03-13 08:57:18 +00:00
} else {
methods = ['card', 'transfer', 'later'];
2019-03-13 08:57:18 +00:00
if (!creditExceededCond) {
methods.push('credit');
selectedMethod = 'CREDIT';
2019-03-13 08:57:18 +00:00
} else
selectedMethod = 'CARD';
}
for (var i = 0; i < methods.length; i++)
2022-05-28 15:49:46 +00:00
this.$[`${methods[i]}Method`].style.display = 'block';
2022-05-28 01:18:06 +00:00
this.$.payMethod.value = selectedMethod;
2019-03-13 08:57:18 +00:00
},
2015-07-17 14:34:42 +00:00
2022-11-16 01:46:44 +00:00
onPayMethodChange(payMethod) {
var id = this.displayedInfo;
2022-05-28 15:49:46 +00:00
if (id)
2022-05-28 15:49:46 +00:00
Vn.Node.removeClass(this.$[id], 'selected');
2019-03-13 08:57:18 +00:00
switch (payMethod.value) {
case 'BALANCE':
2022-05-28 15:49:46 +00:00
id = 'balanceMethod';
break;
case 'CREDIT':
2022-05-28 15:49:46 +00:00
id = 'creditMethod';
break;
case 'CARD':
2022-05-28 15:49:46 +00:00
id = 'cardMethod';
break;
case 'TRANSFER':
2022-05-28 15:49:46 +00:00
id = 'transferMethod';
break;
default:
id = null;
}
2022-05-28 15:49:46 +00:00
this.displayedInfo = id;
if (id)
2022-05-28 15:49:46 +00:00
Vn.Node.addClass(this.$[id], 'selected');
2019-03-13 08:57:18 +00:00
},
2015-07-07 15:27:47 +00:00
2022-11-16 01:46:44 +00:00
disableButtons(disable) {
2022-05-28 01:18:06 +00:00
this.$.modify.disabled = disable;
this.$.confirm.disabled = disable;
2019-03-13 08:57:18 +00:00
},
2015-07-07 15:27:47 +00:00
2022-11-16 01:46:44 +00:00
onModifyClick() {
2015-07-07 15:27:47 +00:00
window.history.back();
2019-03-13 08:57:18 +00:00
},
2015-07-07 15:27:47 +00:00
2022-11-16 01:46:44 +00:00
onConfirmClick() {
2019-03-13 08:57:18 +00:00
this.disableButtons(true);
2022-05-28 01:18:06 +00:00
this.$.confirmQuery.execute();
2019-03-13 08:57:18 +00:00
},
2015-07-07 15:27:47 +00:00
2022-11-16 01:46:44 +00:00
onConfirm(query, resultSet) {
2019-03-13 08:57:18 +00:00
this.disableButtons(false);
2019-03-13 08:57:18 +00:00
if (resultSet.fetchResult())
2022-05-28 01:18:06 +00:00
this.$.successDialog.show();
2019-03-13 08:57:18 +00:00
},
2022-11-16 01:46:44 +00:00
onDialogResponse() {
2022-05-28 01:18:06 +00:00
if (this.$.payMethod.value === 'CARD') {
if (this.$.payAmount.value === 'EXCEEDED')
var payAmount = this.$.excessAmount.value;
else
2022-05-28 01:18:06 +00:00
var payAmount = this.$.totalAmount.value;
2022-05-30 01:30:33 +00:00
var tpv = new Hedera.Tpv({
conn: this.conn,
hash: this.hash
});
2022-10-03 12:49:41 +00:00
tpv.pay(payAmount, this.$.order.companyFk);
2019-03-13 08:57:18 +00:00
} else
2022-10-03 12:49:41 +00:00
this.hash.setAll({form: 'ecomerce/orders'});
2015-07-07 15:27:47 +00:00
}
});