CustomerSearcher.vue 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <template lang="pug">
  2. .customer-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. customers: 'getCustomers'
  11. }),
  12. methods: {
  13. initFuse() {
  14. if (this.fuse) {
  15. this.fuse.setCollection(this.customers)
  16. return
  17. }
  18. this.fuse = new Fuse(this.customers, {
  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. 'emainl',
  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. customers() {
  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. .customer-searcher
  63. width: calc(100% - 30px)
  64. height: 35px
  65. margin: 15px
  66. input
  67. width: 100%
  68. height: inherit
  69. text-align: center
  70. border-radius: 0
  71. font:
  72. size: 11pt
  73. style: normal
  74. weight: bold
  75. </style>