(async function () { Vue.prototype.$accounts = window.ctp.accounts; Vue.prototype.$types = window.ctp.types; Vue.component('job-card-items', { props: ['items'], methods: { removeItem: function (index) { } }, template: ` `, }); Vue.component('job-card-item', { props: ['index', 'item', 'items'], methods: { removeItem: function (e) { if (confirm('Do want to delete Item?')) { if (this.items[this.index].id === 0) { this.items.splice(this.index, 1); } else { // post request and reload page on success $.ajax({ url: '/ctp/rest/job-cards?job-card-item-id=' + this.items[this.index].id, method: 'POST', contentType: 'application/json', dataType: 'json', success: function (data) { location.reload(); }, error: function (err) { console.log(err) location.reload(); } }); } } }, addPieces: function (e) { e.preventDefault(); this.item.cutPieces.push({ 'id': 0, 'jobCardItemId': 0, 'type': '', 'quantity': 0 }) }, removePiece: function (index) { if (confirm('Do want to delete Item?')) { if (this.item.cutPieces[index].id === 0) { this.item.cutPieces.splice(index, 1); } else { // post request and reload page on success $.ajax({ url: '/ctp/rest/cut-pieces?cut-piece-id=' + this.item.cutPieces[index].id, method: 'POST', contentType: 'application/json', dataType: 'json', success: function (data) { location.reload(); }, error: function (err) { console.log(err) location.reload(); } }); } } }, onItemSelect(itemId, invItem) { this.item.itemId = invItem.id; this.item.sku = invItem.sku; }, searchCutPieceBySku(sku) { $.ajax({ url: `/ctp/rest/cut-pieces?sku=${sku}`, method: 'GET', success: (response) => { this.$set(this.item, 'cutPieces', response); }, error: (error) => { console.error('Error fetching data:', error); } }); } }, watch: { 'item.sku': function(newSku, oldSku) { console.log('SKU changed:', newSku); this.searchCutPieceBySku(newSku); } }, template: `
` }); Vue.component('cut-piece', { props: ['index', 'piece', 'pIndex'], methods: { removePiece: function (e) { e.preventDefault(); this.$emit('piece-remove', this.index) } }, template: `