// noinspection JSUnusedLocalSymbols const articleAPIUrl = `${window['TT_CONFIG']['BASE_PATH']}/WarehouseArticle/autocomplete`; const articlePacketAPIUrl = `${window['TT_CONFIG']['BASE_PATH']}/WarehouseArticlePacket/autocomplete`; Vue.component('warehouse-e-shop-order-modal-positions-mgmt', { props: { id: {type: [String, Number], required: true}, }, data() { return { window: window, positions: [], articleAPIUrl: articleAPIUrl, articlePacketAPIUrl: articlePacketAPIUrl, articleNames: {}, articlePacketNames: {}, articleId: null, articlePacketId: null, amount: null, editIndex: null, } }, async mounted() { // get all positions by /WarehouseEShopOrder/getAllItemsPerOrder?orderId=ID const response = await axios.get(`${window['TT_CONFIG']['BASE_PATH']}/WarehouseEShopOrder/getAllItemsPerOrder?orderId=${this.id}`); this.positions = response.data; }, methods: { async fetchNames() { console.log("hallohallo"); // TODO: there must be a better way to do this for (const position of this.positions) { if (position.articleId) this.$set(this.articleNames, position.articleId, 'Loading...'); if (position.articlePacketId) this.$set(this.articlePacketNames, position.articlePacketId, 'Loading...'); } const articlePromises = this.positions.filter(position => position.articleId) .map(position => axios.get(window.TT_CONFIG["BASE_PATH"] + '/WarehouseArticle/autoComplete?searchedID=' + position.articleId)); const articlePacketPromises = this.positions.filter(position => position.articlePacketId) .map(position => axios.get(window.TT_CONFIG["BASE_PATH"] + '/WarehouseArticlePacket/autoComplete?searchedID=' + position.articlePacketId)); const articleResponses = await Promise.all(articlePromises); const articlePacketResponses = await Promise.all(articlePacketPromises); for (const response of articleResponses) { this.$set(this.articleNames, response.data[0].value, response.data[0].text); } for (const response of articlePacketResponses) { this.$set(this.articlePacketNames, response.data[0].value, response.data[0].data[0].text); // Adjusted for packet autocomplete response structure } }, async addPosition() { if (!this.articleId && !this.articlePacketId) return window.notify('error', 'Bitte wählen Sie einen Artikel oder ein Artikel Packet aus.'); if (this.editIndex !== null) return this.updatePosition(); const response = await axios.post(`${window['TT_CONFIG']['BASE_PATH']}/WarehouseEShopOrder/addPosition`, { orderId: this.id, articleId: this.articleId, articlePacketId: this.articlePacketId, quantity: this.amount, }); if (response.data.success) { this.positions.push(response.data.position); this.articleId = null; this.articlePacketId = null; this.amount = null; window.notify('success', 'Position hinzugefügt'); } else { window.notify('error', response.data.message); } }, async updatePosition() { const position = this.positions[this.editIndex]; const response = await axios.post(`${window['TT_CONFIG']['BASE_PATH']}/WarehouseEShopOrder/updatePosition`, { id: position.id, articleId: this.articleId, articlePacketId: this.articlePacketId, quantity: this.amount, }); if (response.data.success) { this.positions[this.editIndex] = response.data.position; this.articleId = null; this.articlePacketId = null; this.amount = null; this.editIndex = null; window.notify('success', response.data.message); } else { window.notify('error', response.data.message); } }, async deletePosition(id) { const response = await axios.post(`${window['TT_CONFIG']['BASE_PATH']}/WarehouseEShopOrder/deletePosition`, {id}); if (response.data.success) { this.positions = this.positions.filter(position => position.id !== id); window.notify('success', response.data.message); } else { window.notify('error', response.data.message); } }, async editPosition(id) { const position = this.positions.find(position => position.id === id); this.articleId = position.articleId; this.articlePacketId = position.articlePacketId; this.amount = position.quantity; this.editIndex = this.positions.indexOf(position); }, }, watch: {positions: {handler: 'fetchNames', immediate: true}}, //language=Vue template: `
| Artikel | Menge | Aktionen | |
|---|---|---|---|
| Keine Einträge | |||
| {{ position.articleId ? articleNames[position.articleId] : position.articlePacketId ? articlePacketNames[position.articlePacketId] : 'Loading...' }} | {{ position.quantity }} | ||