This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
site-base/spark/resources/assets/js/kiosk/add-discount.js
2017-11-03 16:26:07 +11:00

66 lines
1.3 KiB
JavaScript
Vendored

function kioskAddDiscountForm () {
return {
type: 'amount',
value: null,
duration: 'once',
months: null
};
}
module.exports = {
mixins: [require('./../mixins/discounts')],
/**
* The component's data.
*/
data() {
return {
loadingCurrentDiscount: false,
currentDiscount: null,
discountingUser: null,
form: new SparkForm(kioskAddDiscountForm())
};
},
/**
* The component has been created by Vue.
*/
created() {
var self = this;
Bus.$on('addDiscount', function (user) {
self.form = new SparkForm(kioskAddDiscountForm());
self.setUser(user);
$('#modal-add-discount').modal('show');
});
},
methods: {
/**
* Set the user receiving teh discount.
*/
setUser(user) {
this.discountingUser = user;
this.getCurrentDiscountForUser(user);
},
/**
* Apply the discount to the user.
*/
applyDiscount() {
Spark.post('/spark/kiosk/users/discount/' + this.discountingUser.id, this.form)
.then(() => {
$('#modal-add-discount').modal('hide');
});
},
}
};