Index.vue 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <script setup>
  2. import { Inertia } from '@inertiajs/inertia'
  3. import { useConfirm } from 'primevue/useconfirm'
  4. import { indexTable } from './config'
  5. import AppSearchFilter from '@/components/AppSearchFilter.vue'
  6. import AppButtonLink from '@/components/AppButtonLink.vue'
  7. import AppPagination from '@/components/AppPagination.vue'
  8. import DashboardLayout from '@/layouts/Dashboard/DashboardLayout.vue'
  9. defineProps({
  10. customers: Object,
  11. initialSearch: String,
  12. })
  13. const deleteConfirm = useConfirm()
  14. const onDelete = (data) => {
  15. deleteConfirm.require({
  16. message: `Yakin akan menghapus data (${data.name}) ?`,
  17. header: 'Hapus Pelanggan',
  18. acceptLabel: 'Iya',
  19. rejectLabel: 'Tidak',
  20. accept: () => {
  21. Inertia.delete(route('customers.destroy', data.id))
  22. },
  23. reject: () => {
  24. deleteConfirm.close()
  25. },
  26. })
  27. }
  28. </script>
  29. <template>
  30. <DashboardLayout title="Daftar Pelanggan">
  31. <DataTable
  32. responsiveLayout="scroll"
  33. columnResizeMode="expand"
  34. :value="customers.data"
  35. :rowHover="true"
  36. :stripedRows="true"
  37. >
  38. <template #header>
  39. <h1>Pelanggan</h1>
  40. <div class="grid">
  41. <div class="col-12 md:col-8">
  42. <div class="flex align-items-center">
  43. <AppSearchFilter
  44. class="w-full md:w-27rem"
  45. placeholder="nama, no hp, npwp"
  46. :initial-search="initialSearch"
  47. />
  48. </div>
  49. </div>
  50. <div
  51. class="col-12 md:col-4 flex flex-column md:flex-row justify-content-end"
  52. >
  53. <AppButtonLink
  54. label="Tambah Pelanggan"
  55. icon="pi pi-pencil"
  56. class="p-button-outlined"
  57. :href="route('customers.create')"
  58. />
  59. </div>
  60. </div>
  61. </template>
  62. <Column
  63. v-for="value in indexTable"
  64. :field="value.field"
  65. :header="value.header"
  66. :key="value.field"
  67. />
  68. <Column>
  69. <template #body="{ data }">
  70. <AppButtonLink
  71. icon="pi pi-pencil"
  72. class="p-button-icon-only p-button-rounded p-button-text"
  73. v-tooltip.bottom="'Ubah Pelanggan'"
  74. :href="route('customers.edit', data.id)"
  75. />
  76. <Button
  77. v-if="!data.isUsed"
  78. icon="pi pi-trash"
  79. class="p-button-icon-only p-button-rounded p-button-text"
  80. v-tooltip.bottom="'Hapus Pelanggan'"
  81. @click="onDelete(data)"
  82. />
  83. </template>
  84. </Column>
  85. </DataTable>
  86. <AppPagination :links="customers.links" />
  87. </DashboardLayout>
  88. </template>