<div class="enablevue">
    <searchblock placeholder="Skriv här för att söka" search-url="http://localhost:2000/production/KitModules/EPiFind/Services/SearchService.asmx/QueryFreeText" search-text="Den som söker han finner" init-data="{&quot;ShowAllSearchSection&quot;:true,&quot;CurrentPageId&quot;:&quot;198827&quot;,&quot;currentPageLink&quot;:&quot;https://wwwtest.miun.se/ny-design/block/searchblock/&quot;,&quot;lang&quot;:&quot;sv&quot;,&quot;SearchPageId&quot;:&quot;65227&quot;,&quot;take&quot;:15,&quot;NoHitHighlight&quot;:true,&quot;controlid&quot;:&quot;0c3d4e1655e14805980e76cd8c8a9323&quot;,&quot;sortorder&quot;:&quot;&quot;,&quot;currentSearchPageLink&quot;:&quot;https://wwwtest.miun.se/sok/&quot;,&quot;GetBestBets&quot;:&quot;False&quot;,&quot;ShowAllLink&quot;:&quot;False&quot;,&quot;DoNotTrack&quot;:true,&quot;mainfacet&quot;:&quot;80856|Välkomstbrev|100|False&quot;,&quot;querytext&quot;:&quot;testar&quot;}"></searchblock>
</div>
<div class="enablevue">
    <searchblock placeholder="{{placeholder}}" search-url="{{queryFreeTextUrl}}" search-text="{{searchText}}" init-data="{{initData}}"></searchblock>
