Refactoring premiss edit:
- fixed bug in mass edit, when editing single value
This commit is contained in:
parent
20fa52826a
commit
20ad15e4e4
4 changed files with 43 additions and 61 deletions
|
|
@ -239,15 +239,17 @@ export default {
|
|||
.edit-calculation-cell {
|
||||
flex: 1 1 auto;
|
||||
margin: 1.6rem 0;
|
||||
padding: 0.8rem;
|
||||
}
|
||||
|
||||
.edit-calculation-empty {
|
||||
flex: 1 1 auto;
|
||||
margin: 1.6rem 0;
|
||||
padding: 0.8rem;
|
||||
}
|
||||
|
||||
.copyable-cell {
|
||||
padding: 0.8rem;
|
||||
|
||||
border-radius: 0.8rem;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,17 +1,14 @@
|
|||
<template>
|
||||
<div class="container" :class="{ 'responsive': responsive }" @focusout="focusLost">
|
||||
|
||||
<div class="field-group">
|
||||
<div class="field-group" v-if="!hideDescription">
|
||||
<div class="caption-column">Part number</div>
|
||||
<div class="input-column">
|
||||
<span>{{ partNumber }}</span>
|
||||
<modal :state="modalSelectMaterial" @close="closeEditModal">
|
||||
<select-material :part-number="partNumber" @close="modalEditClick"/>
|
||||
</modal>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="field-group">
|
||||
<div class="field-group" v-if="!hideDescription">
|
||||
<div class="caption-column">Description</div>
|
||||
<div class="input-column">
|
||||
<span>{{ description }}</span>
|
||||
|
|
@ -83,7 +80,7 @@ export default {
|
|||
type: String,
|
||||
required: true,
|
||||
},
|
||||
openSelectDirect: {
|
||||
hideDescription: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
|
|
@ -100,11 +97,10 @@ export default {
|
|||
},
|
||||
data() {
|
||||
return {
|
||||
modalSelectMaterial: false,
|
||||
|
||||
}
|
||||
},
|
||||
created() {
|
||||
this.modalSelectMaterial = this.openSelectDirect;
|
||||
},
|
||||
methods: {
|
||||
focusLost(event) {
|
||||
|
|
@ -112,22 +108,6 @@ export default {
|
|||
this.$emit('save', 'material');
|
||||
}
|
||||
},
|
||||
closeEditModal() {
|
||||
this.modalSelectMaterial = false;
|
||||
if (this.openSelectDirect) {
|
||||
this.$emit('close');
|
||||
}
|
||||
},
|
||||
modalEditClick(data) {
|
||||
this.modalSelectMaterial = false;
|
||||
|
||||
if (data.action === 'accept') {
|
||||
this.selectedMaterial = data.material;
|
||||
this.$emit('updateMaterial', data.material.id, data.updateMasterData ? 'updateMasterData' : 'keepMasterData');
|
||||
} else if (this.openSelectDirect) {
|
||||
this.$emit('close');
|
||||
}
|
||||
},
|
||||
updateInputValue(inputRef, formattedValue) {
|
||||
this.$nextTick(() => {
|
||||
if (this.$refs[inputRef] && this.$refs[inputRef].value !== formattedValue) {
|
||||
|
|
@ -147,9 +127,6 @@ export default {
|
|||
|
||||
event.target.value = validatedPercent === null ? null : validatedPercent.toFixed(2);
|
||||
},
|
||||
activateEditMode() {
|
||||
this.modalSelectMaterial = true;
|
||||
},
|
||||
async fetchHsCode(query) {
|
||||
const hsCodeQuery = {searchTerm: query};
|
||||
await this.customsStore.setQuery(hsCodeQuery);
|
||||
|
|
|
|||
|
|
@ -84,6 +84,7 @@
|
|||
v-model:unitCount="componentProps.unitCount"
|
||||
v-model:mixable="componentProps.mixable"
|
||||
v-model:stackable="componentProps.stackable"
|
||||
v-model:hideDescription="componentProps.hideDescription"
|
||||
:responsive="false"
|
||||
@close="closeEditModalAction('cancel')"
|
||||
|
||||
|
|
@ -193,7 +194,7 @@ export default {
|
|||
modalType: null,
|
||||
componentsData: {
|
||||
price: {props: {price: 0, overSeaShare: 0, includeFcaFee: false}},
|
||||
material: {props: {partNumber: "", hsCode: "", tariffRate: 0.00, description: "", openSelectDirect: false}},
|
||||
material: {props: {partNumber: "", hsCode: "", tariffRate: 0.00, description: "", hideDescription: false}},
|
||||
packaging: {
|
||||
props: {
|
||||
length: 0,
|
||||
|
|
@ -248,7 +249,7 @@ export default {
|
|||
openModal(type, ids, dataSource = -1, massEdit = true) {
|
||||
|
||||
if (type !== 'destinations')
|
||||
this.fillData(type, dataSource)
|
||||
this.fillData(type, dataSource, massEdit)
|
||||
else {
|
||||
this.premiseEditStore.prepareDestinations(dataSource, ids, massEdit, true);
|
||||
}
|
||||
|
|
@ -287,13 +288,13 @@ export default {
|
|||
this.fillData(this.modalType);
|
||||
this.modalType = null;
|
||||
},
|
||||
fillData(type, id = -1) {
|
||||
fillData(type, id = -1, hideDescription = false) {
|
||||
|
||||
if (id === -1) {
|
||||
// clear
|
||||
this.componentsData = {
|
||||
price: {props: {price: null, overSeaShare: null, includeFcaFee: null}},
|
||||
material: {props: {partNumber: "", hsCode: "", tariffRate: null, description: null, openSelectDirect: true}},
|
||||
material: {props: {partNumber: "", hsCode: "", tariffRate: null, description: null, hideDescription: hideDescription}},
|
||||
packaging: {
|
||||
props: {
|
||||
length: null,
|
||||
|
|
@ -322,21 +323,21 @@ export default {
|
|||
|
||||
this.componentsData.material.props = {
|
||||
partNumber: premise.material.part_number,
|
||||
hsCode: premise.material.hs_code ?? "",
|
||||
hsCode: premise.material.hs_code,
|
||||
tariffRate: premise.tariff_rate ?? 0.00,
|
||||
description: premise.material.name ?? "",
|
||||
openSelectDirect: false
|
||||
hideDescription: hideDescription
|
||||
}
|
||||
|
||||
} else if (type === "packaging") {
|
||||
this.componentsData.packaging.props = {
|
||||
length: premise.handling_unit.length ?? 0,
|
||||
width: premise.handling_unit.width ?? 0,
|
||||
height: premise.handling_unit.height ?? 0,
|
||||
weight: premise.handling_unit.weight ?? 0,
|
||||
length: premise.handling_unit.length,
|
||||
width: premise.handling_unit.width,
|
||||
height: premise.handling_unit.height,
|
||||
weight: premise.handling_unit.weight,
|
||||
weightUnit: premise.handling_unit.weight_unit ?? "KG",
|
||||
dimensionUnit: premise.handling_unit.dimension_unit ?? "MM",
|
||||
unitCount: premise.handling_unit.content_unit_count ?? 1,
|
||||
unitCount: premise.handling_unit.content_unit_count,
|
||||
mixable: premise.is_mixable ?? true,
|
||||
stackable: premise.is_stackable ?? true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -264,7 +264,7 @@ export const usePremiseEditStore = defineStore('premiseEdit', {
|
|||
});
|
||||
this.premisses = updatedPremises;
|
||||
|
||||
return await this.savePrice(ids);
|
||||
return await this.savePrice(ids, priceData);
|
||||
},
|
||||
async batchUpdateMaterial(ids, materialData) {
|
||||
const updatedPremises = this.premisses.map(p => {
|
||||
|
|
@ -283,9 +283,11 @@ export const usePremiseEditStore = defineStore('premiseEdit', {
|
|||
});
|
||||
this.premisses = updatedPremises;
|
||||
|
||||
return await this.saveMaterial(ids);
|
||||
return await this.saveMaterial(ids, materialData);
|
||||
},
|
||||
async batchUpdatePackaging(ids, packagingData) {
|
||||
|
||||
|
||||
const updatedPremises = this.premisses.map(p => {
|
||||
if (ids.includes(p.id)) {
|
||||
return {
|
||||
|
|
@ -308,7 +310,9 @@ export const usePremiseEditStore = defineStore('premiseEdit', {
|
|||
});
|
||||
this.premisses = updatedPremises;
|
||||
|
||||
return await this.savePackaging(ids);
|
||||
logger.info("packaging data:", toRaw(packagingData), "update result", toRaw(updatedPremises));
|
||||
|
||||
return await this.savePackaging(ids, packagingData);
|
||||
},
|
||||
async startCalculation() {
|
||||
|
||||
|
|
@ -698,7 +702,7 @@ export const usePremiseEditStore = defineStore('premiseEdit', {
|
|||
* Save
|
||||
*/
|
||||
|
||||
async savePrice(ids = null) {
|
||||
async savePrice(ids = null, priceData = null) {
|
||||
let success = true;
|
||||
const toBeUpdated = this.premisses ? (ids ? (ids.map(id => this.premisses.find(p => String(p.id) === String(id)))) : (this.premisses.filter(p => p.selected))) : null;
|
||||
|
||||
|
|
@ -706,9 +710,9 @@ export const usePremiseEditStore = defineStore('premiseEdit', {
|
|||
|
||||
const body = {
|
||||
premise_ids: toBeUpdated.map(p => p.id),
|
||||
material_cost: toBeUpdated[0].material_cost,
|
||||
oversea_share: toBeUpdated[0].oversea_share,
|
||||
is_fca_enabled: toBeUpdated[0].is_fca_enabled
|
||||
material_cost: priceData === null ? toBeUpdated[0].material_cost : priceData.material_cost,
|
||||
oversea_share: priceData === null ? toBeUpdated[0].oversea_share : priceData.oversea_share,
|
||||
is_fca_enabled: priceData === null ? toBeUpdated[0].is_fca_enabled : priceData.includeFcaFee
|
||||
};
|
||||
|
||||
await performRequest(this, 'POST', `${config.backendUrl}/calculation/price/`, body, false).catch(e => {
|
||||
|
|
@ -717,32 +721,30 @@ export const usePremiseEditStore = defineStore('premiseEdit', {
|
|||
|
||||
return success;
|
||||
},
|
||||
async savePackaging(ids = null) {
|
||||
async savePackaging(ids = null, packagingData = null) {
|
||||
let success = true;
|
||||
|
||||
const toBeUpdated = this.premisses ? (ids ? (ids.map(id => this.premisses.find(p => String(p.id) === String(id)))) : (this.premisses.filter(p => p.selected))) : null;
|
||||
|
||||
if (!toBeUpdated?.length) return;
|
||||
|
||||
logger.info(toBeUpdated[0]);
|
||||
|
||||
const body = {
|
||||
premise_ids: toBeUpdated.map(p => p.id),
|
||||
|
||||
handling_unit: {
|
||||
weight: toBeUpdated[0].handling_unit.weight,
|
||||
weight_unit: toBeUpdated[0].handling_unit.weight_unit,
|
||||
weight: packagingData === null ? toBeUpdated[0].handling_unit.weight : packagingData.weight,
|
||||
weight_unit: packagingData === null ? toBeUpdated[0].handling_unit.weight_unit : packagingData.weightUnit,
|
||||
|
||||
length: toBeUpdated[0].handling_unit.length,
|
||||
width: toBeUpdated[0].handling_unit.width,
|
||||
height: toBeUpdated[0].handling_unit.height,
|
||||
dimension_unit: toBeUpdated[0].handling_unit.dimension_unit,
|
||||
length: packagingData === null ? toBeUpdated[0].handling_unit.length : packagingData.length,
|
||||
width: packagingData === null ? toBeUpdated[0].handling_unit.width : packagingData.width,
|
||||
height: packagingData === null ? toBeUpdated[0].handling_unit.height : packagingData.height,
|
||||
dimension_unit: packagingData === null ? toBeUpdated[0].handling_unit.dimension_unit : packagingData.dimensionUnit,
|
||||
|
||||
content_unit_count: toBeUpdated[0].handling_unit.content_unit_count,
|
||||
content_unit_count: packagingData === null ? toBeUpdated[0].handling_unit.content_unit_count : packagingData.unitCount,
|
||||
},
|
||||
|
||||
is_mixable: toBeUpdated[0].is_mixable,
|
||||
is_stackable: toBeUpdated[0].is_stackable,
|
||||
is_mixable: packagingData === null ? toBeUpdated[0].is_mixable : packagingData.mixable,
|
||||
is_stackable: packagingData === null ? toBeUpdated[0].is_stackable : packagingData.stackable,
|
||||
|
||||
};
|
||||
|
||||
|
|
@ -753,7 +755,7 @@ export const usePremiseEditStore = defineStore('premiseEdit', {
|
|||
return success;
|
||||
|
||||
},
|
||||
async saveMaterial(ids = null) {
|
||||
async saveMaterial(ids = null, materialData = null) {
|
||||
let success = true;
|
||||
const toBeUpdated = this.premisses ? (ids ? (ids.map(id => this.premisses.find(p => String(p.id) === String(id)))) : (this.premisses.filter(p => p.selected))) : null;
|
||||
|
||||
|
|
@ -763,8 +765,8 @@ export const usePremiseEditStore = defineStore('premiseEdit', {
|
|||
const body = {
|
||||
premise_ids: toBeUpdated.map(p => p.id),
|
||||
|
||||
hs_code: toBeUpdated[0].hs_code,
|
||||
tariff_rate: toBeUpdated[0].tariff_rate,
|
||||
hs_code: materialData === null ? toBeUpdated[0].hs_code : materialData.hsCode,
|
||||
tariff_rate: materialData === null ? toBeUpdated[0].tariff_rate : materialData.tariffRate,
|
||||
};
|
||||
|
||||
await performRequest(this, 'POST', `${config.backendUrl}/calculation/material/`, body, false).catch(() => {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue