123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291 |
- <script setup>
- import { ref, reactive, watch } from "vue";
- import { useMainStore } from "../stores/store";
- import { useI18n } from "vue-i18n";
- import axios from "axios";
- import Navbar from "../components/Navbar.vue";
- const { t } = useI18n();
- const store = useMainStore();
- let loading = ref(false);
- let pageNum = ref(1);
- let pageAmount = ref(10);
- let totalPages = ref(1);
- let assignBrand = ref("");
- let searchKeyword = ref("");
- let noResults = ref(false);
- function filterBrand(val) {
- if (val !== "全部") {
- assignBrand.value = val;
- } else {
- assignBrand.value = "";
- }
- getBrand();
- pageNum.value = 1;
- }
- watch(pageNum, () => {
- getBrand();
- });
- let data = reactive({
- list: [],
- });
- async function getBrand() {
- loading.value = true;
- let keyword = "館外";
- let url = `https://cmm.ai:9101/find_brand?language=ch&page_num=${pageNum.value}&page_amount=${pageAmount.value}`;
- if (searchKeyword.value !== "") {
- url += `&search_name=${searchKeyword.value}`;
- }
-
- if (assignBrand.value !== "") {
- keyword += `,${assignBrand.value}`;
- }
- url += `&keyword=${keyword}`;
- try {
- const response = await axios.get(url);
- data.list = response.data.data;
- totalPages.value = getTotalPages(response.data.all_num, pageAmount.value);
- loading.value = false;
- console.log("館外品牌", response.data.data);
- if (!response.data.data.length) {
- noResults.value = true;
- } else {
- noResults.value = false;
- }
- console.log("noResults.value", noResults.value);
- } catch (error) {
- console.error(error);
- }
- }
- getBrand();
- function getTotalPages(totalRecords, recordsPerPage) {
- return Math.ceil(totalRecords / recordsPerPage);
- }
- const truncateText = (text, maxLength) => {
- text = text.replace(/\s+/g, "");
- if (text.length <= maxLength) {
- return text;
- }
- return text.substring(0, maxLength) + "...";
- };
- let brandList = reactive([
- {
- value: "全部",
- text: "external.all",
- },
- {
- value: "伴手禮",
- text: "external.gifts",
- },
- {
- value: "餐飲",
- text: "external.dining",
- },
- {
- value: "住宿",
- text: "external.accommodation",
- },
- {
- value: "美髮",
- text: "external.hairdressing",
- },
- {
- value: "汽車用品",
- text: "external.car_supplies",
- },
- {
- value: "休閒娛樂",
- text: "external.entertainment",
- },
- {
- value: "寵物用品",
- text: "external.pet_supplies",
- },
- ]);
- function handleSearch() {
- console.log("Searching for:");
- searchKeyword.value;
- }
- </script>
- <template>
- <Navbar />
- <div class="brand-list">
- <v-text-field
- v-model="searchKeyword"
- append-inner-icon="mdi-magnify"
- density="compact"
- label="搜尋品牌"
- variant="outlined"
- hide-details
- single-line
- @click:append-inner="getBrand"
- @keydown.enter="getBrand"
- class="border-sm rounded"
- ></v-text-field>
- <v-row class="mt-3 px-1">
- <v-col
- cols="6"
- v-for="(item, index) in brandList"
- :key="index"
- class="pa-2"
- >
- <button
- @click="filterBrand(item.value)"
- :class="{ active: item.value === assignBrand }"
- class="rounded brand-btn"
- >
- {{ t(item.text) }}
- </button>
- </v-col>
- </v-row>
- <div v-if="loading" class="d-flex justify-center pt-15">
- <v-progress-circular color="primary" indeterminate></v-progress-circular>
- </div>
- <v-row v-else-if="!loading && !noResults" class="content mt-0">
- <v-col
- cols="12"
- class="card"
- v-for="(item, index) in data.list"
- :key="index"
- >
- <a :href="item.info.url" target="_blank">
- <img class="card-img" :src="item.info.img" :alt="item.info.name" />
- </a>
- <h2>{{ item.info.name }}</h2>
- <p>{{ truncateText(item.info.content, 100) }}</p>
- <div class="d-flex align-center mt-3 mb-5">
- <img src="../assets/img/location-dot-solid.svg" width="15" alt="" />
- <p class="ms-2">{{ item.info.address }}</p>
- </div>
- <div class="cta">
- <a :href="item.info.url" target="_blank">
- <button>立即前往</button>
- </a>
- </div>
- </v-col>
- </v-row>
- <p v-else-if="noResults" class="text-center mt-10">
- 找不到符合的資料,請重新搜尋。
- </p>
- <v-pagination
- v-if="!loading && !noResults"
- color="primary"
- v-model="pageNum"
- class="my-10"
- :length="totalPages"
- ></v-pagination>
- </div>
- </template>
- <style lang="scss">
- .brand-list {
- width: 90%;
- margin: 30px auto;
- .brand-btn {
- width: 100%;
- padding: 0.7rem;
- color: var(--main-color);
- background-color: #f5f2eb;
- letter-spacing: 1px;
- transition: all 0.3s;
- &:hover {
- opacity: 0.8;
- }
- &.active {
- color: #fff;
- background-color: var(--main-color);
- }
- }
- .content {
- text-align: center;
- .card {
- border-bottom: 1px solid #cea84d;
- padding: 2rem 1rem;
- &:last-child {
- border-bottom: none !important;
- }
- }
- .card {
- letter-spacing: 0.05rem;
- h2 {
- margin: 0.5rem 0;
- font-size: 1.2rem;
- font-weight: bold;
- text-align: left;
- }
- p {
- text-align: left;
- }
- .card-img {
- width: 100%;
- height: 220px;
- object-fit: contain;
- }
- .cta {
- text-align: right;
- button {
- padding: 10px 20px;
- border-radius: 100px;
- color: #fff;
- text-align: center;
- background-color: #b07843;
- letter-spacing: 0.05rem;
- text-decoration: none;
- transition: all 0.3s;
- }
- }
- }
- }
- .v-pagination {
- margin: auto;
- max-width: 300px;
- }
- .v-btn--icon.v-btn--density-default {
- width: 35px !important;
- }
- }
- </style>
|