<template>
  <div class="search-template">
    <div class="search-line">
      <div class="search-container">
        <img src="@/assets/search2.png" alt="" />
        <input
          ref="input"
          class="placeholder"
          placeholder="请输入搜索关键词"
          v-model="searchValue"
          @input="onSearch"
        />
      </div>
      <div class="cancel-text" @click="handleClickCancel">
        取消
      </div>
    </div>
    <div class="folder-detail">
      <div class="search-result">
        搜索结果：
      </div>
      <div v-if="searchResult.length <= 0" style="padding: 30px">
        <van-image
          src="@/assets/search.png"
          fit="contain"
          width="78px"
        ></van-image>
        <div style="color: #9b9b9b; font-size: 14px;margin-top:10px;">
          无搜索结果
        </div>
      </div>
      <TemplateListContainer
        :templateList="searchResult"
        class="template-list-container"
      />
    </div>
  </div>
</template>
<script lang="ts">
import {
  Component,
  Prop,
  Vue,
  Emit,
  Inject,
  Mixins,
} from 'vue-property-decorator';

import { State, Action, namespace } from 'vuex-class';

import TemplateListContainer from '@/views/viewTemplate/components/TemplateListContainer.vue';

@Component({
  components: { TemplateListContainer },
})
export default class SearchTemplate extends Vue {
  private searchValue: string = '';
  private searchResult: any[] = [];
  private onSearch(e: any) {
    const key = e.target.value;
    if (!key) {
      return;
    }
    this.$api.template.searchCustomize(key).then((res: any) => {
      this.searchResult = res.results || [];
    });
  }

  mounted() {
    (this.$refs.input as any).focus();
  }

  handleClickCancel() {
    this.$router.go(-1);
  }
}
</script>
<style scoped lang="scss">
.search-template {
  padding: 0 16px;
  .search-line {
    display: flex;
    align-items: center;
    .search-container {
      flex-grow: 1;
      margin-top: 17px;
      margin-bottom: 15px;
      height: 40px;
      background: #f7f7f7;
      border-radius: 4px;
      display: flex;
      align-items: center;
      img {
        margin-left: 14px;
        width: 17px;
      }

      input {
        border: 0;
        padding-left: 0px;
        text-align: left;
        margin-left: 10px;
        flex-grow: 1;
        font-size: 14px;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        line-height: 20px;
        background: #f7f7f7;
      }
      input::placeholder {
        color: #b6b5ba;
      }
    }
    .cancel-text {
      width: 28px;
      height: 20px;
      font-size: 14px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 500;
      color: #353535;
      line-height: 20px;
      margin-left: 9px;
    }
  }
  .search-result {
    text-align: left;
    font-size: 14px;
    font-family: PingFangSC-Medium, PingFang SC;
    font-weight: 500;
    color: #353535;
    line-height: 20px;
  }
  .template-list-container {
    margin-top: 21px;
  }
}
</style>
