Files
FE_CPONE/test/vuex/one-fo-registration-dev/components/oneMouPxPx.vue
2026-04-27 10:13:31 +07:00

310 lines
9.3 KiB
Vue

<template>
<v-card-text>
<v-layout column>
<v-layout row>
<v-flex xs6 class="pa-0 ma-0" >
<v-text-field
label="Pemeriksaan"
placeholder="ketikkan pemeriksaan ..."
@change="search"
class="ma-0"
outline
hide-details
>
</v-text-field>
</v-flex>
<v-flex xs6 class="pa-3">
<v-label >
Test Found {{test_count}}, display {{ test_count < 20 ? test_count : display_count }}
</v-label>
</v-flex>
</v-layout>
<v-divider class="mt-2 mb-2"></v-divider>
<v-progress-linear class="ma-0 pa-0" indeterminate :active="is_loading" />
</v-layout>
<v-container grid-list-xs pa-0>
<v-layout row wrap>
<v-flex xs6 v-for="test in tests" :key="test.T_TestPriceID"
pr-2
>
<v-btn block
:disabled="is_selectPx"
@click="selectPx(test)"
depressed small :color="px_color(test.px_type)" dark
outline
class="ma-0 btn-px"
>
{{test.T_TestName}}
</v-btn>
</v-flex>
</v-layout>
</v-container>
</v-card-text>
</template>
<style scoped>
.btn-px > .v-btn__content {
justify-content: left !important
}
</style>
<script>
let in_selectPx = false
module.exports = {
methods: {
search(val) {
if ( val == this.prev_search ) return
console.log('Searching',val)
this.prev_search = val
this.$store.commit("px/update_search",val)
this.$store.dispatch("px/search")
},
selectPx(px) {
try {
// START LOADING
this.$store.commit('update_dialog_loading', true)
// IF PROFILE
if (px.px_type == "PR" || px.px_type == "PXR")
return this.selectProfile(px)
// SEARCH NAT TEST
let nt = this.$store.state.px.nat_test
let found_nt = false
for (let i in px.nat_test) {
if (nt.indexOf(px.nat_test[i]) > -1)
found_nt = true
}
if (found_nt) {
alert('Pemeriksaan tersebut sudah ada !')
// END LOADING
this.$store.commit('update_dialog_loading', false)
return
}
if (in_selectPx) return
in_selectPx = true
let selected_test = this.$store.state.px.selected_test
let flag_found = false
selected_test.forEach( function(t,idx) {
if (t.T_TestID == px.T_TestID) {
selected_test[idx] = px
flag_found = true
}
})
if (!flag_found) {
selected_test.push(px)
let tests = this.$store.state.px.tests
let p_idx = -1
tests.forEach(function(t,idx) {
if (t.T_TestID == px.T_TestID) {
p_idx = idx
}
})
if (p_idx >= 0 ) {
_.pullAt(tests,[p_idx])
let dt = {
records: tests,
total: tests.length
}
this.$store.commit('px/update_tests',dt)
}
}
this.$store.commit('px/update_selected_test', selected_test)
let req = px.requirement
let reqs = this.$store.state.px.requirement
if (req.length > 0) {
for(let i in req) {
let found = false
for(let j in reqs) {
if (reqs[j]['req_id'] == req[i]['req_id'])
found = j
}
if (!found)
reqs.push({
px_id: [px.T_TestID],
label: req[i]['req_name'],
error_message: 'Hasil harus di isi',
is_error: true,
checked : false,
note: '',
req_id: req[i]['req_id']
})
else
reqs[found].px_id.push(px.T_TestID)
}
this.$store.commit('px/update_requirement', reqs)
}
this.$store.dispatch('px/appx_schedule')
// if (px.T_TestRequirement != '' ) {
// let reqs = this.$store.state.px.requirement
// let rst = _.find(reqs, function(r) { return r.label == px.T_TestRequirement; })
// if ( rst == undefined ) {
// reqs.push({
// px_id: px.T_TestID,
// label: px.T_TestRequirement,
// error_message: 'Hasil harus di isi',
// is_error: true,
// checked : false,
// note: ''
// })
// }
// this.$store.commit('px/update_requirement',reqs)
// // Update Janji Hasil
// this.$store.dispatch('px/appx_schedule')
// }
// checked:false
// error_message:"Hasil harus di isi"
// is_error:true
// label:null
// note:""
// px_id:"969"
in_selectPx = false
this.$store.commit('px/update_nat_test')
// END LOADING
this.$store.commit('update_dialog_loading', false)
} catch(e) {
console.log(e)
in_selectPx = false
}
},
selectProfile(px) {
try {
// SEARCH NAT TEST
let nt = this.$store.state.px.nat_test
let found_nt = false
for (let i in px.nat_test) {
if (nt.indexOf(px.nat_test[i]) > -1)
found_nt = true
}
if (found_nt) {
alert('Pemeriksaan tersebut sudah ada !')
// END LOADING
this.$store.commit('update_dialog_loading', false)
return
}
let pxs = px.child_test
for (let i in pxs) {
px = pxs[i]
let selected_test = this.$store.state.px.selected_test
let flag_found = false
selected_test.push(px)
let tests = this.$store.state.px.tests
let p_idx = -1
tests.forEach(function(t,idx) {
if (t.T_TestID == px.T_TestID) {
p_idx = idx
}
})
if (p_idx >= 0 ) {
_.pullAt(tests,[p_idx])
let dt = {
records: tests,
total: tests.length
}
this.$store.commit('px/update_tests',dt)
}
this.$store.commit('px/update_selected_test', selected_test)
let req = px.requirement
let reqs = this.$store.state.px.requirement
if (req.length > 0) {
for(let i in req) {
let found = false
for(let j in reqs) {
if (reqs[j]['req_id'] == req[i]['req_id'])
found = j
}
if (!found)
reqs.push({
px_id: [px.T_TestID],
label: req[i]['req_name'],
error_message: 'Hasil harus di isi',
is_error: true,
checked : false,
note: '',
req_id: req[i]['req_id']
})
else
reqs[found].px_id.push(px.T_TestID)
}
this.$store.commit('px/update_requirement', reqs)
}
}
this.$store.dispatch('px/appx_schedule')
in_selectPx = false
this.$store.commit('px/update_nat_test')
// END LOADING
this.$store.commit('update_dialog_loading', false)
} catch(e) {
console.log(e)
// END LOADING
this.$store.commit('update_dialog_loading', false)
in_selectPx = false
}
},
px_color (x) {
if (x == "PR")
return "green"
else if (x == "PN")
return "orange"
else
return "error"
}
},
computed: {
test_count() {
return this.$store.state.px.total_test
},
display_count() {
return this.tests.length
},
tests() {
return this.$store.state.px.tests
},
is_selectPx() {
return in_selectPx
},
is_loading() {
return this.$store.state.px.search_status == 1
}
},
data: function(){
return {
prev_search : ''
}
}
}
</script>