Commit 71fb597c authored by hypsug0's avatar hypsug0
Browse files

fix: deep copy newSighting

parent ed851362
......@@ -1026,7 +1026,7 @@ const countDetailOtherForm = [
'comment',
]
const CountDetailObject = (lastdata) => {
const CountDetailObject = () => {
return {
id_countdetail: null,
method: null,
......@@ -1458,7 +1458,6 @@ const sigthingFormApp = (id_session, type_contact) => {
typeContact: type_contact,
moreSightingForm: false,
moreCountDetailForm: false,
// dictSpecies: [],
messages: [],
countDetailSelectedItem: -1,
postInProgress: 0,
......@@ -1489,43 +1488,36 @@ const sigthingFormApp = (id_session, type_contact) => {
return !(this.initialDataLoaded && this.dictsLoaded)
},
addNewSighting() {
console.log('test', this.data.find(e => e.codesp == null))
if (!this.data.find(e => e.codesp == null)) {
const newSighting = { ...this.newSighting }
const newCountDetail = { ...this.newCountDetail }
if (!this.data.find((e) => e.codesp == null)) {
const newSightingObject = JSON.parse(JSON.stringify(this.newSighting))
const newCountDetailObject = { ...this.newCountDetail }
const allCountDetails = []
this.data.forEach((es) =>
allCountDetails.push(...es.countdetails)
)
console.debug('<allCountDetails>', allCountDetails)
const lastCountDetail =
allCountDetails[allCountDetails.length - 1]
if (lastCountDetail) {
// const lastCountDetail = allCountDetail[allCountDetail.length - 1]
console.debug(
'<addNewCountDetail> has countdetails items'
)
console.debug(
'newObject before',
lastCountDetail,
newCountDetail
)
newCountDetail.time = lastCountDetail.time
newCountDetail.method = lastCountDetail.method
newCountDetail.precision = lastCountDetail.precision
newCountDetail.unit = lastCountDetail.unit
newCountDetailObject.time = lastCountDetail.time
newCountDetailObject.method = lastCountDetail.method
newCountDetailObject.precision =
lastCountDetail.precision
newCountDetailObject.unit = lastCountDetail.unit
if (type_contact == 'vm') {
newCountDetail.count = 1
}
console.log('newObject after', newCountDetail)
}
newSighting.countdetails.push(newCountDetail)
this.data.push(newSighting)
newSightingObject.countdetails.push(newCountDetailObject)
if (type_contact == 'du') {
newSightingObject.total_count = 1
}
this.data.push(newSightingObject)
this.selectedItem = this.data.length - 1
this.countDetailSelectedItem = 0
}
else {
alert('Vous ne pouvez pas entrez d autre taxon si tous ne sont pas complétés')
} else {
alert(
'Vous ne pouvez pas entrez d autre taxon si tous ne sont pas complétés'
)
}
},
// refactorForSelect(dict, contact) {
......@@ -1628,8 +1620,7 @@ const sigthingFormApp = (id_session, type_contact) => {
console.log('DELETE', r)
this.data.splice(i, 1)
})
}
else {
} else {
this.data.splice(i, 1)
}
},
......@@ -1821,9 +1812,11 @@ const sigthingFormApp = (id_session, type_contact) => {
watch: {
data: {
handler() {
this.data.forEach((e, i) => {
e.total_count = this.sumCountDetails(i)
})
if (type_contact != 'du') {
this.data.forEach((e, i) => {
e.total_count = this.sumCountDetails(i)
})
}
this.dupSpecies()
},
deep: true,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment