_keyword.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <template>
  2. <div class="container" id="searchResult">
  3. <result-title :keyword="key"></result-title>
  4. <kind @kindFilterEvent="listenKindFilter"
  5. @brandFilterEvent="listenBrandFilter"
  6. @typeFilterEvent="listenTypeFilter"
  7. @crnameFilterEvent="listenCrnameFilter"
  8. ></kind>
  9. <good-list @pageEvent="listenPage" @sortEvent="listenSort" @filterPriceEvent="listenPriceFilter"></good-list>
  10. </div>
  11. </template>
  12. <script>
  13. import { GoodList, Kind, ResultTitle } from '~components/search'
  14. export default{
  15. layout: 'main',
  16. data () {
  17. return {
  18. key: this.$route.query.w,
  19. pageSize: 15,
  20. nowPage: 1,
  21. sorting: {'GO_RESERVE': 'DESC', 'GO_SEARCH': 'DESC'},
  22. filter: {},
  23. paramJSON: {}
  24. }
  25. },
  26. fetch ({store, route}) {
  27. return Promise.all([
  28. store.dispatch('searchData/searchForKinds', {collectList: 'goods_kind', keyword: route.query.w, paramJSON: {}}),
  29. store.dispatch('searchData/searchForBrands', {collectList: 'goods_brand', keyword: route.query.w, paramJSON: {}}),
  30. store.dispatch('searchData/searchForList', {count: this.pageSize, filter: this.filter, keyword: route.query.w, page: this.nowPage, sorting: this.sorting}),
  31. store.dispatch('searchData/searchForStoreType', {collectList: 'goods_store_type', keyword: route.query.w, paramJSON: {}}),
  32. store.dispatch('searchData/searchForCrname', {collectList: 'goods_crname', keyword: route.query.w, paramJSON: {}})
  33. ])
  34. },
  35. components: {
  36. ResultTitle,
  37. Kind,
  38. GoodList
  39. },
  40. methods: {
  41. reloadList: function () {
  42. if (this.sorting === {}) {
  43. this.sorting = {'GO_RESERVE': 'DESC', 'GO_SEARCH': 'DESC'}
  44. }
  45. this.$store.dispatch('searchData/searchForList', {count: this.pageSize, filter: this.filter, keyword: this.$route.query.w, page: this.nowPage, sorting: this.sorting})
  46. },
  47. reloadKind: function () {
  48. this.$store.dispatch('searchData/searchForKinds', {collectList: 'goods_kind', keyword: this.$route.query.w, paramJSON: this.paramJSON})
  49. },
  50. reloadBrand: function () {
  51. this.$store.dispatch('searchData/searchForBrands', {collectList: 'goods_brand', keyword: this.$route.query.w, paramJSON: this.paramJSON})
  52. },
  53. reloadStoreType: function () {
  54. this.$store.dispatch('searchData/searchForStoreType', {collectList: 'goods_store_type', keyword: this.$route.query.w, paramJSON: this.paramJSON})
  55. },
  56. reloadCrname: function () {
  57. this.$store.dispatch('searchData/searchForCrname', {collectList: 'goods_crname', keyword: this.$route.query.w, paramJSON: this.paramJSON})
  58. },
  59. listenPage: function (nPage) {
  60. this.nowPage = nPage
  61. this.reloadList()
  62. },
  63. listenSort: function (sortType) {
  64. this.sorting = sortType
  65. this.reloadList()
  66. },
  67. listenPriceFilter: function (filterType) {
  68. if (filterType.goods_minpricermb) {
  69. this.filter.goods_minpricermb = filterType.goods_minpricermb
  70. } else {
  71. delete this.filter.goods_minpricermb
  72. }
  73. if (filterType.goods_maxpricermb) {
  74. this.filter.goods_maxpricermb = filterType.goods_maxpricermb
  75. } else {
  76. delete this.filter.goods_maxpricermb
  77. }
  78. this.reloadList()
  79. },
  80. listenKindFilter: function (kindarr) {
  81. console.log(kindarr.length)
  82. if (kindarr.length === 0) {
  83. delete this.filter.goods_kindId
  84. delete this.paramJSON.goods_kindid
  85. this.reloadBrand()
  86. this.reloadList()
  87. this.reloadStoreType()
  88. this.reloadCrname()
  89. } else {
  90. this.filter.goods_kindId = kindarr
  91. this.paramJSON.goods_kindid = kindarr
  92. this.reloadBrand()
  93. this.reloadList()
  94. this.reloadStoreType()
  95. this.reloadCrname()
  96. }
  97. },
  98. listenBrandFilter: function (brandarr) {
  99. if (brandarr.length === 0) {
  100. delete this.filter.goods_brandId
  101. delete this.paramJSON.goods_brandid
  102. this.reloadKind()
  103. this.reloadList()
  104. this.reloadStoreType()
  105. this.reloadCrname()
  106. } else {
  107. this.filter.goods_brandId = brandarr
  108. this.paramJSON.goods_brandid = brandarr
  109. this.reloadKind()
  110. this.reloadList()
  111. this.reloadStoreType()
  112. this.reloadCrname()
  113. }
  114. },
  115. listenTypeFilter: function (typearr) {
  116. if (typearr.length === 0) {
  117. delete this.filter.goods_store_type
  118. delete this.paramJSON.goods_store_type
  119. this.reloadKind()
  120. this.reloadBrand()
  121. this.reloadList()
  122. this.reloadCrname()
  123. } else {
  124. this.filter.goods_store_type = typearr
  125. this.paramJSON.goods_store_type = typearr
  126. this.reloadKind()
  127. this.reloadBrand()
  128. this.reloadList()
  129. this.reloadCrname()
  130. }
  131. },
  132. listenCrnameFilter: function (crnamearr) {
  133. if (crnamearr.length === 0) {
  134. delete this.filter.goods_crname
  135. delete this.paramJSON.goods_crname
  136. this.reloadKind()
  137. this.reloadBrand()
  138. this.reloadList()
  139. this.reloadStoreType()
  140. } else {
  141. this.filter.goods_crname = crnamearr
  142. this.paramJSON.goods_crname = crnamearr
  143. this.reloadKind()
  144. this.reloadBrand()
  145. this.reloadList()
  146. this.reloadStoreType()
  147. }
  148. }
  149. }
  150. }
  151. </script>