2019-12-09 11:15:19 +00:00
|
|
|
import ngModule from '../module';
|
|
|
|
import Section from 'salix/components/section';
|
|
|
|
|
|
|
|
class Controller extends Section {
|
2020-03-10 13:09:26 +00:00
|
|
|
$onChanges() {
|
2020-03-18 11:55:22 +00:00
|
|
|
if (this.$params && this.$params.q)
|
|
|
|
this.travel = JSON.parse(this.$params.q);
|
2020-03-10 13:09:26 +00:00
|
|
|
}
|
|
|
|
|
2021-02-10 07:47:58 +00:00
|
|
|
onShippedChange(value) {
|
2021-02-11 07:32:16 +00:00
|
|
|
let hasFilledProperties;
|
|
|
|
let hasAgencyMode;
|
|
|
|
if (this.travel) {
|
|
|
|
hasAgencyMode = Boolean(this.travel.agencyModeFk);
|
|
|
|
hasFilledProperties = this.travel.landed || this.travel.warehouseInFk || this.travel.warehouseOutFk;
|
|
|
|
}
|
|
|
|
if (!hasAgencyMode || hasFilledProperties)
|
2021-02-10 07:47:58 +00:00
|
|
|
return;
|
|
|
|
|
2021-02-12 10:27:24 +00:00
|
|
|
const query = `travels/getAverageDays`;
|
2021-02-10 07:47:58 +00:00
|
|
|
const params = {
|
|
|
|
agencyModeFk: this.travel.agencyModeFk
|
|
|
|
};
|
|
|
|
this.$http.get(query, {params}).then(res => {
|
|
|
|
const landed = new Date(value);
|
2021-02-17 10:01:50 +00:00
|
|
|
const futureDate = landed.getDate() + res.data[0].dayDuration;
|
2021-02-10 07:47:58 +00:00
|
|
|
landed.setDate(futureDate);
|
|
|
|
|
|
|
|
this.travel.landed = landed;
|
2021-02-17 10:01:50 +00:00
|
|
|
this.travel.warehouseInFk = res.data[0].warehouseInFk;
|
|
|
|
this.travel.warehouseOutFk = res.data[0].warehouseOutFk;
|
2021-02-10 07:47:58 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-12-09 11:15:19 +00:00
|
|
|
onSubmit() {
|
|
|
|
return this.$.watcher.submit().then(
|
2020-12-28 13:53:26 +00:00
|
|
|
res => this.$state.go('travel.card.basicData', {id: res.data.id})
|
2019-12-09 11:15:19 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-24 12:22:30 +00:00
|
|
|
ngModule.vnComponent('vnTravelCreate', {
|
2019-12-09 11:15:19 +00:00
|
|
|
template: require('./index.html'),
|
|
|
|
controller: Controller
|
|
|
|
});
|