Index.vue 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <script setup>
  2. import { watch, ref } from 'vue'
  3. import { Inertia } from '@inertiajs/inertia'
  4. import { Head, useForm } from '@inertiajs/inertia-vue3'
  5. import throttle from 'lodash/throttle'
  6. import pickBy from 'lodash/pickBy'
  7. import AppButton from '@/components/AppButton.vue'
  8. import AppPagination from '@/components/AppPagination.vue'
  9. import AppLayout from '@/layouts/AppLayout.vue'
  10. import { IndexTable } from './TableHeader'
  11. const props = defineProps({
  12. customers: Object,
  13. filters: Object,
  14. })
  15. const filterForm = useForm({
  16. search: props.filters.search,
  17. })
  18. watch(
  19. filterForm,
  20. throttle(() => {
  21. Inertia.get('/customers', pickBy({ search: filterForm.search }), { preserveState: true })
  22. const params = window.location.search
  23. exportExcelLink.value = `/reports/customers/export/excel${params}`
  24. }, 300)
  25. )
  26. const exportExcelLink = ref('/reports/customers/export/excel')
  27. </script>
  28. <template>
  29. <Head title="Daftar Customer" />
  30. <AppLayout>
  31. <DataTable
  32. responsiveLayout="scroll"
  33. columnResizeMode="expand"
  34. :value="customers.data"
  35. :rowHover="true"
  36. :stripedRows="true"
  37. >
  38. <template #header>
  39. <h1>Customer</h1>
  40. <div class="grid">
  41. <div class="col-12 md:col-8">
  42. <div class="grid">
  43. <div class="col-12 md:col-3">
  44. <InputText class="w-full" placeholder="cari..." v-model="filterForm.search" />
  45. </div>
  46. <div v-if="customers.data" class="col-12 md:col-3">
  47. <AppButton
  48. label="Export excel"
  49. class-button="p-button-outlined w-full md:w-16rem"
  50. icon="pi pi-file-excel"
  51. :inertia-link="false"
  52. :href="exportExcelLink"
  53. />
  54. </div>
  55. </div>
  56. </div>
  57. <div class="col-12 md:col-4 flex flex-column md:flex-row justify-content-end">
  58. <AppButton
  59. :href="route('customers.create')"
  60. label="Tambah Customer"
  61. icon="pi pi-pencil"
  62. class="p-button-outlined"
  63. />
  64. </div>
  65. </div>
  66. </template>
  67. <Column
  68. v-for="indexTable in IndexTable"
  69. :field="indexTable.field"
  70. :header="indexTable.header"
  71. :key="indexTable.field"
  72. />
  73. <Column>
  74. <template #body="{ data }">
  75. <AppButton
  76. icon="pi pi-angle-double-right"
  77. class="p-button-icon-only p-button-rounded p-button-text"
  78. :href="route('customers.edit', data.id)"
  79. />
  80. </template>
  81. </Column>
  82. </DataTable>
  83. <AppPagination :links="customers.links" />
  84. </AppLayout>
  85. </template>