fix: edit values

This commit is contained in:
zeinab.ashrafi
2025-04-19 09:51:58 +03:30
parent 2e98810cf0
commit b599301477
3 changed files with 25 additions and 28 deletions
+2 -1
View File
@@ -99,6 +99,7 @@ const ApiService = {
export default ApiService export default ApiService
export { ApiService } export { ApiService }
/*
axios.interceptors.request.use(request => { axios.interceptors.request.use(request => {
// console.log("🔵 API Request:", request.method.toUpperCase(), request.url); // console.log("🔵 API Request:", request.method.toUpperCase(), request.url);
// console.log("🔹 Headers:", request.headers); // console.log("🔹 Headers:", request.headers);
@@ -117,4 +118,4 @@ axios.interceptors.response.use(response => {
}, error => { }, error => {
console.error("🔴 API Error:", error.response ? error.response.data : error); console.error("🔴 API Error:", error.response ? error.response.data : error);
return Promise.reject(error); return Promise.reject(error);
}); });*/
+15 -21
View File
@@ -120,33 +120,36 @@ export default {
formData: { formData: {
note: "", note: "",
labels: [ labels: [
{ {name: ''}
name: ''
}
] ]
}, },
labels: [], labels: [],
rules: { rules: {
required: value => !!value || "Required.", required: value => !!value || "Required.",
counter: value => counter: value => !value || value.length == 0 || value.length >= 5 || "Min 5 characters"
!value ||
value.length == 0 ||
value.length >= 5 ||
"Min 5 characters"
} }
}; };
}, },
created() { created() {
this.loadLabels();
if (this.$route.params.cycle) { if (this.$route.params.cycle) {
this.load(this.$route.params.cycle); this.load(this.$route.params.cycle);
} }
this.loadLabels();
}, },
methods: { methods: {
async load(id) { async load(id) {
const result = await ApiService.get(urls.editCycle(id)); const result = await ApiService.get(urls.editCycle(id));
if (result && result.status == 200) { if (result && result.status == 200) {
this.formData = result.data.data; this.formData = result.data.data;
const usedLabels = this.formData.labels.filter(i => i.id );
const existingIds = this.labels.map(i => i.id);
usedLabels.forEach(ui => {
if (!existingIds.includes(ui.id)) {
this.labels.push(ui);
}
});
console.log()
} }
}, },
async loadLabels() { async loadLabels() {
@@ -158,15 +161,9 @@ export default {
async submitForm() { async submitForm() {
let result; let result;
if (this.$route.params.cycle) { if (this.$route.params.cycle) {
result = await ApiService.put( result = await ApiService.put(urls.updateCycle(this.$route.params.cycle), this.formData);
urls.updateCycle(this.$route.params.cycle),
this.formData
);
} else { } else {
result = await ApiService.post( result = await ApiService.post(urls.storeCycle, this.formData);
urls.storeCycle,
this.formData
);
} }
if (result && result.status == 200) { if (result && result.status == 200) {
@@ -174,10 +171,7 @@ export default {
} }
}, },
duplicateForm(infoIndex) { duplicateForm(infoIndex) {
this.formData.labels.push({ this.formData.labels.push({name: "",});
name: "",
});
}, },
removeForm(infoIndex) { removeForm(infoIndex) {
this.formData.labels.splice(infoIndex, 1); this.formData.labels.splice(infoIndex, 1);
+8 -6
View File
@@ -104,19 +104,15 @@ export default {
items: [], items: [],
rules: { rules: {
required: value => !!value || "Required.", required: value => !!value || "Required.",
counter: value => counter: value => !value || value.length == 0 || value.length >= 5 || "Min 5 characters"
!value ||
value.length == 0 ||
value.length >= 5 ||
"Min 5 characters"
} }
}; };
}, },
created() { created() {
this.loadItems();
if (this.$route.params.label) { if (this.$route.params.label) {
this.load(this.$route.params.label); this.load(this.$route.params.label);
} }
this.loadItems();
}, },
computed: { computed: {
lotNumber() { lotNumber() {
@@ -138,6 +134,12 @@ export default {
const result = await ApiService.get(urls.editLabel(id)); const result = await ApiService.get(urls.editLabel(id));
if (result && result.status == 200) { if (result && result.status == 200) {
this.formData = result.data.data; this.formData = result.data.data;
const existingIds = this.items.map(i => i.id);
if (!existingIds.includes(this.formData.package_id)) {
this.items.push(this.formData.package);
}
console.log()
} }
}, },
async loadItems() { async loadItems() {