</div>
{
  "epiDivClass": "col-md-8 offset-md-2",
  "heading": "Sök",
  "placeholder": "Skriv här för att söka",
  "searchText": "Den som söker han finner",
  "queryFreeTextUrl": "http://localhost:2000/production/KitModules/EPiFind/Services/SearchService.asmx/QueryFreeText",
  "initData": "{\"ShowAllSearchSection\":true,\"CurrentPageId\":\"198827\",\"currentPageLink\":\"https://wwwtest.miun.se/ny-design/block/searchblock/\",\"lang\":\"sv\",\"SearchPageId\":\"65227\",\"take\":15,\"NoHitHighlight\":true,\"controlid\":\"0c3d4e1655e14805980e76cd8c8a9323\",\"sortorder\":\"\",\"currentSearchPageLink\":\"https://wwwtest.miun.se/sok/\",\"GetBestBets\":\"False\",\"ShowAllLink\":\"False\",\"DoNotTrack\":true,\"mainfacet\":\"80856|Välkomstbrev|100|False\",\"querytext\":\"testar\"}"
}
  • Content:
    Vue.component("searchblock", {
      props: ["initData", "searchText", "placeholder", "searchUrl"],
      data() {
        return {
          isInputFocus: false,
          showAutoComplete: false,
          userQuery: "",
          autoCompleteHits: [],
          loading: false,
          url: this.searchUrl,
          init: JSON.parse(JSON.stringify(this.initData)),
          ph: JSON.parse(JSON.stringify(this.placeholder))
        };
      },
      mounted() {
        console.log(JSON.parse(this.init));
    
      },
      watch: {
        userQuery: function (newVal, oldVal) {
          if (newVal !== oldVal) {
            this.showAutoComplete = true;
            this.autocomplete(newVal)
          }
          if (newVal.length < 2) {
            this.showAutoComplete = false;
            this.autoCompleteHits = "";
          }
        }
      },
      methods: {
        hideAutoCompleteWindow() {
          if (this.showAutoComplete) {
            this.showAutoComplete = false;
            this.autoCompleteHits = "";
          }
        },
        async autocomplete(val) {
          if (typeof val === "string") {
            if (val.length >= 2 && this.url) {
              this.loading = true;
              try {
                let req = {
                  query: {
                    ...JSON.parse(this.init)
                  }
                }
                req.query.querytext = val;
                console.log(req);
    
                let res = await axios.post(this.url, req);
                let data = res.data.d;
    
                console.log(data)
                if (data.SearchHits) {
                  this.autoCompleteHits = data.SearchHits;
                }
                this.loading = false;
              } catch (error) {
                console.log(error);
              }
            } else {
              this.autoCompleteHits = "";
            }
          }
        }
      },
      template: `
        <div class="w-100 searchblock">
            <div class="w-100" v-if="this.searchText">
                <h4 class="heading-level-4">
                  {{this.searchText}}
                </h4>
            </div>
            <div class="w-100 searchblock">
                <form autocomplete="off" @submit.prevent="autocomplete" :class="{'is--focused': isInputFocus}" class="search--input--container form-control" ref="search">
                    <input type="text" name="name" v-model="userQuery" :placeholder="this.ph ? this.ph : 'Sök'"  @focus="isInputFocus = true" @blur="isInputFocus = false"/>
                    <transition name="fade" mode="in-out">
                        <button  @click="this.autocomplete" type="submit" v-if="!isInputFocus "
                            class="d-flex align-items-center justify-content-center search--btn">
                            <span class="material-icons ">search</span>
                        </button>
                        <button  type="submit" @click="this.autocomplete" v-else
                            class="d-flex search--btn align-items-center active justify-content-center">
                            <span class="material-icons blue">search</span>
                        </button>
                    </transition>
                    <autocomplete-results @hideAutoComplete="this.hideAutoCompleteWindow" :isLoading="this.loading" :hits="this.autoCompleteHits"></autocomplete-results>
                </form>
            </div>
          </div>
        `
    });
    
    Vue.component("autocomplete-results", {
      props: ["isLoading", "hits"],
      methods: {
        hideAutoComplete() {
          this.$emit("hideAutoComplete")
        }
      },
      directives: {
        ClickOutside
      },
      template: `
    <div class="autocomplete-results d-flex flex-column align-items-center" v-click-outside="this.hideAutoComplete">
            <vloading class="mt-3 mb-3" key="1" v-if="this.isLoading" :height="25" :width="25" :color="'#404040'" :is-full-page="false" :active.sync="this.isLoading"></vloading>
            <transition-group tag="ul" name="fade"  v-else-if="this.hits.length > 0" class="list-unstyled d-flex flex-column">
                <a class="d-flex flex-row align-items-center justify-content-between" v-for="(hit, index) in this.hits" :key="hit.Id" :href="hit.Url" v-if="hit.Title && hit.Url">{{hit.Title}}
                  <small class="ml-4 anmalningskod" v-if="hit.MetaData && hit.MetaData.Anmalningskod && hit.MetaData.Anmalningskod.StringValue" v-html="hit.MetaData.Anmalningskod.StringValue"></small>
                </a>
            </transition-group>
    </div>
        `
    })
  • URL: /components/raw/searchblock/SearchBlock.js
  • Filesystem Path: src\components\02-block_components\SearchBlock\SearchBlock.js
  • Size: 4.3 KB
  • Content:
    .searchblock {
      .search--input--container {
        position: relative;
        overflow: inherit;
    
        input[type=text] {
          padding: 0px 15px;
          height: 100%;
        }
      }
    
      .autocomplete-results {
        position: absolute;
        z-index: 1;
        left: 0;
        overflow-y: auto;
        max-height: 400px;
        right: 0;
        top: 59px;
        background: white;
        box-shadow: $box-shadow;
    
        ul {
          width: 100%;
          margin-bottom: 0px;
    
          a {
            display: flex;
            flex-direction: row;
            padding-left: 25px;
            padding-right: 25px;
            padding-top: 15.5px;
            padding-bottom: 15.5px;
            align-items: center;
            cursor: pointer;
            color: $dark-grey;
            font-size: 16px;
            line-height: 19px;
    
            .anmalningskod {
              opacity: 0.6;
            }
    
            &:hover {
              background-color: #e7f1f8;
    
              a {
                text-decoration: underline;
              }
            }
    
            &:focus {
              background-color: #e7f1f8;
            }
          }
        }
      }
    }
  • URL: /components/raw/searchblock/SearchBlock.scss
  • Filesystem Path: src\components\02-block_components\SearchBlock\SearchBlock.scss
  • Size: 1.1 KB
  • Handle: @searchblock
  • Preview:
  • Filesystem Path: src\components\02-block_components\SearchBlock\SearchBlock.hbs

There are no notes for this item.