import ngModule from '../module'; import Section from 'salix/components/section'; class Controller extends Section { $onChanges() { if (this.$params && this.$params.q) this.travel = JSON.parse(this.$params.q); } onShippedChange(value) { const hasFilledProperties = this.travel.landed || this.travel.warehouseInFk || this.travel.warehouseOutFk; if (!this.travel.agencyModeFk || hasFilledProperties) return; const query = `travels/getTravelData`; const params = { agencyModeFk: this.travel.agencyModeFk }; this.$http.get(query, {params}).then(res => { const landed = new Date(value); const warehouseIn = res.data.warehouseIn; const warehouseOut = res.data.warehouseOut; const futureDate = landed.getDate() + res.data.dayDuration; landed.setDate(futureDate); this.travel.landed = landed; this.travel.warehouseInFk = warehouseIn; this.travel.warehouseOutFk = warehouseOut; }); } onSubmit() { return this.$.watcher.submit().then( res => this.$state.go('travel.card.basicData', {id: res.data.id}) ); } } ngModule.vnComponent('vnTravelCreate', { template: require('./index.html'), controller: Controller });