Files
REG_IBL/one-ui/masterdata/one-md-doctor-v3x/components/oneMdDoctorAddress.vue
2026-05-25 20:01:37 +07:00

528 lines
23 KiB
Vue

<template>
<v-layout column >
<v-dialog v-model="dialogconfirmationdeleteaddr" persistent max-width="290">
<v-card>
<v-card-title
dark
class="headline error pt-2 pb-2"
primary-title
style="color:white"
>
<h4 dark>Konfirmasi</h4>
</v-card-title>
<v-card-text>
{{msgconfirmationdeleteaddr}}
</v-card-text>
<v-card-actions>
<v-spacer></v-spacer>
<v-btn small v-if="!checkError('deleteutama')" color="error darken-1 text-sm-left" flat @click="doDeleteAddr()">Hapus</v-btn>
<v-btn small color="primary darken-1 text-sm-right" flat @click="dialogconfirmationdeleteaddr = false">Batal</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
<v-dialog v-model="dialogformaddress" persistent max-width="650">
<v-card>
<v-card-title>
<span class="headline">Form Alamat Dokter</span>
</v-card-title>
<v-card-text class="pt-0 pb-0">
<v-layout wrap>
<v-flex xs5 pa-1>
<v-text-field v-model="labeladdress" label="Label"></v-text-field>
<p v-if="checkError('requiredlabel')" class="error pl-2 pr-2" style="color:#fff">Jangan kosong dong</p>
<p v-if="checkError('readonlyutama')" class="error pl-2 pr-2" style="color:#fff">Biarkan jadi yang utama</p>
</v-flex>
<v-flex xs7 pa-1>
<v-select
item-text="Nat_JpaName"
return-object
:items="xjpas"
v-model="jpaaddress"
hide-details
label="JPA"
></v-select>
<p v-if="checkError('requiredjpa')" class="error pl-2 pr-2" style="color:#fff">Jangan kosong dong</p>
</v-flex>
<v-flex xs12>
<v-layout row>
<v-flex xs4 pa-1>
<v-autocomplete
label="Kota"
v-model="cityaddress"
:items="xcities"
:search-input.sync="search_city"
auto-select-first
hide-details
no-filter
item-text="M_CityName"
return-object
:loading="isLoading"
no-data-text="Pilih Kota"
>
<template
slot="item"
slot-scope="{ item }"
>
<v-list-tile-content>
<v-list-tile-title v-text="item.M_CityName"></v-list-tile-title>
</v-list-tile-content>
</template>
</v-autocomplete>
<p v-if="checkError('requiredcity')" class="error pl-2 pr-2" style="color:#fff">Jangan kosong deh</p>
</v-flex>
<v-flex xs4 pa-1>
<v-select
item-text="M_DistrictName"
return-object
:items="xdistricts"
v-model="districtaddress"
hide-details
label="Kecamatan*"
></v-select>
<p v-if="checkError('requireddistrict')" class="error pl-2 pr-2" style="color:#fff">Jangan kosong dong</p>
</v-flex>
<v-flex xs4 pa-1>
<v-select
item-text="M_KelurahanName"
return-object
:items="xkelurahans"
v-model="kelurahanaddress"
hide-details
label="Kelurahan / Desa*"
></v-select>
<p v-if="checkError('requiredkelurahan')" class="error pl-2 pr-2" style="color:#fff">Jangan kosong deh</p>
</v-flex>
</v-layout>
</v-flex>
<v-flex xs12>
<v-textarea
box
label="Alamat Lengkap"
v-model="descriptionaddress"
hide-details
></v-textarea>
<p v-if="checkError('requireddescription')" class="error pl-2 pr-2" style="color:#fff">Jangan kosong dong</p>
</v-flex>
</v-layout>
</v-card-text>
<v-card-actions>
<v-spacer></v-spacer>
<v-btn color="grey darken-1" flat @click="cancelAddress()">Batal</v-btn>
<v-btn dark v-if="xactaddr === 'new'" color="teal" flat @click="saveAddress()">Simpan</v-btn>
<v-btn dark v-if="xactaddr === 'edit' && xact !== 'new'" color="teal" flat @click="saveEditAddress()">Simpan</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
<v-card>
<v-layout row>
<v-flex xs12>
<v-subheader red--text text--lighten-1> ALAMAT DOKTER
<v-flex text-md-right>
<v-btn @click="createNewAddress()" small dark color="teal">Baru</v-btn>
</v-flex>
</v-subheader>
<v-divider></v-divider>
<v-layout row wrap>
<v-flex xs12 pa-2>
<v-data-table
:headers="headers"
:items="addresses"
:loading="isLoading"
hide-actions class="elevation-1">
<template slot="items" slot-scope="props">
<td class="text-xs-center pa-2">
<v-icon v-if="xact !== 'new'" color="error" @click="deleteAddress(props.item)">delete</v-icon>
<v-icon v-if="xact !== 'new'" class="ml-3" color="teal " @click="editAddress(props.item)">edit</v-icon>
</td>
<td class="text-xs-left pa-2">{{ props.item.M_DoctorAddressNote}}</td>
<td class="text-xs-left pa-2">{{ props.item.M_DoctorAddressDescription}}</td>
<td class="text-xs-left pa-2">{{ props.item.Nat_JpaName}}</td>
</template>
</v-data-table>
</v-flex>
</v-layout>
</v-flex>
</v-layout>
</v-card>
</v-layout>
</template>
<style scoped>
</style>
<script>
module.exports = {
data: () => ({
search_city:'',
oldlabel:'',
tmp_id:-1,
headers: [
{
text: "AKSI",
align: "center",
sortable: false,
value: "action",
width: "10%",
class: "pa-1 teal lighten-3 white--text"
},
{
text: "LABEL",
align: "left",
sortable: false,
value: "mr",
width: "20%",
class: "pa-1 teal lighten-3 white--text"
},
{
text: "ALAMAT",
align: "left",
sortable: false,
value: "lab",
width: "30%",
class: "pa-1 teal lighten-3 white--text"
},
{
text: "JPA",
align: "left",
sortable: false,
value: "lab",
width: "20%",
class: "pa-1 teal lighten-3 white--text"
}
]
}),
computed: {
dialogconfirmationdeleteaddr:{
get() {
return this.$store.state.doctor.dialog_confirmation_delete_addr
},
set(val) {
this.$store.commit("doctor/update_dialog_confirmation_delete_addr",val)
}
},
msgconfirmationdeleteaddr(){
return this.$store.state.doctor.msg_confirmation_delete_addr
},
xact() {
return this.$store.state.doctor.act
},
xactaddr() {
return this.$store.state.doctor.act_addr
},
dialogformaddress:{
get() {
return this.$store.state.doctor.dialog_form_address
},
set(val) {
this.$store.commit("doctor/update_dialog_form_address",val)
}
},
isLoading() {
return this.$store.state.doctor.search_status == 1
},
addresses:{
get() {
return this.$store.state.doctor.addresses
},
set(val) {
this.$store.commit("doctor/update_addresses",val)
}
},
xcities(){
return this.$store.state.doctor.cities
},
labeladdress:{
get() {
return this.$store.state.doctor.label_address
},
set(val) {
this.$store.commit("doctor/update_label_address",val)
}
},
cityaddress:{
get() {
return this.$store.state.doctor.city_address
},
set(val) {
this.$store.commit("doctor/update_city_address",val)
this.$store.dispatch("doctor/getdistrict",this.$store.state.doctor.city_address)
}
},
xdistricts(){
return this.$store.state.doctor.districts
},
districtaddress:{
get() {
return this.$store.state.doctor.district_address
},
set(val) {
this.$store.commit("doctor/update_district_address",val)
this.$store.dispatch("doctor/getkelurahan",this.$store.state.doctor.district_address)
}
},
xkelurahans(){
return this.$store.state.doctor.kelurahans
},
kelurahanaddress:{
get() {
return this.$store.state.doctor.kelurahan_address
},
set(val) {
this.$store.commit("doctor/update_kelurahan_address",val)
}
},
xjpas(){
return this.$store.state.doctor.jpas
},
jpaaddress:{
get() {
return this.$store.state.doctor.jpa_address
},
set(val) {
this.$store.commit("doctor/update_jpa_address",val)
}
},
descriptionaddress:{
get() {
return this.$store.state.doctor.description_address
},
set(val) {
this.$store.commit("doctor/update_description_address",val)
}
},
},
methods : {
createNewAddress(){
this.$store.commit("doctor/update_act_addr",'new')
this.search_city = ''
this.labeladdress = ''
this.$store.commit("doctor/update_cities",[])
this.cityaddress = {}
this.$store.commit("doctor/update_districts",[])
this.districtaddress = {}
this.$store.commit("doctor/update_kelurahans",[])
this.kelurahanaddress = {}
//this.$store.commit("doctor/update_jpas",[])
this.jpaaddress = {}
this.descriptionaddress = ''
this.$store.commit("doctor/update_dialog_form_address",true)
},
cancelAddress(){
this.$store.commit("doctor/update_dialog_form_address",false)
},
thr_search_city: _.debounce( function () {
this.$store.dispatch("doctor/searchcity",this.search_city)
},2000),
checkError(value){
var errors = this.$store.state.doctor.errors
if(errors.includes(value)){
return true
}
else{
return false
}
},
saveAddress(){
//alert('dsadasd')
this.$store.commit("doctor/update_errors",[])
var errors = this.$store.state.doctor.errors
if(this.labeladdress === ''){
errors.push("requiredlabel")
}
if(_.isEmpty(this.cityaddress)){
errors.push("requiredcity")
}
if(_.isEmpty(this.districtaddress)){
errors.push("requireddistrict")
}
if(_.isEmpty(this.kelurahanaddress)){
errors.push("requiredkelurahan")
}
if(_.isEmpty(this.$store.state.doctor.jpa_address)){
errors.push("requiredjpa")
}
if(_.isEmpty(this.descriptionaddress)){
errors.push("requireddescription")
}
if(errors.length === 0){
var prm = {}
prm.M_DoctorAddressM_DoctorID = this.$store.state.doctor.selected_doctor.M_DoctorID
prm.M_DoctorName = this.$store.state.doctor.selected_doctor.M_DoctorName
prm.M_DoctorAddressNote = this.labeladdress
prm.M_DoctorAddressDescription = this.descriptionaddress
prm.M_DoctorAddressM_KelurahanID = this.kelurahanaddress.M_KelurahanID
prm.M_CityID = this.cityaddress.M_CityID
prm.M_CityName = this.cityaddress.M_CityName
prm.M_DistrictID = this.districtaddress.M_DistrictID
prm.M_DistrictName = this.districtaddress.M_DistrictName
prm.M_KelurahanID = this.kelurahanaddress.M_KelurahanID
prm.M_KelurahanName = this.kelurahanaddress.M_KelurahanName
prm.M_DoctorAddressNat_JpaID = this.$store.state.doctor.jpa_address.Nat_JpaID
prm.Nat_JpaName = this.$store.state.doctor.jpa_address.Nat_JpaName
console.log(this.$store.state.doctor.selected_doctor)
if(!_.isEmpty(this.$store.state.doctor.selected_doctor)){
this.$store.dispatch("doctor/savenewaddress",prm)
}
else{
prm.tmp_id = Math.floor((Math.random() * 100) + 1)
var xaddress_now = this.$store.state.doctor.addresses
console.log(xaddress_now)
console.log('dasdasdrreee')
xaddress_now.push(prm)
console.log(xaddress_now)
this.$store.commit("doctor/update_addresses",xaddress_now)
this.$store.commit("doctor/update_dialog_form_address",false)
}
}
},
saveNewAddress(){
this.$store.commit("doctor/update_errors",[])
var errors = this.$store.state.doctor.errors
if(this.labeladdress === ''){
errors.push("requiredlabel")
}
if(_.isEmpty(this.cityaddress)){
errors.push("requiredcity")
}
if(_.isEmpty(this.districtaddress)){
errors.push("requireddistrict")
}
if(_.isEmpty(this.kelurahanaddress)){
errors.push("requiredkelurahan")
}
if(_.isEmpty(this.$store.state.doctor.jpa_address)){
errors.push("requiredjpa")
}
if(_.isEmpty(this.descriptionaddress)){
errors.push("requireddescription")
}
if(errors.length === 0){
var prm = {}
prm.M_DoctorAddressM_DoctorID = this.$store.state.doctor.selected_doctor.M_DoctorID
prm.M_DoctorName = this.$store.state.doctor.selected_doctor.M_DoctorName
prm.M_DoctorAddressNote = this.labeladdress
prm.M_DoctorAddressDescription = this.descriptionaddress
prm.M_DoctorAddressM_KelurahanID = this.kelurahanaddress.M_KelurahanID
prm.M_DoctorAddressNat_JpaID = this.$store.state.doctor.jpa_address.Nat_JpaID
this.$store.dispatch("doctor/savenewaddress",prm)
}
},
editAddress(value){
this.tmp_id = -1
console.log("matahasa")
this.$store.commit("doctor/update_act_addr",'edit')
this.$store.commit("doctor/update_x_addr_id",value.M_DoctorAddressID)
this.labeladdress = value.M_DoctorAddressNote
this.oldlabel = value.M_DoctorAddressNote
this.$store.commit("doctor/update_cities",[{M_CityID:value.M_CityID,M_CityName:value.M_CityName}])
this.cityaddress = {M_CityID:value.M_CityID,M_CityName:value.M_CityName}
this.$store.commit("doctor/update_districts",[{M_DistrictID:value.M_DistrictID,M_DistrictName:value.M_DistrictName}])
this.districtaddress = {M_DistrictID:value.M_DistrictID,M_DistrictName:value.M_DistrictName}
this.$store.commit("doctor/update_kelurahans",[{M_KelurahanID:value.M_DoctorAddressM_KelurahanID,M_KelurahanName:value.M_KelurahanName}])
this.kelurahanaddress = {M_KelurahanID:value.M_DoctorAddressM_KelurahanID,M_KelurahanName:value.M_KelurahanName}
//this.$store.commit("doctor/update_jpas",[{Nat_JpaID:value.M_DoctorAddressNat_JpaID,Nat_JpaName:value.Nat_JpaName}])
this.jpaaddress = {Nat_JpaID:value.M_DoctorAddressNat_JpaID,Nat_JpaName:value.Nat_JpaName}
this.descriptionaddress = value.M_DoctorAddressDescription
if(value.tmp_id){
this.tmp_id = value.tmp_id
}
this.$store.commit("doctor/update_dialog_form_address",true)
},
saveEditAddress(){
this.$store.commit("doctor/update_errors",[])
var errors = this.$store.state.doctor.errors
if(this.labeladdress === ''){
errors.push("requiredlabel")
}
/*if(this.oldlabel.toLowerCase() === 'utama' && this.labeladdress.toLowerCase() !== 'utama'){
errors.push("readonlyutama")
}*/
if(_.isEmpty(this.cityaddress)){
errors.push("requiredcity")
}
if(_.isEmpty(this.districtaddress)){
errors.push("requireddistrict")
}
if(_.isEmpty(this.kelurahanaddress)){
errors.push("requiredkelurahan")
}
if(_.isEmpty(this.$store.state.doctor.jpa_address)){
errors.push("requiredjpa")
}
if(_.isEmpty(this.descriptionaddress)){
errors.push("requireddescription")
}
if(errors.length === 0){
var prm = {}
prm.M_DoctorAddressID = this.$store.state.doctor.x_addr_id
prm.M_DoctorAddressM_DoctorID = this.$store.state.doctor.selected_doctor.M_DoctorID
prm.M_DoctorName = this.$store.state.doctor.selected_doctor.M_DoctorName
prm.M_DoctorAddressNote = this.labeladdress
prm.M_DoctorAddressDescription = this.descriptionaddress
prm.M_DoctorAddressM_KelurahanID = this.kelurahanaddress.M_KelurahanID
prm.M_DoctorAddressNat_JpaID = this.$store.state.doctor.jpa_address.Nat_JpaID
this.$store.dispatch("doctor/saveeditaddress",prm)
//this.$store.dispatch("doctor/saveeditaddress",prm)
}
},
deleteAddress(value){
this.$store.commit("doctor/update_act_addr",'delete')
this.$store.commit("doctor/update_x_addr_id",value.M_DoctorAddressID)
this.$store.commit("doctor/update_errors",[])
this.oldlabel = value.M_DoctorAddressNote
var errors = this.$store.state.doctor.errors
if(value.M_DoctorAddressNote.toLowerCase() === 'utama'){
errors.push("deleteutama")
}
var msg = ''
if(errors.includes("deleteutama")){
msg = "Biarkan yang utama tetap ada"
}
else{
msg = "Yakin, akan menghapus data alamat dokter "+value.M_DoctorAddressNote+" ?"
}
this.$store.commit("doctor/update_msg_confirmation_delete_addr",msg)
this.$store.commit("doctor/update_dialog_confirmation_delete_addr",true)
},
deleteAddressNew(value){
var xaddress_now = this.$store.state.doctor.addresses
var idx = _.findIndex(xaddress_now, function(o) { return o.tmp_id == value.tmp_id})
xaddress_now.splice(idx, 1);
this.$store.commit("doctor/update_addresses",xaddress_now)
},
doDeleteAddr(){
var prm = {}
prm.M_DoctorAddressID = this.$store.state.doctor.x_addr_id
prm.M_DoctorAddressM_DoctorOldCode = this.$store.state.doctor.selected_doctor.M_DoctorOldCode
prm.M_DoctorName = this.$store.state.doctor.selected_doctor.M_DoctorName
prm.M_DoctorAddressNote = this.oldlabel
this.$store.dispatch("doctor/deleteaddress",prm)
}
},
watch: {
search_city(val,old) {
if (val == old ) return
if (! val) return
if (val.length < 1 ) return
if (this.$store.state.doctor.update_autocomplete_status == 1 ) return
this.thr_search_city()
}
}
}
</script>