2021-01-18 13:16:39 +00:00
|
|
|
import ngModule from '../module';
|
|
|
|
import Section from 'salix/components/section';
|
|
|
|
import './style.scss';
|
|
|
|
|
|
|
|
export default class Controller extends Section {
|
|
|
|
constructor($element, $) {
|
|
|
|
super($element, $);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Inserts a new instance
|
|
|
|
*/
|
|
|
|
add() {
|
|
|
|
this.$.model.insert({});
|
|
|
|
}
|
|
|
|
|
|
|
|
upsertPrice(price) {
|
|
|
|
price.hasMinPrice = price.minPrice ? true : false;
|
|
|
|
|
2021-01-18 15:32:54 +00:00
|
|
|
let requiredFields = ['itemFk', 'started', 'ended', 'rate2', 'rate3'];
|
2021-01-18 13:16:39 +00:00
|
|
|
for (let field of requiredFields)
|
|
|
|
if (price[field] == undefined) return;
|
|
|
|
|
|
|
|
const query = 'FixedPrices/upsertFixedPrice';
|
|
|
|
this.$http.patch(query, price)
|
|
|
|
.then(res => {
|
|
|
|
this.vnApp.showSuccess(this.$t('Data saved!'));
|
|
|
|
Object.assign(price, res.data);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
removePrice($index) {
|
|
|
|
const price = this.$.model.data[$index];
|
|
|
|
if (price.id) {
|
|
|
|
this.$http.delete(`FixedPrices/${price.id}`)
|
|
|
|
.then(() => {
|
|
|
|
this.$.model.remove($index);
|
|
|
|
this.vnApp.showSuccess(this.$t('Data saved!'));
|
|
|
|
});
|
|
|
|
} else
|
|
|
|
this.$.model.remove($index);
|
|
|
|
}
|
2021-01-19 19:56:33 +00:00
|
|
|
|
|
|
|
itemSearchFunc($search) {
|
|
|
|
return /^\d+$/.test($search)
|
|
|
|
? {id: $search}
|
|
|
|
: {name: {like: '%' + $search + '%'}};
|
|
|
|
}
|
2021-01-18 13:16:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ngModule.vnComponent('vnFixedPrice', {
|
|
|
|
template: require('./index.html'),
|
|
|
|
controller: Controller
|
|
|
|
});
|