PartnerSearcher.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <template lang="pug">
  2. .partner-searcher
  3. input(type="text" placeholder="Buscar un cliente" v-model="search")
  4. </template>
  5. <script>
  6. import Fuse from 'fuse.js'
  7. import { mapGetters, mapActions } from 'vuex'
  8. export default {
  9. computed: mapGetters([
  10. 'partners'
  11. ]),
  12. methods: {
  13. initFuse() {
  14. if (this.fuse) {
  15. this.fuse.setCollection(this.partners)
  16. return
  17. }
  18. this.fuse = new Fuse(this.partners, {
  19. shouldSort: true,
  20. threshold: 0.4,
  21. location: 0,
  22. distance: 100,
  23. maxPatternLength: 32,
  24. minMatchCharLength: 1,
  25. keys: [
  26. 'name',
  27. 'phone',
  28. 'mobile',
  29. 'email',
  30. 'categories.name'
  31. ]
  32. })
  33. },
  34. fuzzySearch() {
  35. this.results = this.fuse.search(this.search)
  36. },
  37. ...mapActions([
  38. 'filterCustomers'
  39. ])
  40. },
  41. watch: {
  42. partners() {
  43. this.initFuse()
  44. },
  45. search() {
  46. this.fuzzySearch()
  47. },
  48. results() {
  49. this.filterCustomers(this.results)
  50. }
  51. },
  52. data() {
  53. return {
  54. search: '',
  55. fuse: null,
  56. results: []
  57. }
  58. }
  59. }
  60. </script>
  61. <style lang="sass">
  62. .partner-searcher
  63. width: 100%
  64. height: 35px
  65. input
  66. width: 100%
  67. height: inherit
  68. text-align: center
  69. border-radius: 0
  70. font:
  71. size: 11pt
  72. style: normal
  73. weight: bold
  74. </style>