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.

484 lines
16 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. <template>
  2. <div
  3. class="tw-px-[30px] tw-mt-[30px] tw-mb-[60px] md:tw-mb-[100px] xl:tw-px-[60px] xl:tw-max-w-screen-xl xl:tw-mx-auto xl:tw-grid xl:tw-grid-cols-[380px_auto] xl:tw-gap-[30px]">
  4. <section class="xl:tw-col-span-2 tw-mb-[36px] md:tw-mb-[24px] lg:tw-mb-[34px]">
  5. <Breadcrumbs></Breadcrumbs>
  6. <sort :results="result" :sortType="sortType" :sortBy="sortBy" @sort="updateSortBy($event)"
  7. @filter="$modal.show(`sidebar-filter-modal`)"></sort>
  8. </section>
  9. <section class="tw-grid tw-grid-cols-1 tw-gap-[30px] tw-auto-rows-min">
  10. <div v-if="$vuetify.breakpoint.xl">
  11. <multipleLevel :label="'Categories'" :placeholder="$t('Find category/subcategory ...')" :list="categoryList" :queryItem="categoryQueryFilter"
  12. @update="updateCategoryFilter"></multipleLevel>
  13. </div>
  14. <div v-if="$vuetify.breakpoint.xl">
  15. <multipleLevel :label="'Location'" :placeholder="$t('Find country/city ...')" :list="locationList"
  16. :queryItem="locationQueryFilter" @update="updateLocationFilter"></multipleLevel>
  17. </div>
  18. <div v-if="$vuetify.breakpoint.xl">
  19. <price :max="maxPrice" :currentValue="priceRangeFilter" @update="updatePriceRange"></price>
  20. </div>
  21. <div v-if="$vuetify.breakpoint.xl">
  22. <!-- <rating @update="updateRatingRange"></rating> -->
  23. </div>
  24. </section>
  25. <section class="">
  26. <ServiceListCard class="tw-mb-[30px]" v-for="(item, index) in serviceList" :key="index" :service="item">
  27. </ServiceListCard>
  28. <div class="tw-mt-[34px] tw-flex tw-justify-end">
  29. <pagination :pageLength="pageLength" @update="updateCurrentPage"></pagination>
  30. </div>
  31. </section>
  32. <div v-if="!$vuetify.breakpoint.xl">
  33. <sidebarFilterModal :max="maxPrice" :locationList="locationList"
  34. :locationChecked="locationNameFilter" :categoryChecked="categoryFilter" :priceChecked="priceRangeFilter"
  35. @updatePriceRange="updatePriceRange" @updateCategoryFilter="updateCategoryFilter"
  36. @updateLocationFilter="updateLocationFilter"></sidebarFilterModal>
  37. </div>
  38. <loading :isLoading="isPageLoading"></loading>
  39. </div>
  40. </template>
  41. <script>
  42. import Breadcrumbs from "@/components/Breadcrumbs";
  43. import sort from "@/components/newComponent/sort/sort";
  44. import oneLevel from "@/components/newComponent/filter/oneLevel";
  45. import multipleLevel from "@/components/newComponent/filter/multipleLevel";
  46. import price from "@/components/newComponent/filter/price";
  47. import rating from "@/components/newComponent/filter/rating.vue";
  48. import pagination from "@/components/newComponent/pagination/pagination.vue";
  49. import sidebarFilterModal from "@/components/newComponent/modal/sidebarFilterModal.vue";
  50. import ServiceListCard from "@/components/service/ServiceListCard";
  51. import loading from "@/components/newComponent/loading/loading.vue";
  52. export default {
  53. name: "ServiceList",
  54. auth: false,
  55. components: {
  56. Breadcrumbs,
  57. sort,
  58. oneLevel,
  59. multipleLevel,
  60. price,
  61. rating,
  62. sidebarFilterModal,
  63. ServiceListCard,
  64. pagination,
  65. loading,
  66. },
  67. meta: {
  68. pageName: "Service List",
  69. },
  70. data() {
  71. return {
  72. renderList: [],
  73. serviceList: [],
  74. sortType: [
  75. // { name: "Ratings", value: "Ratings" },
  76. // { name: "ShowEasy Recommended", value: "ShowEasy Recommended" },
  77. { name: "Popularity", value: "Popularity" },
  78. { name: "Price (Low to High)", value: "Price" },
  79. { name: "Recently Added", value: "Recently Added" },
  80. ],
  81. locationList: [],
  82. categoryList: [],
  83. // regionNameList: ['123'],
  84. countryNameList: ['Asia','Asia1'],
  85. cityNameList: ['Taiwan','Taiwan1'],
  86. categoryNameList: ['Rental cars','Rental cars1'],
  87. subcategoryNameList: ['子類1'],
  88. sortBy: "CreateDate",
  89. maxPrice: 100,
  90. priceRangeFilter: [0,100],
  91. ratingRangeFilter: [0, 5],
  92. locationNameFilter: ['Asia','Taiwan'],
  93. categoryFilter: ['Rental cars','Rental cars1'],
  94. perPageItems: 10,
  95. currentPage: 1,
  96. total: 0,
  97. locationQueryFilter: "",
  98. categoryQueryFilter: "",
  99. isPageLoading: false,
  100. mainCategoryMap: new Map(),
  101. subCategoryMap: new Map(),
  102. mainLocationMap: new Map(),
  103. subLocationMap: new Map(),
  104. subLocationMap2: new Map(),
  105. mainCategoryQuery: '',
  106. subCategoryQuery: '',
  107. };
  108. },
  109. async created() {
  110. this.isPageLoading = true;
  111. await this.getQuery();
  112. await this.getServiceList();
  113. await this.getCategoryList();
  114. await this.getLocationList();
  115. await this.getPriceRange();
  116. this.isPageLoading = false;
  117. // this.renderList = this.sliceRenderList(this.serviceFilter);
  118. },
  119. mounted() { },
  120. computed: {
  121. // serviceFilter() {
  122. // var vm = this;
  123. // if (Array.isArray(vm.serviceList)) {
  124. // let priceList = vm.filterByPrice(
  125. // vm.serviceList,
  126. // vm.priceRangeFilter[0],
  127. // vm.priceRangeFilter[1]
  128. // );
  129. // priceList = priceList == undefined ? [] : priceList;
  130. // let locationList = vm.filterByLocation(
  131. // priceList,
  132. // vm.locationNameFilter
  133. // );
  134. // locationList = locationList == undefined ? [] : locationList;
  135. // let categoryList = vm.filterByCategory(
  136. // locationList,
  137. // vm.categoryFilter
  138. // );
  139. // categoryList = categoryList == undefined ? [] : categoryList;
  140. // if(categoryList.length<1){
  141. // return [];
  142. // }
  143. // let sortedList = vm.sortServiceList(categoryList);
  144. // return sortedList;
  145. // } else {
  146. // return [];
  147. // }
  148. // },
  149. result() {
  150. return this.total;
  151. },
  152. pageLength() {
  153. return Math.ceil(this.result / this.perPageItems);
  154. },
  155. // renderList() {
  156. // let arr = this.sliceRenderList(this.serviceFilter);
  157. // return arr;
  158. // },
  159. currency() {
  160. return this.$store.getters.getCurrency;
  161. },
  162. },
  163. watch: {
  164. currency: {
  165. handler: async function (newVal, oldVal) {
  166. let vm = this;
  167. if (newVal !== oldVal) {
  168. await vm.getServiceList();
  169. // let data =await vm.mapServiceLocationName(
  170. // vm.serviceList,
  171. // vm.countryNameList,
  172. // vm.cityNameList
  173. // );
  174. // vm.serviceList = data == undefined ? [] : data;
  175. // vm.serviceList =await vm.mapServiceCategoryName(
  176. // vm.serviceList,
  177. // vm.categoryNameList
  178. // );
  179. // vm.serviceList = data == undefined ? [] : data;
  180. // vm.renderList =await vm.serviceList;
  181. await vm.getPriceRange();0
  182. vm.isPageLoading = false;
  183. }
  184. },
  185. },
  186. $route: {
  187. handler: function () {
  188. this.getQuery();
  189. },
  190. },
  191. },
  192. methods: {
  193. async getServiceList() {
  194. let vm = this;
  195. let keyword = "";
  196. let category = "";
  197. let subcatg = "";
  198. if (this.$route.query.q) {
  199. keyword = "&keyword=" + this.$route.query.q;
  200. }
  201. if (this.$route.query.category) {
  202. category = "&category=" + this.$route.query.category;
  203. }
  204. if (this.$route.query.subcatg) {
  205. subcatg = "&subcatg=" + this.$route.query.subcatg;
  206. }
  207. await this.$axios.get(`/trending/api/Onsite/ServiceLists?Lang=${this.$i18n.localeProperties["langQuery"]}&PageIndex=${this.currentPage}
  208. &PageSize=${this.perPageItems}&SortField=CreateDate&sortOrder=desc`).then((response) => {
  209. if(response && response.data && response.data.DATA && response.data.DATA.rel){
  210. let data = response.data.DATA.rel
  211. if(data.DataList.length>0){
  212. this.total = data.Total;
  213. this.serviceList = data.DataList;
  214. }
  215. }
  216. })
  217. .catch((err) => {
  218. console.log(err);
  219. });
  220. },
  221. async getCategoryList() {
  222. await this.$axios
  223. .get(`/trending/api/Onsite/Categories?Lang=${this.$i18n.localeProperties["langQuery"]}`)
  224. .then((response) => {
  225. if(response && response.data && response.data.DATA && response.data.DATA.rel){
  226. let data = response.data.DATA.rel
  227. if(data.length>0){
  228. this.categoryList = data.map((item) => {
  229. this.mainCategoryMap.set(item.CategoryID, item);
  230. if(item.SubCategoryList && item.SubCategoryList.length>0){
  231. item.SubCategoryList = item.SubCategoryList.map(
  232. (children) => {
  233. this.subCategoryMap.set(children.CategoryID, children);
  234. return {
  235. title: children.CategoryName,
  236. key: children.CategoryID,
  237. };
  238. }
  239. );
  240. }else{
  241. item.SubCategoryList = [];
  242. }
  243. return {
  244. title: item.CategoryName,
  245. key: item.CategoryID,
  246. children: item.SubCategoryList,
  247. };
  248. });
  249. }
  250. }
  251. })
  252. .catch((error) =>
  253. console.log(error)
  254. );
  255. },
  256. async getLocationList() {
  257. await this.$axios
  258. .get(`/trending/api/Onsite/Locations?Lang=${this.$i18n.localeProperties["langQuery"]}`)
  259. .then((response) => {
  260. if(response && response.data && response.data.DATA && response.data.DATA.rel){
  261. let data = response.data.DATA.rel
  262. if(data.length>0){
  263. // this.locationList = data;
  264. this.locationList = data.map((item) => {
  265. this.mainLocationMap.set(item.RegionID, item);
  266. if(item.CountryList && item.CountryList.length>0){
  267. item.CountryList = item.CountryList.map(
  268. (children) => {
  269. this.subLocationMap.set(children.CountryID, children);
  270. if(children.CityList && children.CityList.length>0){
  271. children.CityList = children.CityList.map(
  272. (children2) => {
  273. this.subLocationMap2.set(children2.CityID, children2);
  274. return {
  275. title: children2.CityName,
  276. key: children2.CityID,
  277. };
  278. }
  279. );
  280. }else{
  281. children.CityList = [];
  282. }
  283. return {
  284. title: children.CountryName,
  285. key: children.CountryID,
  286. children: children.CityList,
  287. };
  288. }
  289. );
  290. }else{
  291. item.CountryList = [];
  292. }
  293. return {
  294. title: item.RegionName,
  295. key: item.RegionID,
  296. children: item.CountryList,
  297. };
  298. });
  299. }
  300. }
  301. })
  302. .catch((error) =>
  303. console.log(error)
  304. );
  305. },
  306. updateSortBy(data) {
  307. this.sortBy = data;
  308. console.log("排序:"+this.sortBy);
  309. this.getServiceList();
  310. },
  311. // sortServiceList(data) {
  312. // switch (this.sortBy) {
  313. // // case "Ratings":
  314. // // function Ratings(a, b) {
  315. // // if (Number(a.rating) < Number(b.rating)) return 1;
  316. // // if (Number(a.rating) > Number(b.rating)) return -1;
  317. // // return 0;
  318. // // }
  319. // // return data.sort(Ratings);
  320. // // case "ShowEasy Recommended":
  321. // // return data;
  322. // case "Popularity":
  323. // function Views(a, b) {
  324. // if (Number(a.view_counts) < Number(b.view_counts)) return 1;
  325. // if (Number(a.view_counts) > Number(b.view_counts)) return -1;
  326. // return 0;
  327. // }
  328. // return data.sort(Views);
  329. // case "Price":
  330. // function Price(a, b) {
  331. // if (Number(a.price) < Number(b.price)) return -1;
  332. // if (Number(a.price) > Number(b.price)) return 1;
  333. // return 0;
  334. // }
  335. // return data.sort(Price);
  336. // case "Recently Added":
  337. // function Date(a, b) {
  338. // if (
  339. // a.launch_dates[0].replace(/-/g, "") <
  340. // b.launch_dates[0].replace(/-/g, "")
  341. // )
  342. // return 1;
  343. // if (
  344. // a.launch_dates[0].replace(/-/g, "") >
  345. // b.launch_dates[0].replace(/-/g, "")
  346. // )
  347. // return -1;
  348. // return 0;
  349. // }
  350. // return data.sort(Date);
  351. // default:
  352. // return data;
  353. // }
  354. // },
  355. mapSavedService(data, savedList) {
  356. return data.map((item) => {
  357. item.liked = false;
  358. if (savedList.includes(item.id)) {
  359. item.liked = true;
  360. }
  361. return item;
  362. });
  363. },
  364. mapServiceLocationName(data, countryList, cityList) {
  365. data = data.map((item) => {
  366. Number(item.country) > 0
  367. ? (item.countryName = countryList[item.country])
  368. : (item.countryName = "");
  369. return item;
  370. });
  371. data = data.map((item) => {
  372. Number(item.city) > 0
  373. ? (item.cityName = cityList[item.city])
  374. : (item.cityName = "");
  375. return item;
  376. });
  377. return data;
  378. },
  379. mapServiceCategoryName(data, categoryList) {
  380. data = data.map((item) => {
  381. Number(item.category) > 0
  382. ? (item.categoryName = categoryList[item.category])
  383. : (item.categoryName = "");
  384. return item;
  385. });
  386. return data;
  387. },
  388. async getPriceRange() {
  389. let max = 0;
  390. let vm = this;
  391. if(vm.serviceList){
  392. vm.serviceList.forEach((element) => {
  393. if (element.price > max) {
  394. max = element.price;
  395. }
  396. });
  397. }
  398. vm.maxPrice = max;
  399. vm.priceRangeFilter = [0, max];
  400. },
  401. filterByPrice(data, min, max) {
  402. let item = data.filter((item) => item.price >= min && item.price <= max);
  403. return item;
  404. },
  405. updatePriceRange(value) {
  406. this.priceRangeFilter = [...value];
  407. },
  408. filterByRating(data, min, max) {
  409. return data.filter((item) => item.price >= min && item.price <= max);
  410. },
  411. updateRatingRange(value) {
  412. console.log(value);
  413. },
  414. filterByLocation(data, locations) {
  415. let list = data.filter(
  416. (item) =>
  417. locations.includes(item.cityName) ||
  418. locations.includes(item.countryName)
  419. );
  420. return list;
  421. },
  422. updateLocationFilter(value) {
  423. console.log("位置勾選");
  424. this.locationNameFilter = value;
  425. this.getServiceList();
  426. },
  427. filterByCategory(data, categories) {
  428. return data.filter((item) => categories.includes(item.categoryName));
  429. },
  430. updateCategoryFilter(value) {
  431. console.log("類型勾選");
  432. this.categoryFilter = value;
  433. this.getServiceList();
  434. },
  435. updateCurrentPage(value) {
  436. console.log("分頁變化");
  437. this.currentPage = value;
  438. this.getServiceList();
  439. },
  440. sliceRenderList(data) {
  441. return data.slice(
  442. (this.currentPage - 1) * this.perPageItems,
  443. this.currentPage * this.perPageItems
  444. );
  445. },
  446. async getQuery() {
  447. let vm = this;
  448. // this.locationQueryFilter = "";
  449. this.categoryQueryFilter = "";
  450. // if (this.$route.query.hasOwnProperty("country") && this.countryNameList.length>0) {
  451. // this.locationQueryFilter =
  452. // this.countryNameList[Number(this.$route.query.country)];
  453. // }
  454. // if (this.$route.query.hasOwnProperty("city") && this.cityNameList.length>0) {
  455. // this.locationQueryFilter =
  456. // this.cityNameList[Number(this.$route.query.city)];
  457. // }
  458. // if (this.$route.query.hasOwnProperty("region")) {
  459. // this.locationQueryFilter =
  460. // this.regionNameList[Number(this.$route.query.region)];
  461. // }
  462. // if (this.$route.query.hasOwnProperty("category") && this.categoryNameList.length>0) {
  463. // this.categoryQueryFilter =
  464. // this.categoryNameList[Number(this.$route.query.category)];
  465. // }
  466. // if (this.$route.query.hasOwnProperty("subcategory")) {
  467. // this.categoryQueryFilter =
  468. // this.unsortSubcategoryList[Number(this.$route.query.subcategory)];
  469. // }
  470. if(vm.$route.query.hasOwnProperty("category")){
  471. vm.categoryQueryFilter = vm.$route.query.category;
  472. }else if(vm.$route.query.hasOwnProperty("subcatg")){
  473. vm.categoryQueryFilter = vm.$route.query.subcatg;
  474. }
  475. },
  476. },
  477. };
  478. </script>
  479. <style lang="scss" scoped>
  480. </style>