Index.vue 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <script setup>
  2. import { ref } from 'vue'
  3. import { Inertia } from '@inertiajs/inertia'
  4. import { Head, useForm } from '@inertiajs/inertia-vue3'
  5. import AppButton from '@/components/AppButton.vue'
  6. import AppPagination from '@/components/AppPagination.vue'
  7. import AppMenu from '@/components/AppMenu.vue'
  8. import AppDropdown from '@/components/AppDropdown.vue'
  9. import AppLayout from '@/layouts/AppLayout.vue'
  10. import { IndexTable } from './TableHeader'
  11. const props = defineProps({
  12. transactions: Object,
  13. transactionsStatus: Array,
  14. })
  15. const transactionId = ref()
  16. const updateStatusDialog = ref(false)
  17. const updateStatusForm = useForm({
  18. transaction_status_id: null,
  19. })
  20. const updateStatusSubmit = () => {
  21. updateStatusForm.put(route('transactions.update', transactionId.value), {
  22. onSuccess: () => {
  23. updateStatusDialog.value = false
  24. },
  25. })
  26. }
  27. const updateStatusItems = ref([])
  28. const overlayMenu = ref()
  29. const overlayItems = ref([])
  30. const overlayToggle = (event, data) => {
  31. overlayItems.value =
  32. data.transactionStatusId == 4
  33. ? [
  34. {
  35. label: 'Lihat detail',
  36. icon: 'pi pi-eye',
  37. to: route('transactions.show', data.id),
  38. },
  39. {
  40. label: 'Cetak ulang',
  41. icon: 'pi pi-print',
  42. command() {},
  43. },
  44. ]
  45. : [
  46. {
  47. label: 'Perbaharui status',
  48. icon: 'pi pi-refresh',
  49. command() {
  50. updateStatusDialog.value = true
  51. },
  52. },
  53. {
  54. label: 'Lihat detail',
  55. icon: 'pi pi-eye',
  56. to: route('transactions.show', data.id),
  57. },
  58. {
  59. label: 'Cetak ulang',
  60. icon: 'pi pi-print',
  61. command() {
  62. Inertia.get(`/thermal-printing/${data.transactionNumber}`)
  63. },
  64. },
  65. ]
  66. updateStatusItems.value = props.transactionsStatus.filter((val) => val.value >= data.transactionStatusId)
  67. updateStatusForm.transaction_status_id = data.transactionStatusId
  68. transactionId.value = data.id
  69. overlayMenu.value.toggle(event)
  70. }
  71. </script>
  72. <template>
  73. <Head title="Daftar Transaksi" />
  74. <AppLayout>
  75. <DataTable
  76. responsiveLayout="scroll"
  77. columnResizeMode="expand"
  78. :value="transactions.data"
  79. :rowHover="true"
  80. :stripedRows="true"
  81. >
  82. <template #header>
  83. <div class="grid">
  84. <div class="col-12 md:col-6">
  85. <div class="flex align-items-center">
  86. <h5 class="mr-3 mb-0">Transaksi</h5>
  87. <InputText class="w-full md:w-27rem" placeholder="cari..." />
  88. </div>
  89. </div>
  90. <div class="col-12 md:col-6 flex justify-content-end">
  91. <AppButton
  92. label="Tambah Transaksi"
  93. class="p-button-text"
  94. icon="pi pi-pencil"
  95. :href="route('transactions.create')"
  96. />
  97. </div>
  98. </div>
  99. </template>
  100. <Column
  101. v-for="indexTable in IndexTable"
  102. :field="indexTable.field"
  103. :header="indexTable.header"
  104. :key="indexTable.field"
  105. >
  106. <template #body="{ data, field }">
  107. <template v-if="field === 'transactionStatusName'">
  108. <Badge v-if="data['transactionStatusId'] === 1" :value="data[field]"></Badge>
  109. <Badge v-else-if="data['transactionStatusId'] === 2" :value="data[field]" severity="warning"></Badge>
  110. <Badge v-else :value="data[field]" severity="success"></Badge>
  111. </template>
  112. <template v-else-if="field === 'customer'">
  113. <p class="font-bold">{{ data.customer.number }}</p>
  114. <p>{{ data.customer.name }}</p>
  115. <p>{{ data.customer.phone }}</p>
  116. </template>
  117. <template v-else-if="field === 'transactionNumber'">
  118. <p class="font-bold">{{ data[field] }}</p>
  119. <p>{{ data.dateLaundry }}</p>
  120. </template>
  121. <template v-else>
  122. {{ data[field] }}
  123. </template>
  124. </template>
  125. </Column>
  126. <Column>
  127. <template #body="slotProps">
  128. <Button
  129. icon="pi pi-angle-double-down"
  130. class="p-button-rounded p-button-text"
  131. aria-controls="overlay_menu"
  132. @click="overlayToggle($event, slotProps.data)"
  133. />
  134. <AppMenu id="overlay_menu" ref="overlayMenu" :popup="true" :model="overlayItems" />
  135. </template>
  136. </Column>
  137. </DataTable>
  138. <AppPagination :links="transactions.links" />
  139. <Dialog
  140. modal
  141. v-model:visible="updateStatusDialog"
  142. class="p-fluid"
  143. header="Perbaharui Status"
  144. :style="{ width: '450px' }"
  145. :breakpoints="{ '960px': '75vw' }"
  146. @hide="updateStatusDialog"
  147. >
  148. <div class="grid">
  149. <div class="col-12">
  150. <AppDropdown
  151. label="Perbaharui Status"
  152. placeholder="pilih satu"
  153. v-model="updateStatusForm.transaction_status_id"
  154. :error="updateStatusForm.error"
  155. :options="updateStatusItems"
  156. />
  157. </div>
  158. </div>
  159. <template #footer>
  160. <div class="flex justify-content-end">
  161. <AppButton
  162. label="Simpan"
  163. icon="pi pi-check"
  164. class="p-button-text"
  165. :disabled="updateStatusForm.processing"
  166. @click="updateStatusSubmit"
  167. />
  168. </div>
  169. </template>
  170. </Dialog>
  171. </AppLayout>
  172. </template>