123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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. },
  63. ];
  64. updateStatusItems.value = props.transactionsStatus.filter(
  65. (val) => val.value >= data.transactionStatusId
  66. );
  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
  109. v-if="data['transactionStatusId'] === 1"
  110. :value="data[field]"
  111. ></Badge>
  112. <Badge
  113. v-else-if="data['transactionStatusId'] === 2"
  114. :value="data[field]"
  115. severity="warning"
  116. ></Badge>
  117. <Badge v-else :value="data[field]" severity="success"></Badge>
  118. </template>
  119. <template v-else-if="field === 'customer'">
  120. <p class="font-bold">{{ data.customer.number }}</p>
  121. <p>{{ data.customer.name }}</p>
  122. <p>{{ data.customer.phone }}</p>
  123. </template>
  124. <template v-else-if="field === 'transactionNumber'">
  125. <p class="font-bold">{{ data[field] }}</p>
  126. <p>{{ data.dateLaundry }}</p>
  127. </template>
  128. <template v-else>
  129. {{ data[field] }}
  130. </template>
  131. </template>
  132. </Column>
  133. <Column>
  134. <template #body="slotProps">
  135. <Button
  136. icon="pi pi-angle-double-down"
  137. class="p-button-rounded p-button-text"
  138. aria-controls="overlay_menu"
  139. @click="overlayToggle($event, slotProps.data)"
  140. />
  141. <AppMenu
  142. id="overlay_menu"
  143. ref="overlayMenu"
  144. :popup="true"
  145. :model="overlayItems"
  146. />
  147. </template>
  148. </Column>
  149. </DataTable>
  150. <AppPagination :links="transactions.links" />
  151. <Dialog
  152. modal
  153. v-model:visible="updateStatusDialog"
  154. class="p-fluid"
  155. header="Perbaharui Status"
  156. :style="{ width: '450px' }"
  157. :breakpoints="{ '960px': '75vw' }"
  158. @hide="updateStatusDialog"
  159. >
  160. <div class="grid">
  161. <div class="col-12">
  162. <AppDropdown
  163. label="Perbaharui Status"
  164. placeholder="pilih satu"
  165. v-model="updateStatusForm.transaction_status_id"
  166. :error="updateStatusForm.error"
  167. :options="updateStatusItems"
  168. />
  169. </div>
  170. </div>
  171. <template #footer>
  172. <div class="flex justify-content-end">
  173. <AppButton
  174. label="Simpan"
  175. icon="pi pi-check"
  176. class="p-button-text"
  177. :disabled="updateStatusForm.processing"
  178. @click="updateStatusSubmit"
  179. />
  180. </div>
  181. </template>
  182. </Dialog>
  183. </AppLayout>
  184. </template>