<template>
  <van-config-provider :theme-vars="themeVars">
    <div class="search_box">
      <van-search
        v-model="values"
        :placeholder="placeholder"
        shape="round"
        @clear="onClear"
        @search="onSearch"
        :style="{ width: isSx ? '90%' : '100%' }"
      >
      </van-search>
      <!-- 是否有筛选条件 -->
      <div class="sx_box" v-if="isSx" @click="onClickSx">
        <van-icon name="bars" size="8vw"></van-icon>
      </div>
    </div>
  </van-config-provider>
</template>

<script>
export default {
  name: "search",
  props: ["placeholder", "modelValue", "isSx"],
  data() {
    return {
      isChecked: 0,
      themeType: getStorage("themeSetting"),
      themeVars: {},
      values: "",
    };
  },
  watch: {
    modelValue: {
      handler(val) {
        this.$nextTick(() => {
          this.values = val;
        });
      },
      immediate: true,
      deep: true,
    },
  },
  mounted() {
    this.themeVars = {
      fieldInputTextColor: this.themeType == "light" ? "#333" : "#333",
      // fieldInputTextColor: this.themeType == "light" ? "#333" : "#fff",
      SearchContentBackgroundColor:
        this.themeType == "light" ? "#f7f8fa" : "#f7f8fa",
      // SearchContentBackgroundColor: this.themeType == "light" ? "#f7f8fa" : "#092556",
    };
  },
  methods: {
    //确认筛选
    onSearch(e) {
      this.$emit("update:modelValue", this.values);
    },
    //清除
    onClear() {
      this.$emit("update:modelValue", "");
    },
    //打开筛选条件
    onClickSx() {
      this.$emit("update:sx", true);
    },
  },
};
</script>

<style lang="scss" scoped>
@import "../assets/styles/mixin.scss";

.search_box {
  @include font_size($font_medium_s);
  display: flex;
  width: 100%;
  z-index: 1;
}
.sx_box {
  width: 10%;
  @include font_color($font-color-theme);
  text-align: center;
  padding: 3.1vw 2vw 2vw 0;
}
::v-deep .van-search {
  background: none;
  padding: 10px;
}
</style>
