index.tsx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import { Button, Icon, Search } from "vant";
  2. import { defineComponent, PropType } from "vue";
  3. import styles from './index.module.less'
  4. import iconSearch from '@common/images/icon_search.png';
  5. import iconFilter from '@common/images/icon_filter.png';
  6. type inputBackground = 'default' | 'white'
  7. export default defineComponent({
  8. name: "ColSearch",
  9. props: {
  10. modelValue: {
  11. type: String,
  12. default: ''
  13. },
  14. showAction: {
  15. type: Boolean,
  16. default: false
  17. },
  18. placeholder: {
  19. type: String,
  20. default: '请输入搜索关键词'
  21. },
  22. background: {
  23. type: String,
  24. default: '#fff'
  25. },
  26. inputBackground: {
  27. type: String as PropType<inputBackground>,
  28. default: 'default'
  29. },
  30. onSearch: {
  31. type: Function,
  32. default: (val: string) => { }
  33. },
  34. onFilter: {
  35. type: Function,
  36. default: () => { }
  37. }
  38. },
  39. data() {
  40. return {
  41. search: ''
  42. }
  43. },
  44. mounted() {
  45. },
  46. render() {
  47. return (
  48. <Search class={[styles['col-search'], styles[this.inputBackground]]} v-model={this.search}
  49. background={this.background}
  50. showAction={this.showAction}
  51. shape="round"
  52. placeholder={this.placeholder}
  53. onSearch={(val: string) => { this.onSearch(val) }}
  54. v-slots={{
  55. 'left-icon': () => (<Icon name={iconSearch} size={16} />),
  56. 'right-icon': () => (<Button class={styles.searchBtn} round type="primary" size="mini" onClick={() => { this.onSearch(this.search) }}>搜索</Button>),
  57. action: () => (<Icon name={iconFilter} size={28} onClick={() => { this.onFilter }} />)
  58. }} />
  59. )
  60. }
  61. })