<!--
 * @Author: your name
 * @Date: 2021-10-18 17:44:42
 * @LastEditTime: 2022-01-10 14:46:46
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \Foshan4A\src\views\account\components\search.vue
-->
<template>
  <div class="pub-search">
    <div class="flex">
      <div v-if="isTitle" :class="isChild ? 'childTitle' : ''" class="title">
        {{ title }}
      </div>
      <div v-if="isOnly" class="content flex-wrap">
        <div
          v-if="isSearch"
          :class="isChild ? 'childSearch' : ''"
          class="search"
        >
          <el-input
            :size="isChild ? 'medium' : ''"
            :placeholder="placeholder"
            @clear="clearSearch"
            clearable
            v-model="input"
            @keyup.enter.native="checkSearch"
          >
            <el-button slot="prepend" icon="el-icon-search"></el-button>
          </el-input>
        </div>
        <div v-if="isSearch" class="btn">
          <button
            :class="isChild ? 'childBtnAn' : ''"
            @click="checkSearch"
            class="btnAn"
          >
            搜索
          </button>
        </div>
        <div v-if="isSlot" class="add">
          <slot></slot>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "PubSearch",
  props: {
    //title
    title: {
      type: String,
      default: "",
    },
    //placeholder
    placeholder: {
      type: String,
      default: "请输入内容",
    },
    //是否只显示title
    isOnly: {
      type: Boolean,
      default: true,
    },
    //是否显示搜索
    isSearch: {
      type: Boolean,
      default: true,
    },
    //是否显示插槽
    isSlot: {
      type: Boolean,
      default: false,
    },
    //是否title
    isTitle: {
      type: Boolean,
      default: false,
    },
    //是否二级页面搜索
    isChild: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      input: "",
    };
  },
  created() {
    const { keyWords } = this.$route.query;
    if (keyWords) {
      this.input = keyWords;
    }
  },
  methods: {
    checkSearch() {
      this.$emit("getSearchData", this.input);
    },
    clearSearch() {
      this.$emit("clearSearchData", this.input);
    },
  },
};
</script>

<style lang="scss" scoped>
.pub-search {
  .content > div {
    margin-right: 24px;
    &:last-child {
      margin-right: 0;
    }
  }
  .title {
    line-height: 48px;
    font-size: 24px;
    font-family: Microsoft YaHei;
    font-weight: bold;
    color: #303133;
    position: relative;
    padding-left: 16px;
    &::after {
      position: absolute;
      content: "";
      width: 4px;
      height: 26px;
      top: 50%;
      margin-top: -12px;
      left: 0;
      background: #6e82a7;
    }
  }
  ::v-deep .search {
    width: 320px;
    height: 48px;
    line-height: 48px;
    padding: 0 24px;
    background: #ffffff;
    box-shadow: 0px 6px 7px 0px rgba(0, 0, 0, 0.06);
    border-radius: 6px;
    .el-input-group__prepend {
      background-color: #fff;
      border: none;
      padding-left: 0;
      padding-right: 15px;
      .el-icon-search {
        font-size: 16px;
        font-weight: bold;
      }
    }
    .el-input__inner {
      border: none;
      padding: 0;
      font-size: 16px;
    }
  }
  .childSearch {
    height: 38px;
    line-height: 38px;
    box-shadow: none;
    border: 1px solid #d7dae3;
    background: #f9fbff;
    padding: 0 22px;
  }
  .btnAn {
    padding: 0 32px;
    height: 48px;
    background: linear-gradient(0deg, #6983be, #777dba);
    box-shadow: 0px 3px 4px 0px rgba(0, 0, 0, 0.18);
    border-radius: 6px;
    outline: none;
    border: none;
    cursor: pointer;
    color: #fff;
    font-size: 16px;
    font-family: Microsoft YaHei;
    font-weight: bold;
  }
  .btnAdd {
    padding: 0 32px;
    height: 48px;
    background: #f5f7fa;
    border: 1px solid #b4b7cb;
    box-shadow: 0px 6px 7px 0px rgba(0, 0, 0, 0.06);
    border-radius: 6px;
    font-size: 16px;
    font-family: Microsoft YaHei;
    font-weight: bold;
    color: #6f81bc;
    cursor: pointer;
  }
  .childBtnAn {
    padding: 0 24px;
    height: 40px;
    background: linear-gradient(0deg, #777dba, #6983be);
    box-shadow: 0px 3px 4px 0px rgba(0, 0, 0, 0.18);
    border-radius: 6px;
    outline: none;
    border: none;
    cursor: pointer;
    color: #fff;
    font-size: 16px;
    font-family: Microsoft YaHei;
    font-weight: bold;
  }
  .childBtnAdd {
    padding: 0 24px;
    height: 40px;
    background: #f5f7fa;
    border: 1px solid #b4b7cb;
    box-shadow: 0px 6px 7px 0px rgba(0, 0, 0, 0.06);
    border-radius: 6px;
    font-size: 16px;
    font-family: Microsoft YaHei;
    font-weight: bold;
    color: #6f81bc;
    cursor: pointer;
  }
  .childTitle {
    line-height: 40px;
  }
}
</style>
