_keyword.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <template>
  2. <div class="container" id="searchResult">
  3. <detail-brand></detail-brand>
  4. <result-title :keyword="key" :page="nowPage"></result-title>
  5. <kind @kindFilterEvent="listenKindFilter"
  6. @brandFilterEvent="listenBrandFilter"
  7. ></kind>
  8. <good-list @pageEvent="listenPage"
  9. @sortEvent="listenSort"
  10. @filterPriceEvent="listenPriceFilter"
  11. ></good-list>
  12. </div>
  13. </template>
  14. <script>
  15. import { GoodList, Kind, ResultTitle, DetailBrand } from '~components/pcb'
  16. export default{
  17. layout: 'pcb',
  18. data () {
  19. return {
  20. key: this.$route.query.w,
  21. pageSize: 15,
  22. nowPage: 1,
  23. sorting: {},
  24. filter: {},
  25. paramJSON: {}
  26. }
  27. },
  28. fetch ({store, route}) {
  29. return Promise.all([
  30. store.dispatch('pcb/searchForKinds', {collectedField: 'goods_kind', keyword: route.query.w, filters: {}}),
  31. store.dispatch('pcb/searchForBrands', {collectedField: 'goods_brand', keyword: route.query.w, filters: {}}),
  32. store.dispatch('pcb/searchForList', {count: 15, filter: {}, keyword: route.query.w, page: 1, sorting: {}})
  33. ])
  34. },
  35. watch: {
  36. '$route.query.w': {
  37. handler: function (val) {
  38. this.key = val
  39. this.reloadAll()
  40. },
  41. immediate: false
  42. }
  43. },
  44. components: {
  45. ResultTitle,
  46. Kind,
  47. GoodList,
  48. DetailBrand
  49. },
  50. methods: {
  51. reloadAll: function () {
  52. this.filter = {}
  53. this.sorting = {}
  54. this.paramJSON = {}
  55. this.reloadList()
  56. this.reloadKind()
  57. this.reloadBrand()
  58. },
  59. reloadList: function () {
  60. if (this.sorting === {}) {
  61. this.sorting = {}
  62. }
  63. this.$store.dispatch('pcb/searchForList', {count: this.pageSize, filter: this.filter, keyword: this.$route.query.w, page: this.nowPage, sorting: this.sorting})
  64. },
  65. reloadKind: function () {
  66. if (!this.filter.goods_kindId) {
  67. this.$store.dispatch('pcb/searchForKinds', {collectedField: 'goods_kind', keyword: this.$route.query.w, filters: this.paramJSON})
  68. }
  69. },
  70. reloadBrand: function () {
  71. if (!this.filter.goods_brandId) {
  72. this.$store.dispatch('pcb/searchForBrands', {collectedField: 'goods_brand', keyword: this.$route.query.w, filters: this.paramJSON})
  73. }
  74. },
  75. listenPage: function (nPage) {
  76. this.nowPage = nPage
  77. this.reloadList()
  78. },
  79. listenSort: function (sortType) {
  80. this.sorting = sortType
  81. this.reloadList()
  82. },
  83. listenPriceFilter: function (filterType) {
  84. if (filterType.goods_minpricermb) {
  85. this.filter.goods_minpricermb = filterType.goods_minpricermb
  86. } else {
  87. delete this.filter.goods_minpricermb
  88. }
  89. if (filterType.goods_maxpricermb) {
  90. this.filter.goods_maxpricermb = filterType.goods_maxpricermb
  91. } else {
  92. delete this.filter.goods_maxpricermb
  93. }
  94. this.reloadList()
  95. },
  96. listenKindFilter: function (kindarr) {
  97. this.nowPage = 1
  98. if (kindarr.length === 0) {
  99. delete this.filter.goods_kindId
  100. delete this.paramJSON.goods_kindid
  101. this.reloadKind()
  102. this.reloadBrand()
  103. this.reloadList()
  104. } else {
  105. this.filter.goods_kindId = kindarr
  106. this.paramJSON.goods_kindid = kindarr
  107. this.reloadBrand()
  108. this.reloadList()
  109. }
  110. },
  111. listenBrandFilter: function (brandarr) {
  112. this.nowPage = 1
  113. if (brandarr.length === 0) {
  114. delete this.filter.goods_brandId
  115. delete this.paramJSON.goods_brandid
  116. this.reloadKind()
  117. this.reloadBrand()
  118. this.reloadList()
  119. } else {
  120. this.filter.goods_brandId = brandarr
  121. this.paramJSON.goods_brandid = brandarr
  122. this.reloadKind()
  123. this.reloadList()
  124. }
  125. }
  126. }
  127. }
  128. </script>