Index.vue 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. initialFilters: Object,
  11. customers: Object,
  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. <AppSearchFilter
  43. placeholder="nama, no hp, npwp"
  44. name-param="search"
  45. :initial-search="initialFilters"
  46. />
  47. </div>
  48. <div
  49. class="col-12 md:col-4 flex flex-column md:flex-row justify-content-end"
  50. >
  51. <AppButtonLink
  52. label="Tambah Pelanggan"
  53. icon="pi pi-pencil"
  54. class="p-button-outlined"
  55. :href="route('customers.create')"
  56. />
  57. </div>
  58. </div>
  59. </template>
  60. <Column
  61. v-for="value in indexTable"
  62. :field="value.field"
  63. :header="value.header"
  64. :key="value.field"
  65. />
  66. <Column>
  67. <template #body="{ data }">
  68. <div class="grid gap-2">
  69. <AppButtonLink
  70. icon="pi pi-list"
  71. class="p-button-icon-only p-button-rounded p-button-text"
  72. v-tooltip.bottom="'History Pembelian'"
  73. :href="route('customers.show', data.id)"
  74. />
  75. <AppButtonLink
  76. icon="pi pi-pencil"
  77. class="p-button-icon-only p-button-rounded p-button-text"
  78. v-tooltip.bottom="'Ubah Pelanggan'"
  79. :href="route('customers.edit', data.id)"
  80. />
  81. <Button
  82. v-if="!data.isUsed"
  83. icon="pi pi-trash"
  84. class="p-button-icon-only p-button-rounded p-button-text"
  85. v-tooltip.bottom="'Hapus Pelanggan'"
  86. @click="onDelete(data)"
  87. />
  88. </div>
  89. </template>
  90. </Column>
  91. </DataTable>
  92. <AppPagination :links="customers.links" />
  93. </DashboardLayout>
  94. </template>