SyuanYu пре 6 месеци
родитељ
комит
ab596c0ed8
3 измењених фајлова са 93 додато и 6 уклоњено
  1. 31 2
      builder/lists/js/main.js
  2. 31 2
      designers/lists/js/main.js
  3. 31 2
      videos/lists/js/main.js

+ 31 - 2
builder/lists/js/main.js

@@ -97,7 +97,6 @@ function createFilterHtml(item) {
 
 // 清除單一篩選條件
 function removeBtn(element, id, val) {
-  console.log('id, val', id, val);
   filterList = filterList.filter(item => item.text !== val);
 
   ; // 移除 div & active
@@ -145,7 +144,37 @@ async function builderSearch() {
     let input = $(".keywords").val();
 
     if (input !== "") {
-      url += `&keyword=${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) {

+ 31 - 2
designers/lists/js/main.js

@@ -100,7 +100,6 @@ function createFilterHtml(item) {
 
 // 清除單一篩選條件
 function removeBtn(element, id, val) {
-  console.log('id, val', id, val);
   filterList = filterList.filter(item => item.text !== val);
 
   ; // 移除 div & active
@@ -155,7 +154,37 @@ async function designerSearch(type = "") {
     let input = $(".keywords").val();
 
     if (input !== "") {
-      url += `&keyword=${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) {

+ 31 - 2
videos/lists/js/main.js

@@ -97,7 +97,6 @@ function createFilterHtml(item) {
 
 // 清除單一篩選條件
 function removeBtn(element, id, val) {
-  console.log('id, val', id, val);
   filterList = filterList.filter(item => item.text !== val);
 
   ; // 移除 div & active
@@ -153,7 +152,37 @@ async function videoSearch(type = "") {
     let input = $(".keywords").val();
 
     if (input !== "") {
-      url += `&keyword=${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) {