// 載入共用 template $('#navbar').load('../../template/navbar.html'); $('#footer').load('../../template/footer.html'); $('#btn-box').load('../../template/button.html'); $('#topCarousel').load('../../template/top_carousel.html'); let page = 1; // 當前頁數 let pageSize = 18; // 每頁數量 let isFirstLoad = true; // 初始載入 // 列表篩選 async function dataSearch(type = "") { let url; $('#builderSpinner').show(); $('#builderList').hide(); if (isFirstLoad) { // 第一次載入使用本地 JSON 文件 // url = './json/designers_lists_data.json'; url = `https://m3.hhh.com.tw:18673/builder_search?page=${page}&page_size=${pageSize}`; } else { // 後續使用 API (預設排序為 recommend) url = `https://m3.hhh.com.tw:18673/builder_search?page=${page}&page_size=${pageSize}`; let input = $(".keywords").val(); if (input !== "") { let isExist = filterList.some((item) => item.id === "keyword"); // 判斷是否已存在關鍵字 const newItem = { id: "keyword", text: "關鍵字", value: input }; if (!isExist) { filterList.push(newItem); createFilterHtml(newItem); } else { // 移除原本關鍵字 $('.budget p.me-1').each(function () { if ($(this).text().includes('關鍵字')) { $(this).closest('.me-3').remove(); } }); if (filterList.length === 0) { $('#removeResultBtn').hide(); } filterList = filterList.filter(item => item.text !== "關鍵字"); filterList.push(newItem); createFilterHtml(newItem); } $(".keywords").val("") // url += `&keyword=${input}`; } if (filterList.length) { filterList.map(item => { url += `&${item.id}=${item.value}`; }); } } try { const response = await axios.get(url); console.log('response.data', response.data); // console.log('response.data.videos', response.data.videos); let totalCount = response.data.total_count; let totalPages = Math.ceil(totalCount / pageSize); $("#totalCount").html(totalCount); if (totalPages) { $('.filter-list .pagination').show(); setPagination(totalPages); // 分頁處理 } else { $('.filter-list .pagination').hide(); } let resultHtml = ''; if (response.data.videos.length) { response.data.videos.forEach((item) => { resultHtml += `
`; }); } else { resultHtml += "找不到符合的資料,請重新搜尋。
" } $('#builderList').html(resultHtml); setTimeout(() => { $('#builderList').show(); $('#builderSpinner').hide(); }, 100) // 更新初始載入狀態 if (isFirstLoad) { isFirstLoad = false; } } catch (error) { console.log("error", error); } } dataSearch(); async function getData() { // 取得當前網址的查詢字串部分 let urlParams = new URLSearchParams(window.location.search); // 從查詢字串中取得 'id' 的值 let id = urlParams.get('id'); let url = `https://m3.hhh.com.tw:18674/genbuilder?id=${id}&page=1`; console.log(id); // 顯示 "2058" try { const response = await axios.get(url); let data = response.data[0]; $("#name").text(data.name); $("#city").text(data.city); $("#builder_name").text(data.name); $("#service_phone").text(data.service_phone); $("#service_phone").attr("href", "tel:" + data.service_phone); $("#detail").text(data.detail); if (data.detail_data.unit_price !== "") { $("#unit_price span").text(data.detail_data.unit_price); } else { $("#unit_price").hide(); } // 判斷是否有值,若無則隱藏 if (data.detail_data.construction_company !== "") { $("#construction_company span").text(data.detail_data.construction_company); } else { $("#construction_company").hide(); } if (data.detail_data.builder_type !== "") { $("#builder_type span").text(data.detail_data.builder_type); } else { $("#builder_type").hide(); } if (data.detail_data.configuration !== "") { $("#configuration span").text(data.detail_data.configuration); } else { $("#configuration").hide(); } if (data.detail_data.house_type !== "") { $("#house_type span").text(data.detail_data.house_type); } else { $("#house_type").hide(); } if (data.detail_data.address !== "") { $("#address a").text(data.detail_data.address); $("#address a").attr("href", "https://maps.google.com.tw/maps?q=" + data.detail_data.address); } else { $("#address").hide(); } if (data.detail_data.phone !== "") { $("#phone span").text(data.detail_data.phone); } else { $("#phone").hide(); } if (data.detail_data.website !== "") { $("#website a").text(data.detail_data.website); $("#website a").attr("href", data.detail_data.website); } else { $("#website").hide(); } // 建案影片 if (data.yt.length) { let dom = ""; data.yt.map((item) => { dom += `