Merge branch 'WarehouseArticlePacket/enable-editing' into 'master'

fixed warehousearticlepacket editing

See merge request fronk/thetool!1415
This commit is contained in:
Luca Haid
2025-06-05 09:17:49 +00:00
4 changed files with 46 additions and 77 deletions

View File

@@ -1,90 +1,42 @@
Vue.component('WarehouseArticlePacket', {
//language=Vue
template: `
<tt-card>
<tt-table-crud @openHistory="historyModal = true; historyModalId = $event.id" ref="WarehouseArticlePacketCrud">
template: `
<tt-card>
<tt-table-crud @openHistory="historyModal = true; historyModalId = $event.id" ref="WarehouseArticlePacketCrud">
<template v-slot:subitems="{row}">
<template v-for="item in JSON.parse(row.subItems)">
<template v-slot:subitems="{row}">
<template v-for="item in JSON.parse(row.subItems)">
<span v-if="articles.find(article => article.value === item.id)">
{{item.amount + 'x '}}{{articles.find(article => article.value === item.id).text}}<br>
</span>
<span v-else></span>
</template>
</template>
<span v-else></span>
</template>
</template>
<template v-slot:subitems-modal="{crudModalData}">
<!-- TODO: add autocomplete and list with items, each removable, just simple quick-->
<div style="display: grid; grid-template-columns: 1fr 1fr auto;grid-gap: 8px">
<tt-autocomplete v-model="subItemsAutocomplete"
:items="articles"
ref="subItemsAutocomplete"
label="Subitems" sm/>
<tt-input v-model="newSubItemAmount" label="Menge" sm/>
<button type="button" class="btn btn-primary" @click="addSubItem" style="max-height: 32px; align-self: center">
<i class="fas fa-plus"></i>
</button>
</div>
<ul class="list-group" v-if="typeof subItems !== 'undefined' && subItems.length > 0" :key="updateCounter">
<template v-for="item in subItems">
<li class="list-group-item d-flex justify-content-between align-items-center">
Menge {{item.amount}} | Artikel {{articles.find(article => article.value === item.id).text}}
<button type="button" class="btn btn-danger btn-sm" @click="removeSubItem(item)">
<i class="fas fa-trash"></i>
</button>
</li>
</template>
</ul>
<span v-else>Keine Artikel hinzugefügt</span>
<template v-slot:subitems-modal="{crudModalData}">
<tt-positions-manager :config="WarehouseArticlePacketItemsConfig" v-model="crudModalData.subItems"/>
</template>
</template>
</tt-table-crud>
<warehouse-history-modal :show.sync="historyModal" :id="historyModalId"/>
</tt-card>
`, data() {
</tt-table-crud>
</tt-card>
`, data() {
return {
window: window,
historyModal: false,
historyModalId: null,
subItemsAutocomplete: '',
articles: [],
updateCounter: 0,
newSubItemAmount: 1,
subItems: []
window: window,
historyModal: false,
historyModalId: null,
WarehouseArticlePacketItemsConfig: {
fields: {
id: {type: 'input-article', label: 'Artikel', customFieldReference: 'WarehouseArticle'},
amount: {type: 'input', label: 'Menge', inputType: 'number'},
},
validateFormOptions: [
{key: 'id', message: 'Bitte füllen Sie den Artikel aus'},
{key: 'amount', message: 'Bitte füllen Sie die Menge aus'},
]
},
articles: [],
}
}, beforeMount() {
this.articles = window['TT_CONFIG']['CRUD_CONFIG'].columns.find(column => column.key === 'subItems').modal.items;
}, methods: {
updateCrudModalData() {
const ref = this.$refs.WarehouseArticlePacketCrud;
ref.$set(ref.crudModalData, 'subItems', JSON.stringify(this.subItems));
this.updateCounter++;
}, removeSubItem(item) {
this.subItems = this.subItems.filter(subItem => subItem !== item);
this.updateCrudModalData();
}, addSubItem() {
// only continue if id and amount are set else use window.notify('error', 'Bitte Artikel und Menge auswählen');
if (this.subItemsAutocomplete === '' || this.newSubItemAmount === '') {
window.notify('error', 'Bitte Artikel und Menge auswählen');
return;
}
this.subItems.push({id: this.subItemsAutocomplete, amount: this.newSubItemAmount});
this.updateCrudModalData();
this.$refs.subItemsAutocomplete.clear();
this.newSubItemAmount = 1;
}
}, mounted() {
this.$watch(() => {
return this.$refs.WarehouseArticlePacketCrud.crudModal
}, () => {
// check if this.$refs.WarehouseArticlePacketCrud.crudModalData.subItems is defined
if (typeof this.$refs.WarehouseArticlePacketCrud.crudModalData.subItems === 'undefined') {
this.$set(this.$refs.WarehouseArticlePacketCrud.crudModalData, 'subItems', JSON.stringify([]));
}
this.subItems = JSON.parse(this.$refs.WarehouseArticlePacketCrud.crudModalData.subItems);
})
}
})

View File

@@ -247,7 +247,7 @@ Vue.component('warehouse-offer-create-basic-offer-modal', {
sm row/>
</div>
<div class="col-md-4 text-right">
<h4>Gesamtsumme: <strong>{{ formatPrice(totalPrice) }} €</strong></h4>
<h4>Gesamtsumme: <strong>{{ formatPrice(totalPrice) }} </strong></h4>
</div>
</div>
</div>

File diff suppressed because one or more lines are too long

View File

@@ -17,6 +17,15 @@ Vue.component('tt-resolver', {
<span v-else>{{ text }}</span>
`,
async created() {
const cacheKey = `${this.reference}_${this.value}_${this.autocomplete}`;
const cached = JSON.parse(localStorage.getItem(cacheKey) || 'null');
if (cached && Date.now() - cached.timestamp < 1800000) {
this.text = cached.text;
this.loading = false;
return;
}
const endpoint = this.autocomplete
? `${window.TT_CONFIG["BASE_PATH"]}${this.reference}?searchedID=${this.value}`
: `${window.TT_CONFIG["BASE_PATH"]}/${this.reference}/getById?id=${this.value}`;
@@ -25,6 +34,8 @@ Vue.component('tt-resolver', {
if (this.reference === 'WarehouseArticle') this.text = `${data.articleNumber} | ${data.title}`;
else this.text = this.autocomplete ? data[0]?.text : data.name ?? data.title ?? data.text ?? '[E] Key not found';
localStorage.setItem(cacheKey, JSON.stringify({ text: this.text, timestamp: Date.now() }));
this.loading = false;
}
});