(async function () { Vue.prototype.$types = window.ctp.types; Vue.component('item-table', { props: ['items'], methods: { removeItem: function (index) { if (confirm('Do want to delete Item?')) { if (this.items[index].id === 0) { this.items.splice(index, 1); } else { // post request and reload page on success $.ajax({ url: '/ctp/rest/job-cards?job-card-item-id=' + this.items[index].id, method: 'POST', contentType: 'application/json', dataType: 'json', success: function (data) { location.reload(); }, error: function (err) { console.log(err) location.reload(); } }); } } } }, template: `
Item Item Sku/Title Cut Panels Expected Production Action
`, }); Vue.component('item-rows', { props: ['index', 'item'], methods: { removeItem: function (e) { e.preventDefault(); this.$emit('remove-item', this.index); }, 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; } }, template: ` {{item.sku}} ` }); Vue.component('cut-piece', { props: ['index', 'piece', 'pIndex'], methods: { removePiece: function (e) { e.preventDefault(); this.$emit('piece-remove', this.index) } }, template: `
` }); let app = new Vue({ el: '#jobCardApp', data: { jobCard: {}, items: [], }, methods: { addItem: function (e) { e.preventDefault(); this.items.push(this.createNewItem()) }, createNewItem: function () { return { 'id': 0, 'jobCardId': 0, 'itemId': 0, 'sku': '', 'expectedProductionQuantity': 0.0, cutPieces: [] } }, removeItem: function () { e.preventDefault(); }, hasDuplicates: function () { const ids = this.items.map(item => item.itemId); const uniqueIds = new Set(ids); return ids.length !== uniqueIds.size; }, hasEmptyItems: function () { if( this.items.length === 0 ) return true; for( let x of this.items ){ if( x.itemId === 0 ){ return true; } } return false; } }, mounted: function () { this.jobCard = window.ctp.jobCard; this.items = this.jobCard.items; } }); })(jQuery);