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.

497 lines
17 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
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: "CreateDate" },
  78. { name: "Price (Low to High)", value: "MinPrice" },
  79. { name: "Recently Added", value: "LaunchDateS" },
  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.renderList = this.sliceRenderList(this.serviceFilter);
  117. this.isPageLoading = false;
  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. vm.isPageLoading = true;
  169. await vm.getServiceList();
  170. // let data =await vm.mapServiceLocationName(
  171. // vm.serviceList,
  172. // vm.countryNameList,
  173. // vm.cityNameList
  174. // );
  175. // vm.serviceList = data == undefined ? [] : data;
  176. // vm.serviceList =await vm.mapServiceCategoryName(
  177. // vm.serviceList,
  178. // vm.categoryNameList
  179. // );
  180. // vm.serviceList = data == undefined ? [] : data;
  181. // vm.renderList =await vm.serviceList;
  182. // await vm.getPriceRange();
  183. vm.isPageLoading = false;
  184. }
  185. },
  186. },
  187. $route: {
  188. handler: function () {
  189. this.getQuery();
  190. },
  191. },
  192. },
  193. methods: {
  194. async getServiceList() {
  195. let vm = this;
  196. let keyword = "";
  197. let subcatg = "";
  198. let sortField = "CreateDate";
  199. if(vm.sortBy){
  200. sortField = vm.sortBy;
  201. }
  202. let location = "";
  203. // let category = "";
  204. let currency = this.$store.getters.getCurrency;
  205. if (vm.$route.query.q) {
  206. keyword = vm.$route.query.q;
  207. }
  208. // if (vm.$route.query.category) {
  209. // category = "&category=" + vm.$route.query.category;
  210. // }
  211. // if (vm.categoryQueryFilter) {
  212. // subcatg = vm.categoryQueryFilter;
  213. // }else if(vm.$route.query.subcatg){
  214. // subcatg = vm.$route.query.subcatg;
  215. // }
  216. // if(vm.locationQueryFilter){
  217. // location = vm.locationQueryFilter;
  218. // }
  219. await vm.$axios.get(`/trending/api/Onsite/ServiceLists?Lang=${vm.$i18n.localeProperties["langQuery"]}&PageIndex=${vm.currentPage}
  220. &PageSize=${vm.perPageItems}&SortField=${sortField}&sortOrder=desc&KeyWord=${keyword}&Categories=${subcatg}&Locations=${location}
  221. &Currency=${currency}&MinPrice=0&MaxPrice=0`).then((response) => {
  222. if(response && response.data && response.data.DATA && response.data.DATA.rel){
  223. let data = response.data.DATA.rel
  224. if(data.DataList.length>0){
  225. vm.total = data.Total;
  226. vm.serviceList = data.DataList;
  227. }
  228. }
  229. })
  230. .catch((err) => {
  231. console.log(err);
  232. });
  233. },
  234. async getCategoryList() {
  235. await this.$axios
  236. .get(`/trending/api/Onsite/Categories?Lang=${this.$i18n.localeProperties["langQuery"]}`)
  237. .then((response) => {
  238. if(response && response.data && response.data.DATA && response.data.DATA.rel){
  239. let data = response.data.DATA.rel
  240. if(data.length>0){
  241. this.categoryList = data.map((item) => {
  242. this.mainCategoryMap.set(item.CategoryID, item);
  243. if(item.SubCategoryList && item.SubCategoryList.length>0){
  244. item.SubCategoryList = item.SubCategoryList.map(
  245. (children) => {
  246. this.subCategoryMap.set(children.CategoryID, children);
  247. return {
  248. title: children.CategoryName,
  249. key: children.CategoryID,
  250. };
  251. }
  252. );
  253. }else{
  254. item.SubCategoryList = [];
  255. }
  256. return {
  257. title: item.CategoryName,
  258. key: item.CategoryID,
  259. children: item.SubCategoryList,
  260. };
  261. });
  262. }
  263. }
  264. })
  265. .catch((error) =>
  266. console.log(error)
  267. );
  268. },
  269. async getLocationList() {
  270. await this.$axios
  271. .get(`/trending/api/Onsite/Locations?Lang=${this.$i18n.localeProperties["langQuery"]}`)
  272. .then((response) => {
  273. if(response && response.data && response.data.DATA && response.data.DATA.rel){
  274. let data = response.data.DATA.rel
  275. if(data.length>0){
  276. // this.locationList = data;
  277. this.locationList = data.map((item) => {
  278. this.mainLocationMap.set(item.RegionID, item);
  279. if(item.CountryList && item.CountryList.length>0){
  280. item.CountryList = item.CountryList.map(
  281. (children) => {
  282. this.subLocationMap.set(children.CountryID, children);
  283. if(children.CityList && children.CityList.length>0){
  284. children.CityList = children.CityList.map(
  285. (children2) => {
  286. this.subLocationMap2.set(children2.CityID, children2);
  287. return {
  288. title: children2.CityName,
  289. key: children2.CityID,
  290. };
  291. }
  292. );
  293. }else{
  294. children.CityList = [];
  295. }
  296. return {
  297. title: children.CountryName,
  298. key: children.CountryID,
  299. children: children.CityList,
  300. };
  301. }
  302. );
  303. }else{
  304. item.CountryList = [];
  305. }
  306. return {
  307. title: item.RegionName,
  308. key: item.RegionID,
  309. children: item.CountryList,
  310. };
  311. });
  312. }
  313. }
  314. })
  315. .catch((error) =>
  316. console.log(error)
  317. );
  318. },
  319. updateSortBy(data) {
  320. this.sortBy = data;
  321. // console.log("排序:"+this.sortBy);
  322. this.getServiceList();
  323. },
  324. // sortServiceList(data) {
  325. // switch (this.sortBy) {
  326. // // case "Ratings":
  327. // // function Ratings(a, b) {
  328. // // if (Number(a.rating) < Number(b.rating)) return 1;
  329. // // if (Number(a.rating) > Number(b.rating)) return -1;
  330. // // return 0;
  331. // // }
  332. // // return data.sort(Ratings);
  333. // // case "ShowEasy Recommended":
  334. // // return data;
  335. // case "Popularity":
  336. // function Views(a, b) {
  337. // if (Number(a.view_counts) < Number(b.view_counts)) return 1;
  338. // if (Number(a.view_counts) > Number(b.view_counts)) return -1;
  339. // return 0;
  340. // }
  341. // return data.sort(Views);
  342. // case "Price":
  343. // function Price(a, b) {
  344. // if (Number(a.price) < Number(b.price)) return -1;
  345. // if (Number(a.price) > Number(b.price)) return 1;
  346. // return 0;
  347. // }
  348. // return data.sort(Price);
  349. // case "Recently Added":
  350. // function Date(a, b) {
  351. // if (
  352. // a.launch_dates[0].replace(/-/g, "") <
  353. // b.launch_dates[0].replace(/-/g, "")
  354. // )
  355. // return 1;
  356. // if (
  357. // a.launch_dates[0].replace(/-/g, "") >
  358. // b.launch_dates[0].replace(/-/g, "")
  359. // )
  360. // return -1;
  361. // return 0;
  362. // }
  363. // return data.sort(Date);
  364. // default:
  365. // return data;
  366. // }
  367. // },
  368. mapSavedService(data, savedList) {
  369. return data.map((item) => {
  370. item.liked = false;
  371. if (savedList.includes(item.id)) {
  372. item.liked = true;
  373. }
  374. return item;
  375. });
  376. },
  377. mapServiceLocationName(data, countryList, cityList) {
  378. data = data.map((item) => {
  379. Number(item.country) > 0
  380. ? (item.countryName = countryList[item.country])
  381. : (item.countryName = "");
  382. return item;
  383. });
  384. data = data.map((item) => {
  385. Number(item.city) > 0
  386. ? (item.cityName = cityList[item.city])
  387. : (item.cityName = "");
  388. return item;
  389. });
  390. return data;
  391. },
  392. mapServiceCategoryName(data, categoryList) {
  393. data = data.map((item) => {
  394. Number(item.category) > 0
  395. ? (item.categoryName = categoryList[item.category])
  396. : (item.categoryName = "");
  397. return item;
  398. });
  399. return data;
  400. },
  401. async getPriceRange() {
  402. let max = 0;
  403. let vm = this;
  404. if(vm.serviceList){
  405. vm.serviceList.forEach((element) => {
  406. if (element.price > max) {
  407. max = element.price;
  408. }
  409. });
  410. }
  411. vm.maxPrice = max;
  412. vm.priceRangeFilter = [0, max];
  413. },
  414. filterByPrice(data, min, max) {
  415. let item = data.filter((item) => item.price >= min && item.price <= max);
  416. return item;
  417. },
  418. updatePriceRange(value) {
  419. this.priceRangeFilter = [...value];
  420. },
  421. filterByRating(data, min, max) {
  422. return data.filter((item) => item.price >= min && item.price <= max);
  423. },
  424. updateRatingRange(value) {
  425. // console.log(value);
  426. },
  427. filterByLocation(data, locations) {
  428. let list = data.filter(
  429. (item) =>
  430. locations.includes(item.cityName) ||
  431. locations.includes(item.countryName)
  432. );
  433. return list;
  434. },
  435. updateLocationFilter(value) {
  436. // console.log("位置勾選");
  437. this.locationQueryFilter = "";
  438. // this.getServiceList();
  439. },
  440. filterByCategory(data, categories) {
  441. return data.filter((item) => categories.includes(item.categoryName));
  442. },
  443. updateCategoryFilter(value) {
  444. // console.log("類型勾選:" + value);
  445. this.categoryQueryFilter = "";
  446. // this.getServiceList();
  447. },
  448. updateCurrentPage(value) {
  449. // console.log("分頁變化");
  450. this.currentPage = value;
  451. this.getServiceList();
  452. },
  453. sliceRenderList(data) {
  454. return data.slice(
  455. (this.currentPage - 1) * this.perPageItems,
  456. this.currentPage * this.perPageItems
  457. );
  458. },
  459. async getQuery() {
  460. let vm = this;
  461. // this.locationQueryFilter = "";
  462. this.categoryQueryFilter = "";
  463. // if (this.$route.query.hasOwnProperty("country") && this.countryNameList.length>0) {
  464. // this.locationQueryFilter =
  465. // this.countryNameList[Number(this.$route.query.country)];
  466. // }
  467. // if (this.$route.query.hasOwnProperty("city") && this.cityNameList.length>0) {
  468. // this.locationQueryFilter =
  469. // this.cityNameList[Number(this.$route.query.city)];
  470. // }
  471. // if (this.$route.query.hasOwnProperty("region")) {
  472. // this.locationQueryFilter =
  473. // this.regionNameList[Number(this.$route.query.region)];
  474. // }
  475. // if (this.$route.query.hasOwnProperty("category") && this.categoryNameList.length>0) {
  476. // this.categoryQueryFilter =
  477. // this.categoryNameList[Number(this.$route.query.category)];
  478. // }
  479. // if (this.$route.query.hasOwnProperty("subcategory")) {
  480. // this.categoryQueryFilter =
  481. // this.unsortSubcategoryList[Number(this.$route.query.subcategory)];
  482. // }
  483. if(vm.$route.query.hasOwnProperty("category")){
  484. // vm.categoryQueryFilter = vm.$route.query.category;
  485. }else if(vm.$route.query.hasOwnProperty("subcatg")){
  486. vm.categoryQueryFilter = vm.$route.query.subcatg;
  487. }
  488. },
  489. },
  490. };
  491. </script>
  492. <style lang="scss" scoped>
  493. </style>