SearchBox.js 1.13 KB
// components/SearchBox/SearchBox.js
import {componentsMixin } from '../../mixins/index';
Component({
  behaviors: [componentsMixin],
  /**
   * 组件的属性列表
   */
  properties: {
    placeholder: {
      type: String,
      value: "请输入搜索内容",
    },
    value: {
      type: String,
      value: "",
      observer(n) {
        this.setData({
          inputValue: n,
        });
      },
    },
    searchType: {
      type: Number,
      value: 1,
    },
    couponDetails: Boolean,
  },

  /**
   * 组件的初始数据
   */
  data: {
    inputValue: "",
  },

  /**
   * 组件的方法列表
   */
  methods: {
    input(e) {
      let { value } = e.detail;
      this.setData({
        inputValue: value,
      });
    },
    blur(e) {
      let { inputValue } = this.data;
      this.setData({
        inputValue,
      });
    },
    clear() {
      this.setData({
        inputValue: "",
      });
    },
    confirm(e) {
      let { value } = e.detail;
      this.triggerEvent("search", value);
    },
    search(e) {
      let { value } = e.currentTarget.dataset;
      this.triggerEvent("search", value);
    },
  },
});