You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

305 rivejä
7.2 KiB

  1. <script>
  2. import Layout from "@/layout/custom.vue";
  3. import ApiServiece from "@/services/ApiService";
  4. import { onMounted, ref, watch, computed } from "vue";
  5. import moment from "jalali-moment";
  6. export default {
  7. name: "PRODUCT-LIST",
  8. components: {
  9. Layout,
  10. },
  11. setup() {
  12. const searchPage = ref();
  13. const currentPage = ref(1);
  14. const totalPages = ref(1);
  15. const paginate = ref(20);
  16. const page = ref(1);
  17. const filterLoading = ref(false);
  18. const allOrders = ref([]);
  19. const getAllOrders = () => {
  20. filterLoading.value = true;
  21. ApiServiece.get(
  22. `admin/orders?paginate=${paginate.value || 10}&page=${page.value || 1}`
  23. )
  24. .then((resp) => {
  25. console.log(resp);
  26. allOrders.value = resp.data.data.data;
  27. currentPage.value = resp.data.data.current_page;
  28. totalPages.value = resp.data.data.last_page;
  29. })
  30. .catch((err) => {
  31. console.log(err);
  32. });
  33. };
  34. const convertToJalali = (date) => {
  35. return moment(date, "YYYY-MM-DD HH:mm:ss")
  36. .locale("fa")
  37. .format("YYYY/MM/DD");
  38. };
  39. const getStatusLabel = (status) => {
  40. const statusLabels = {
  41. waiting: "در انتظار",
  42. paid: "پرداخت‌شده",
  43. un_paid: "پرداخت‌نشده",
  44. approved: "تأیید‌شده",
  45. processing: "در حال پردازش",
  46. shipping: "در حال ارسال",
  47. delivered: "تحویل‌شده",
  48. canceled: "لغو‌شده",
  49. };
  50. return statusLabels[status] || "نامشخص";
  51. };
  52. const visiblePages = computed(() => {
  53. const pages = [];
  54. if (totalPages.value <= 5) {
  55. for (let i = 1; i <= totalPages.value; i++) {
  56. pages.push(i);
  57. }
  58. } else {
  59. let start = currentPage.value - 2;
  60. let end = currentPage.value + 2;
  61. if (start < 1) start = 1;
  62. if (end > totalPages.value) end = totalPages.value;
  63. for (let i = start; i <= end; i++) {
  64. pages.push(i);
  65. }
  66. }
  67. return pages;
  68. });
  69. function handlePageInput() {
  70. if (searchPage.value < 1) {
  71. searchPage.value = 1;
  72. } else if (searchPage.value > totalPages.value) {
  73. searchPage.value = totalPages.value;
  74. }
  75. if (searchPage.value >= 1 && searchPage.value <= totalPages.value) {
  76. page.value = searchPage.value;
  77. }
  78. }
  79. watch(page, () => {
  80. getAllOrders();
  81. });
  82. const nextPage = () => {
  83. if (currentPage.value < totalPages.value) {
  84. page.value++;
  85. getAllOrders();
  86. }
  87. };
  88. const prevPage = () => {
  89. if (currentPage.value > 1) {
  90. page.value--;
  91. getAllOrders();
  92. }
  93. };
  94. onMounted(() => {
  95. getAllOrders();
  96. });
  97. return {
  98. allOrders,
  99. visiblePages,
  100. nextPage,
  101. prevPage,
  102. handlePageInput,
  103. currentPage,
  104. totalPages,
  105. page,
  106. convertToJalali,
  107. searchPage,
  108. getStatusLabel
  109. };
  110. },
  111. };
  112. </script>
  113. <template>
  114. <Layout>
  115. <BRow>
  116. <BCol class="col-sm-12">
  117. <BCard no-body class="table-card">
  118. <BCardBody>
  119. <div class="text-end p-sm-4 pb-sm-2">
  120. <!-- Button to Trigger Export -->
  121. </div>
  122. <div class="table-responsive">
  123. <table class="table table-hover tbl-product" id="pc-dt-simple">
  124. <thead>
  125. <tr>
  126. <th >شناسه</th>
  127. <th>تاریخ ایحاد</th>
  128. <th>کد رهگیری</th>
  129. <th>وضعیت</th>
  130. </tr>
  131. </thead>
  132. <tbody>
  133. <tr v-for="order in allOrders" :key="order?.id">
  134. <td >{{ order?.id }}</td>
  135. <td>{{ convertToJalali(order?.created_at) }}</td>
  136. <td>{{order?.tracking_code}}</td>
  137. <td >{{ order?.status }}</td>
  138. </tr>
  139. </tbody>
  140. </table>
  141. </div>
  142. </BCardBody>
  143. </BCard>
  144. </BCol>
  145. </BRow>
  146. <BRow>
  147. <BCol sm="12">
  148. <div class="d-flex justify-content-center">
  149. <nav aria-label="Page navigation">
  150. <ul class="pagination">
  151. <li class="page-item" :class="{ disabled: currentPage === 1 }">
  152. <span class="page-link" @click="prevPage">قبلی</span>
  153. </li>
  154. <li v-if="currentPage > 2" class="page-item" @click="page = 1">
  155. <a class="page-link" href="javascript:void(0)">1</a>
  156. </li>
  157. <li v-if="currentPage > 3" class="page-item" disabled>
  158. <span class="page-link">...</span>
  159. </li>
  160. <li
  161. v-for="n in visiblePages"
  162. :key="n"
  163. class="page-item"
  164. :class="{ active: currentPage === n }"
  165. >
  166. <a
  167. class="page-link"
  168. href="javascript:void(0)"
  169. @click="page = n"
  170. >
  171. {{ n }}
  172. </a>
  173. </li>
  174. <li
  175. v-if="currentPage < totalPages - 2"
  176. class="page-item"
  177. disabled
  178. >
  179. <span class="page-link">...</span>
  180. </li>
  181. <li
  182. v-if="currentPage < totalPages - 1"
  183. class="page-item"
  184. @click="page = totalPages"
  185. >
  186. <a class="page-link" href="javascript:void(0)">{{
  187. totalPages
  188. }}</a>
  189. </li>
  190. <li
  191. class="page-item"
  192. :class="{ disabled: currentPage === totalPages }"
  193. >
  194. <span class="page-link" @click="nextPage">بعدی</span>
  195. </li>
  196. </ul>
  197. </nav>
  198. </div>
  199. </BCol>
  200. <BCol sm="4">
  201. <div class="ms-0 search-number">
  202. <input
  203. v-model="searchPage"
  204. type="text"
  205. class="form-control"
  206. placeholder="برو به صفحه"
  207. :max="totalPages"
  208. min="1"
  209. @input="handlePageInput"
  210. />
  211. </div>
  212. </BCol>
  213. </BRow>
  214. </Layout>
  215. </template>
  216. <style scoped>
  217. .product-img {
  218. max-width: 48px;
  219. min-width: 48px;
  220. max-height: 45px;
  221. min-height: 45px;
  222. object-fit: cover;
  223. }
  224. .brand-img {
  225. max-width: 43px;
  226. min-width: 43px;
  227. max-height: 40px;
  228. min-height: 40px;
  229. object-fit: cover;
  230. }
  231. .search-number {
  232. display: flex;
  233. align-items: center;
  234. }
  235. .search-number input {
  236. width: 150px;
  237. padding: 0.5rem;
  238. font-size: 1rem;
  239. border-radius: 0.375rem;
  240. margin-bottom: 7px;
  241. border: 1px solid #ced4da;
  242. transition: border-color 0.3s ease, box-shadow 0.3s ease;
  243. }
  244. .search-number input:focus {
  245. border-color: #007bff;
  246. box-shadow: 0 0 0 0.2rem rgba(38, 143, 255, 0.25);
  247. }
  248. .search-number input::placeholder {
  249. color: #6c757d;
  250. }
  251. .search-number input:disabled {
  252. background-color: #f8f9fa;
  253. cursor: not-allowed;
  254. }
  255. .pagination {
  256. display: flex;
  257. flex-wrap: wrap;
  258. gap: 5px;
  259. }
  260. .page-item {
  261. flex: 0 0 auto;
  262. }
  263. .page-link {
  264. cursor: pointer;
  265. user-select: none;
  266. }
  267. </style>