diff --git a/resources/js/components/util/BlacklistModal.vue b/resources/js/components/util/BlacklistModal.vue index 654bc61..d32aec5 100644 --- a/resources/js/components/util/BlacklistModal.vue +++ b/resources/js/components/util/BlacklistModal.vue @@ -115,12 +115,19 @@ export default { }, methods: { toggleModal: function(){ - this.showModal = !this.showModal; - this.arrayCustomer = []; - this.specCust = []; + + this.showModal = !this.showModal; + + this.arrayCustomer = []; + this.specCust = {}; + this.nota = ''; + + if(this.$refs.btnDropdownRef){ + this.$refs.btnDropdownRef.value = ''; + } }, async toggleDropdown() { - + this.specCust = {}; await this.getData() if(this.arrayCustomer.length > 0) @@ -137,42 +144,52 @@ export default { } }, - getData: function() { + async getData() { let inputvalue = document.getElementById("frminput").value; - if(inputvalue) + if(!inputvalue) { - if(this.hasNumber(inputvalue)) - { - this.axios.get(this.$api1 + '/admin/searchByIC', { - params: { - ic: inputvalue, - kodcaw: this.$kodcaw - } - }).then(response => { - this.arrayCustomer = response.data + this.arrayCustomer = []; + return; + } - }).catch(error => { - console.log(error) - }) + try { - + let response; - }else{ - this.axios.get(this.$api1 + '/admin/searchByName', { - params: { - nama: inputvalue, - kodcaw: this.$kodcaw + if (this.hasNumber(inputvalue)) { + + response = await this.axios.get( + this.$api1 + '/admin/searchByIC', + { + params: { + ic: inputvalue, + kodcaw: this.$kodcaw + } + } + ); + + } else { + + response = await this.axios.get( + this.$api1 + '/admin/searchByName', + { + params: { + nama: inputvalue, + kodcaw: this.$kodcaw + } + } + ); } - }).then(response => { - this.arrayCustomer = response.data - }).catch(error => { - console.log(error) - }) - } + this.arrayCustomer = response.data || []; + + } catch (error) { + + console.log(error); + this.arrayCustomer = []; } }, @@ -221,6 +238,13 @@ export default { }, kemaskinifunc: function(){ + if (!this.specCust || !this.specCust.id) { + this.$toast.error( + "Sila pilih pelanggan daripada senarai carian terlebih dahulu." + ); + return; + } + axios.post(this.$hostname + '/admin/AddSenaraiHitam', { kodcaw: this.$kodcaw, @@ -229,19 +253,18 @@ export default { }).then(response => { - if(response.data == 'berjaya') + if(response.data && response.data.id) { this.showModal = false; - this.$toast.success("Kemaskini Sudah Berjaya!") + this.$toast.success("Kemaskini Sudah Berjaya!"); // vm.$forceUpdate(); - this.$emit('clickEvent_', this.pageNumber) - + this.$emit('clickEvent_', this.pageNumber); // setTimeout("window.location.reload()", 3000); }else{ this.showModal = false; - this.$toast.error("Kemaskini tidak berjaya") + this.$toast.error("Kemaskini tidak berjaya"); } });