Add change handler to clin field components

- emit clin type and obligated amount
This commit is contained in:
montana-mil
2019-06-13 15:48:14 -04:00
committed by montana
parent 4074f11e25
commit c775c7322c
4 changed files with 65 additions and 31 deletions

View File

@@ -1,7 +1,11 @@
import DateSelector from './date_selector'
import { emitEvent } from '../lib/emitters'
import optionsinput from './options_input'
import textinput from './text_input'
const JEDI_CLIN_TYPE = "jedi_clin_type"
const OBLIGATED_AMOUNT = "obligated_amount"
export default {
name: 'clin-fields',
@@ -17,6 +21,7 @@ export default {
type: Number,
default: 0,
},
initialClinType: String,
},
data: function() {
@@ -27,9 +32,14 @@ export default {
clinIndex: this.initialClinIndex,
indexOffset: this.initialLoaCount,
loas: loas,
clinType: this.initialClinType,
}
},
mounted: function() {
this.$root.$on('field-change', this.handleFieldChange)
},
methods: {
addLoa: function(event) {
++this.loas
@@ -38,5 +48,20 @@ export default {
loaIndex: function(index) {
return index + this.indexOffset - 1
},
handleFieldChange: function(event) {
if (this._uid === event.parent_uid) {
if (event.name.includes(JEDI_CLIN_TYPE)) {
this.clinType = event.value
}
else if (event.name.includes(OBLIGATED_AMOUNT)) {
emitEvent('clin-change', this, {
clinType: this.clinType,
amount: event.value,
})
}
}
},
},
}