<!--
 * @Author: your name
 * @Date: 2021-10-18 17:44:42
 * @LastEditTime: 2022-05-13 13:35:45
 * @LastEditors: your name
 * @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">
        <el-select v-model="value" clearable placeholder="请选择" v-if="isSou">
          <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
          </el-option>
        </el-select>
        <el-select v-model="value1" clearable placeholder="请选择" v-if="isSou">
          <el-option v-for="item in options1" :key="item.value" :label="item.label" :value="item.value">
          </el-option>
        </el-select>
        <div v-if="isSearch" :class="isChild ? 'childSearch' : ''" class="search" @keyup.enter="checkSearch">
          <el-input :size="isChild ? 'medium' : ''" :placeholder="placeholder" @clear="clearSearch" clearable v-model="input">
            <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: true,
    },
    //是否二级页面搜索
    isChild: {
      type: Boolean,
      default: false,
    },
    //是否标题
    isTitle: {
      type: Boolean,
      default: true,
    },
    //是否下拉
    isSou: {
      type: Boolean,
      default: false,
    },
  },
  data () {
    return {
      input: "",
    };
  },
  methods: {
    checkSearch () {
      if (this.isSou) {
        let params = {
          input: this.input,
          value1: this.value1,
          value: this.value,
        };
        this.$emit("getSearchData", params);
      } else {
        this.$emit("getSearchData", this.input);
      }
    },
    clearSearch () {
      this.$emit("clearSearchData", this.input);
    },
    setSearch (val) {
      this.input = val
    }
  },
};
</script>

<style lang="scss" scoped>
.pub-search {
  .content {
    display: flex;
    align-items: center;
  }
  .content > div {
    margin-right: 12px;
    &:last-child {
      margin-right: 0;
    }
  }
  ::v-deep .el-select {
    width: 136px;
    .el-input__suffix {
      right: 5px;
      top: 2px;
    }
    .el-input__inner {
      font-size: 14px;
      font-family: Microsoft YaHei;
      font-weight: 400;
      color: #101116;
    }
    // .el-icon-arrow-up:before {
    //   content: "\f057";
    // }
  }
  .title {
    line-height: 36px;
    font-size: 20px;
    font-family: Microsoft YaHei;
    font-weight: bold;
    color: #303133;
    position: relative;
    padding-left: 16px;
    &::after {
      position: absolute;
      content: "";
      width: 4px;
      height: 20px;
      top: 50%;
      margin-top: -9px;
      left: 0;
      background: #2d67e3;
    }
  }
  ::v-deep .el-input__icon {
    line-height: 36px;
  }
  ::v-deep .search {
    width: 320px;
    height: 32px;
    line-height: 32px;
    padding: 0 16px;
    background: #ffffff;
    box-shadow: 0px 3px 3px 0px rgba(0, 0, 0, 0.06);
    border-radius: 4px;

    .el-input-group__prepend {
      background-color: #fff;
      border: none;
      padding-left: 0;
      padding-right: 15px;
      .el-icon-search {
        font-size: 14px;
        font-weight: bold;
      }
    }
    .el-input__inner {
      border: none;
      padding: 0;
      font-size: 14px;
      height: 20px;
      line-height: 20px;
    }
    .el-input__suffix {
      position: absolute;
    }
  }
  .childSearch {
    height: 32px;
    line-height: 32px;
    box-shadow: none;
    border: 1px solid #d7dae3;
    // background: #f9fbff;
    padding: 0 18px;
    overflow: hidden;
  }
  .btnAn {
    padding: 0 18px;
    height: 32px;
    line-height: 32px;
    background: #2d67e3;
    box-shadow: 0px 3px 4px 0px rgba(0, 0, 0, 0.18);
    border-radius: 4px;
    outline: none;
    border: none;
    cursor: pointer;
    color: #fff;
    font-size: 14px;
    font-family: Microsoft YaHei;
    font-weight: bold;
  }
  .btnAdd {
    padding: 0 18px;
    height: 32px;
    line-height: 32px;
    border: 1px solid #9ebbf7;
    background: #f5f7fa;
    box-shadow: 0px 6px 7px 0px rgba(0, 0, 0, 0.06);
    border-radius: 4px;
    font-size: 14px;
    font-family: Microsoft YaHei;
    font-weight: bold;
    color: #2d67e3;
    cursor: pointer;
  }
  .childBtnAn {
    padding: 0 18px;
    height: 32px;
    line-height: 32px;
    background: #2d67e3;
    box-shadow: 0px 3px 4px 0px rgba(0, 0, 0, 0.18);
    border-radius: 4px;
    outline: none;
    border: none;
    cursor: pointer;
    color: #fff;
    font-size: 14px;
    font-family: Microsoft YaHei;
    font-weight: bold;
  }
  .childBtnAdd {
    padding: 0 18px;
    height: 32px;
    line-height: 32px;
    background: #f5f7fa;
    border: 1px solid #9ebbf7;
    box-shadow: 0px 3px 3px 0px rgba(0, 0, 0, 0.06);
    border-radius: 4px;
    font-size: 14px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: #2d67e3;
    cursor: pointer;
  }

  .childTitle {
    line-height: 40px;
  }
}
</style>
