2021-01-26 06:21:05 +00:00
|
|
|
import ngModule from '../../module';
|
2021-04-28 08:32:24 +00:00
|
|
|
import './style.scss';
|
2020-03-17 13:43:46 +00:00
|
|
|
import Section from 'salix/components/section';
|
2020-03-06 08:57:05 +00:00
|
|
|
|
2021-04-28 08:32:24 +00:00
|
|
|
export default class Controller extends Section {
|
|
|
|
saveBuy(buy) {
|
|
|
|
const missingData = !buy.itemFk || !buy.quantity || !buy.packageFk;
|
|
|
|
if (missingData) return;
|
|
|
|
|
2021-04-28 09:55:04 +00:00
|
|
|
let options;
|
2021-04-28 08:32:24 +00:00
|
|
|
if (buy.id) {
|
2021-04-28 09:55:04 +00:00
|
|
|
options = {
|
|
|
|
query: `Buys/${buy.id}`,
|
|
|
|
method: 'patch'
|
|
|
|
};
|
2021-04-28 08:32:24 +00:00
|
|
|
}
|
2021-04-28 09:55:04 +00:00
|
|
|
this.$http[options.method](options.query, buy).then(res => {
|
|
|
|
if (!res.data) return;
|
|
|
|
|
|
|
|
buy = Object.assign(buy, res.data);
|
|
|
|
this.vnApp.showSuccess(this.$t('Data saved!'));
|
|
|
|
});
|
2021-04-28 08:32:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns checked instances
|
|
|
|
*
|
|
|
|
* @return {Array} Checked instances
|
|
|
|
*/
|
|
|
|
selectedBuys() {
|
|
|
|
if (!this.buys) return;
|
|
|
|
|
|
|
|
return this.buys.filter(buy => {
|
|
|
|
return buy.checked;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
deleteBuys() {
|
|
|
|
const buys = this.selectedBuys();
|
|
|
|
const actualInstances = buys.filter(buy => buy.id);
|
|
|
|
|
|
|
|
const params = {buys: actualInstances};
|
|
|
|
|
|
|
|
if (actualInstances.length) {
|
|
|
|
this.$http.post(`Buys/deleteBuys`, params).then(() => {
|
|
|
|
this.vnApp.showSuccess(this.$t('Data saved!'));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
buys.forEach(buy => {
|
|
|
|
const index = this.buys.indexOf(buy);
|
|
|
|
this.buys.splice(index, 1);
|
|
|
|
});
|
|
|
|
}
|
2022-02-07 17:01:45 +00:00
|
|
|
|
|
|
|
toggleGroupingMode(buy, mode) {
|
2022-02-08 08:27:39 +00:00
|
|
|
const grouping = 1;
|
|
|
|
const packing = 2;
|
|
|
|
const groupingMode = mode === 'grouping' ? grouping : packing;
|
2022-02-07 17:01:45 +00:00
|
|
|
|
2022-02-08 08:27:39 +00:00
|
|
|
const newGroupingMode = buy.groupingMode === groupingMode ? 0 : groupingMode;
|
2022-02-07 17:01:45 +00:00
|
|
|
|
|
|
|
const params = {
|
|
|
|
groupingMode: newGroupingMode
|
|
|
|
};
|
|
|
|
|
|
|
|
this.$http.patch(`Buys/${buy.id}`, params).then(() => {
|
|
|
|
buy.groupingMode = newGroupingMode;
|
|
|
|
this.vnApp.showSuccess(this.$t('Data saved!'));
|
|
|
|
});
|
|
|
|
}
|
2022-12-23 11:11:24 +00:00
|
|
|
|
|
|
|
itemSearchFunc($search) {
|
|
|
|
return /^\d+$/.test($search)
|
|
|
|
? {id: $search}
|
|
|
|
: {name: {like: '%' + $search + '%'}};
|
|
|
|
}
|
2021-04-28 08:32:24 +00:00
|
|
|
}
|
|
|
|
|
2021-01-26 06:21:05 +00:00
|
|
|
ngModule.vnComponent('vnEntryBuyIndex', {
|
2020-03-06 08:57:05 +00:00
|
|
|
template: require('./index.html'),
|
2021-04-28 08:32:24 +00:00
|
|
|
controller: Controller,
|
2020-03-06 08:57:05 +00:00
|
|
|
bindings: {
|
|
|
|
entry: '<'
|
|
|
|
}
|
|
|
|
});
|