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.

287 lines
9.2 KiB

2 years ago
  1. <template>
  2. <div>
  3. <Swiper class="swiper tw-mb-[15px] md:tw-mb-[30px]" :options="swiperOption" @click="slideClicked">
  4. <SwiperSlide v-for="(item, index) in bookingType" :key="index"
  5. :class="['tw-transition-all tw-delay-75 tw-ease-in-out',currentType === item
  6. ? 'tw-flex tw-justify-center tw-py-[13px] tw-border-b-2 tw-border-solid tw-border-0 tw-border-primary-1 tw-text-primary-1 tw-cursor-pointer'
  7. : 'tw-flex tw-justify-center tw-py-[13px] hover:tw-border-b-2 tw-border-solid tw-border-0 tw-border-transparent hover:tw-text-primary-1 tw-cursor-pointer']">
  8. {{ item }}
  9. </SwiperSlide>
  10. </Swiper>
  11. <h4 class="t14 tw-font-bold md:t16 tw-mb-[10px]">{{ $t("Filter") }}</h4>
  12. <div class="element tw-w-fit md:tw-w-fit tw-mb-[15px] md:tw-mb-[30px]">
  13. <ElementSelect :select="{
  14. required: false,
  15. }" :selectList="categoryList" :default="0" :defaultOptionMsg="$t('All Categories')" @change="updateCategory">
  16. </ElementSelect>
  17. </div>
  18. <UserServiceItem v-for="(item, index) in renderList" :key="index" :info="item" @contact-us="activeContactUs"
  19. @upload-remittance-slip="activeUploadSlip"></UserServiceItem>
  20. <div v-if="renderList.length < 1 && searchQuery.length < 0" class="tw-mt-[5px] tw-mb-[60px]">
  21. <div class="tw-flex tw-justify-center tw-mt-[60px] tw-mb-[30px]">
  22. <img :src="emptyImg" alt="" class="tw-h-[142px] tw-w-[160px]" />
  23. </div>
  24. <div class="tw-text-center tw-body-3 tw-text-neutrals-800 tw-mb-[30px]">
  25. {{
  26. currentType === "All"
  27. ? $t(`No Bookings yet ...`)
  28. : $t(`You don't have any ${currentType} bookings`)
  29. }}
  30. </div>
  31. <div class="tw-flex tw-justify-center tw-mb-[30px]">
  32. <button
  33. class="tw-transition tw-justify-center tw-items-center tw-btn-md tw-text-white tw-bg-primary-1 tw-px-[30px] tw-py-[8.5px] tw-rounded-xl tw-w-fit tw-h-fit">
  34. {{ $t("Explore with ShowEasy") }}
  35. </button>
  36. </div>
  37. </div>
  38. <div v-if="renderList.length < 1 && searchQuery.length > 0"
  39. class="tw-mb-[60px] tw-py-[60px] tw-pl-[10px] md:tw-body-2">
  40. {{ $t("Sorry, we couldn't find anything for ") + searchQuery }}
  41. </div>
  42. <div class="tw-flex tw-justify-end" v-if="renderList.length > 0">
  43. <pagination :pageLength="pageLength" @update="updateCurrentPage"></pagination>
  44. </div>
  45. <ContactUsModal :ContactUs="contactUs"></ContactUsModal>
  46. <UploadRemittanceSlipModal></UploadRemittanceSlipModal>
  47. </div>
  48. </template>
  49. <script>
  50. import ElementSelect from "@/components/user/userSelect.vue";
  51. import UserServiceItem from "./userServiceItem.vue";
  52. import pagination from "@/components/newComponent/pagination/pagination.vue";
  53. import ContactUsModal from "@/components/booking/Modal/ContactUsModal.vue";
  54. import UploadRemittanceSlipModal from "@/components/booking/Modal/UploadRemittanceSlipModal.vue";
  55. import { Swiper, SwiperSlide } from "vue-awesome-swiper";
  56. export default {
  57. components: {
  58. ElementSelect,
  59. UserServiceItem,
  60. Swiper,
  61. SwiperSlide,
  62. pagination,
  63. ContactUsModal,
  64. UploadRemittanceSlipModal,
  65. },
  66. props: {
  67. searchQuery: {
  68. type: String,
  69. },
  70. width: {
  71. type: Number
  72. }
  73. },
  74. data() {
  75. return {
  76. apiUrl: process.env.SERVICE_CONSOLE,
  77. bookingType: [
  78. this.$t("booking.All"),
  79. this.$t("booking.Unpaid"),
  80. this.$t("booking.Processing"),
  81. this.$t("booking.Completed"),
  82. this.$t("booking.Cancelled"),
  83. ],
  84. previewImage:[],
  85. currentType: "All",
  86. filterList: ["All categories"],
  87. categoryList: [],
  88. categories: [],
  89. emptyImg: require("~/assets/img/companyEmpty.png"),
  90. contactUs: {
  91. Phone: "info@showeasy.com",
  92. Mail: "+886-2-2725-5000",
  93. },
  94. swiperOption: {
  95. slidesPerView: 3,
  96. breakpoints: {
  97. 768: {
  98. slidesPerView: 5,
  99. },
  100. },
  101. },
  102. apiEndPoint: process.env.SERVICE_CONSOLE,
  103. perPageItems: 6,
  104. currentPage: 1,
  105. selectedCategory: 0,
  106. bookingList: [],
  107. };
  108. },
  109. mounted() {
  110. this.getUserOrderList();
  111. this.fetchCategory();
  112. },
  113. // watch: {
  114. // searchQuery: {
  115. // handler: function () {
  116. // this.
  117. // },
  118. // },
  119. // },
  120. computed: {
  121. bookingFilter() {
  122. const categoryList = this.filterByCategory(
  123. this.bookingList,
  124. this.selectedCategory
  125. );
  126. const tabList = this.filterByTab(categoryList, this.currentType);
  127. const searchList = this.filterByQuery(tabList, this.searchQuery);
  128. return searchList;
  129. },
  130. renderList() {
  131. for (let i in this.bookingList) {
  132. this.getServiceData(this.bookingList[i],i);
  133. }
  134. return this.sliceRenderList(this.bookingFilter);
  135. },
  136. result() {
  137. return this.bookingFilter.length;
  138. },
  139. pageLength() {
  140. return Math.ceil(this.result / this.perPageItems);
  141. },
  142. },
  143. methods: {
  144. slideClicked(swiper) {
  145. this.currentType = this.bookingType[swiper.clickedIndex];
  146. },
  147. activeContactUs() {
  148. this.$modal.show("ContactUs");
  149. },
  150. activeUploadSlip() {
  151. this.$modal.show("UploadRemittanceSlip");
  152. },
  153. fetchCategory() {
  154. this.$axios
  155. .get(
  156. `${this.apiEndPoint}/services-category?lang_code=${this.$i18n.localeProperties["langQuery"]}`
  157. )
  158. .then((result) => {
  159. this.categories = result.data;
  160. this.categories = this.categories.map((item) => {
  161. return {
  162. id: item.ids["0"],
  163. name: item.lang_text,
  164. };
  165. });
  166. this.categories.splice(0, 0, null);
  167. this.getCategoryList();
  168. })
  169. .catch((err) => {
  170. console.log(err);
  171. });
  172. },
  173. getCategoryList() {
  174. const userCategory = [
  175. ...new Set(
  176. this.bookingList.map((item) => {
  177. return item.categoryId;
  178. })
  179. ),
  180. ];
  181. this.bookingList = this.bookingList.map((item) => {
  182. item.categoryName =(this.categories[item.categoryId] && this.categories[item.categoryId].name ) ? this.categories[item.categoryId].name : "";
  183. return item;
  184. });
  185. for (const index of userCategory) {
  186. this.categoryList.push(this.categories[index]);
  187. }
  188. },
  189. updateCategory(categoryId) {
  190. this.selectedCategory = Number(categoryId);
  191. },
  192. filterByCategory(data, categoryId) {
  193. if (categoryId === 0) return data;
  194. return data.filter((item) => item.categoryId === categoryId);
  195. },
  196. filterByTab(data, type) {
  197. switch (type) {
  198. case "All":
  199. this.currentPage = 1;
  200. return data;
  201. case "Unpaid":
  202. this.currentPage = 1;
  203. return data.filter((item) => item.order_payment[item.order_payment.length-1].payment_status === 0);
  204. case "Completed":
  205. this.currentPage = 1;
  206. return data.filter((item) => item.order_payment[item.order_payment.length-1].payment_status === 2);
  207. case "Cancelled":
  208. this.currentPage = 1;
  209. return data.filter((item) => item.order_payment[item.order_payment.length-1].payment_status === -1);
  210. case "Processing":
  211. this.currentPage = 1;
  212. return data.filter(
  213. (item) =>
  214. item.order_payment[item.order_payment.length-1].payment_status !== -1 &&
  215. item.order_payment[item.order_payment.length-1].payment_status !== 2 &&
  216. item.order_payment[item.order_payment.length-1].payment_status !== 0
  217. );
  218. default:
  219. return data;
  220. }
  221. },
  222. updateCurrentPage(value) {
  223. this.currentPage = value;
  224. },
  225. sliceRenderList(data) {
  226. return data.slice(
  227. (this.currentPage - 1) * this.perPageItems,
  228. this.currentPage * this.perPageItems
  229. );
  230. },
  231. filterByQuery(data, query) {
  232. if (query.length < 1) return data;
  233. return data.filter((item) => {
  234. return (
  235. item.service_name.toLowerCase().includes(query.toLowerCase()) ||
  236. item.order_display_id.toLowerCase().includes(query.toLowerCase()) ||
  237. item.partnerName.toLowerCase().includes(query.toLowerCase()) ||
  238. item.categoryName.toLowerCase().includes(query.toLowerCase())
  239. );
  240. });
  241. },
  242. async getUserOrderList() {
  243. this.$axios
  244. .get(
  245. `/order?jwt=${this.$auth.$storage.getUniversal("jwt").token}`
  246. )
  247. .then(async (response) => {
  248. this.bookingList = response.data;
  249. })
  250. .catch((error) => console.log(error));
  251. },
  252. async getServiceData(object,i) {
  253. this.$axios
  254. .get(
  255. `${this.apiUrl}/user-services/content?service_id=${object.service_id}&lang_code=${this.$i18n.localeProperties["langQuery"]}&currency=${object.currency}`
  256. )
  257. .then((res) => {
  258. this.bookingList[i].preview_image = res.data.preview_image
  259. })
  260. .catch((error) => console.log(error));
  261. },
  262. },
  263. };
  264. </script>
  265. <style lang="scss" scoped>
  266. ::-webkit-scrollbar {
  267. display: none;
  268. }
  269. :deep() {
  270. // .v-pagination__navigation{
  271. // background-color: #e5e5e5;
  272. // }
  273. .v-pagination>li>.v-pagination__item {
  274. background-color: inherit;
  275. }
  276. .v-pagination__navigation {
  277. background-color: inherit !important;
  278. }
  279. .v-pagination__navigation--disabled {
  280. opacity: 0;
  281. }
  282. }
  283. </style>