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

66 lines
1.3 KiB
JavaScript
Raw Normal View History

2017-11-03 05:26:07 +00:00
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');
});
},
}
};