Achat pour consommer

This commit is contained in:
Vincent Vandemeulebrouck
2021-06-21 23:37:33 +02:00
parent 7cd5f0eef9
commit b808ccc7f7
3 changed files with 78 additions and 21 deletions

View File

@ -28,17 +28,21 @@ export class DialogItemAchat extends Dialog {
}
constructor(html, vendeur, acheteur, venteData, chatMessageIdVente) {
let options = { classes: ["dialogachat"], width: 400, height: 300, 'z-index': 99999 };
const isConsommable = venteData.item.type == 'nourritureboisson';
let options = { classes: ["dialogachat"], width: 400, height: isConsommable ? 450 : 300, 'z-index': 99999 };
const actionAchat = venteData.prixLot > 0 ? "Acheter" : "Prendre";
const buttons = {};
if (isConsommable) {
buttons["consommer"] = { label: venteData.item.data.boisson ? "Boire" : "Manger", callback: it => { this.onAchatConsommer(); } }
}
buttons[actionAchat] = { label: actionAchat, callback: it => { this.onAchat(); } };
buttons["decliner"] = { label: "Décliner", callback: it => { } };
let conf = {
title: actionAchat,
content: html,
default: actionAchat,
buttons: {
[actionAchat]: { label: actionAchat, callback: it => { this.onAchat(); } },
"decliner": { label: "Décliner", callback: it => { } }
}
buttons: buttons
};
super(conf, options);
@ -60,7 +64,11 @@ export class DialogItemAchat extends Dialog {
tailleLot: parseInt(buttonAcheter.attributes['data-tailleLot']?.value ?? 1),
quantiteIllimite: buttonAcheter.attributes['data-quantiteIllimite']?.value == 'true',
quantiteNbLots: parseInt(buttonAcheter.attributes['data-quantiteNbLots']?.value),
nombreLots: 1,
choix: {
nombreLots: 1,
seForcer: false,
supprimerSiZero: true
},
prixLot: prixLot,
prixTotal: prixLot,
isVente: prixLot > 0
@ -73,21 +81,31 @@ export class DialogItemAchat extends Dialog {
(this.vendeur ?? this.acheteur).achatVente({
vendeurId: this.vendeur?.id,
acheteurId: this.acheteur?.id,
nombreLots: this.venteData.nombreLots,
prixTotal: this.venteData.prixTotal,
chatMessageIdVente: this.chatMessageIdVente
chatMessageIdVente: this.chatMessageIdVente,
choix: this.venteData.choix
});
}
async onAchatConsommer() {
this.venteData.choix.consommer = true;
await this.onAchat();
}
/* -------------------------------------------- */
activateListeners(html) {
super.activateListeners(html);
html.find(".nombreLots").change(event => this.setNombreLots(Number(event.currentTarget.value)));
html.find(".se-forcer").change(event => this.setSeForcer(event));
}
setSeForcer(event) {
this.venteData.choix.seForcer = event.currentTarget.checked;
}
setNombreLots(nombreLots) {
this.venteData.nombreLots = nombreLots;
this.venteData.choix.nombreLots = nombreLots;
this.venteData.prixTotal = (nombreLots * this.venteData.prixLot).toFixed(2);
$(".prixTotal").text(this.venteData.prixTotal);
}