diff --git a/src/views/DepartemenIndex.vue b/src/views/DepartemenIndex.vue index 8442c4bc9f497359dc583178c8af2e1b02442c36..c972ef043931dc745b1e6613325b3e916fff3b6d 100644 --- a/src/views/DepartemenIndex.vue +++ b/src/views/DepartemenIndex.vue @@ -114,21 +114,23 @@ export default { isModalVisible: false, deptnameadd:"", deptnameedit:"", + curr_id:"", + //name:"", dept: [], - temp_dept: [ - { - id: 1, - nama: "Keuangan", - }, - { - id: 2, - nama: "Marketing", - }, - { - id: 3, - nama: "Operasional", - }, - ], + // temp_dept: [ + // { + // id: 1, + // nama: "Keuangan", + // }, + // { + // id: 2, + // nama: "Marketing", + // }, + // { + // id: 3, + // nama: "Operasional", + // }, + // ], columns: { Id : { name : "Id", @@ -173,15 +175,35 @@ export default { insert(e){ e.preventDefault(); let formValue = this.deptnameadd - console.log(formValue) - alert("Dept berhasil ditambahkan") - document.getElementById("formAddDept").reset(); + //console.log(formValue) + let data = { + name: formValue + } + console.log(data.name) + + HTTP.put("departments", data, { + headers:{ + 'Content-Type': 'application/json' + } + }).then((res)=>{ + if (res.status == 200){ + alert("Departemen berhasil ditambahkan") + this.closeModal() + //document.getElementById("formAddDept").reset(); + } + }).catch(()=>{ + alert("Gagal menambahkan Departemen") + }) + + + + //alert("Dept berhasil ditambahkan") + //document.getElementById("formAddDept").reset(); }, // addDept(data){ // console.log(data); // }, getDept() { - // di sini ambil data admin dari database HTTP.get("departments").then((res)=>{ if (res.data.success == true){ this.dept = res.data.data @@ -191,56 +213,61 @@ export default { console.log(id); }, deleteDept(id) { - console.log(id); + //console.log(id) //aman + if (confirm("Yakin akan menghapus Departemen?")){ + HTTP.delete(`departments/${id}`).then((res) =>{ + if (res.status == 200){ + alert("Berhasil menghapus Departemen") + this.getDept() + } + }).catch( () => { + alert("Gagal Menghapus Departemen") + } + ) + } }, edit(e){ e.preventDefault(); - - //let prevDept = this.temp_dept[parseInt(id)-1] - //console.log(prevDept.nama) - //get data from form let formValue = this.deptnameedit - console.log(formValue) - console.log(typeof formValue) //udah jalan sampe sini - //console.log(id) //id undefined - //console.log(this.id) //undefined - - //this.temp_dept[parseInt(this.id)-1].nama = formValue - - // methods: { - // // ... - // fillData(selected){ - // this.datacollection.datasets[0].label = selected; - // }, + let data = { + name: formValue + } + HTTP.put(`departments/${this.curr_id}`, data, { + headers: { + 'Content-Type': 'application/json' + } + }).then((res)=>{ + if (res.status == 200){ + alert("Departemen berhasil diedit") + this.closeModal() + //document.getElementById("formEditDept").reset() + } + }).catch(() => alert("Gagal mengedit Departemen")) - // let prevDept = this.temp_dept[parseInt(id)-1].nama - // prevDept = formValue - // console.log(prevDept) + //alert("Dept berhasil diedit") - alert("Dept berhasil diedit") + //document.getElementById("formEditDept").reset() - document.getElementById("formEditDept").reset(); + ; }, editDept(id) { - //console.log(id); + console.log(id); this.showModal("editDept"); //get data - let dept = this.temp_dept[parseInt(id)-1] - this.deptnameedit = dept.nama - //console.log(this.deptnameedit) - - //change data - - + HTTP.get(`departments/${id}`).then((res)=>{ + if (res.status == 200){ + this.deptnameedit = res.data.data.name + } + } + ) + //this.getDept(); + this.curr_id = id; }, - // updateDept(event){ - // console.log(event); - // } }, mounted() { this.getDept();