_keyword.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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. @typeFilterEvent="listenTypeFilter"
  8. @crnameFilterEvent="listenCrnameFilter"
  9. @crnameFlagEvent="listenCrnameFlag"
  10. ></kind>
  11. <good-list @pageEvent="listenPage"
  12. @sortEvent="listenSort"
  13. @filterPriceEvent="listenPriceFilter"
  14. :crname_click_flag="crname_click_flag"
  15. ></good-list>
  16. </div>
  17. </template>
  18. <script>
  19. import { GoodList, Kind, ResultTitle } from '~components/search'
  20. import DetailBrand from '~components/search/DetailBrand.vue'
  21. export default{
  22. layout: 'main',
  23. data () {
  24. return {
  25. key: this.$route.query.w,
  26. pageSize: 15,
  27. nowPage: 1,
  28. sorting: {},
  29. filter: {},
  30. paramJSON: {},
  31. crname_click_flag: {
  32. rmb_click_flag: false,
  33. usd_click_flag: false
  34. }
  35. }
  36. },
  37. fetch ({store, route}) {
  38. return Promise.all([
  39. store.dispatch('searchData/searchForKinds', {collectList: 'goods_kind', keyword: route.query.w, paramJSON: {}}),
  40. store.dispatch('searchData/searchForBrands', {collectList: 'goods_brand', keyword: route.query.w, paramJSON: {}}),
  41. store.dispatch('searchData/searchForList', {count: 15, filter: {}, keyword: route.query.w, page: 1, sorting: {}}),
  42. store.dispatch('searchData/searchForStoreType', {collectList: 'goods_store_type', keyword: route.query.w, paramJSON: {}}),
  43. store.dispatch('searchData/searchForCrname', {collectList: 'goods_crname', keyword: route.query.w, paramJSON: {}})
  44. ])
  45. },
  46. components: {
  47. ResultTitle,
  48. Kind,
  49. GoodList,
  50. DetailBrand
  51. },
  52. watch: {
  53. '$route.query.w': {
  54. handler: function (val) {
  55. this.key = val
  56. this.reloadAll()
  57. },
  58. immediate: false
  59. }
  60. },
  61. methods: {
  62. reloadAll: function () {
  63. this.filter = {}
  64. this.sorting = {}
  65. this.paramJSON = {}
  66. this.reloadList()
  67. this.reloadKind()
  68. this.reloadBrand()
  69. this.reloadStoreType()
  70. this.reloadCrname()
  71. },
  72. reloadList: function () {
  73. if (this.sorting === {}) {
  74. this.sorting = {}
  75. }
  76. this.$store.dispatch('searchData/searchForList', {count: this.pageSize, filter: this.filter, keyword: this.$route.query.w, page: this.nowPage, sorting: this.sorting})
  77. },
  78. reloadKind: function () {
  79. if (!this.filter.goods_kindId) {
  80. this.$store.dispatch('searchData/searchForKinds', {collectList: 'goods_kind', keyword: this.$route.query.w, paramJSON: this.paramJSON})
  81. }
  82. },
  83. reloadBrand: function () {
  84. if (!this.filter.goods_brandId) {
  85. this.$store.dispatch('searchData/searchForBrands', {collectList: 'goods_brand', keyword: this.$route.query.w, paramJSON: this.paramJSON})
  86. }
  87. },
  88. reloadStoreType: function () {
  89. if (!this.filter.goods_store_type) {
  90. this.$store.dispatch('searchData/searchForStoreType', {collectList: 'goods_store_type', keyword: this.$route.query.w, paramJSON: this.paramJSON})
  91. }
  92. },
  93. reloadCrname: function () {
  94. if (!this.filter.goods_crname) {
  95. this.$store.dispatch('searchData/searchForCrname', {collectList: 'goods_crname', keyword: this.$route.query.w, paramJSON: this.paramJSON})
  96. }
  97. },
  98. listenPage: function (nPage) {
  99. this.nowPage = nPage
  100. this.reloadList()
  101. },
  102. listenSort: function (sortType) {
  103. this.sorting = sortType
  104. this.reloadList()
  105. },
  106. listenPriceFilter: function (filterType) {
  107. if (filterType.goods_minpricermb) {
  108. this.filter.goods_minpricermb = filterType.goods_minpricermb
  109. } else {
  110. delete this.filter.goods_minpricermb
  111. }
  112. if (filterType.goods_maxpricermb) {
  113. this.filter.goods_maxpricermb = filterType.goods_maxpricermb
  114. } else {
  115. delete this.filter.goods_maxpricermb
  116. }
  117. this.reloadList()
  118. },
  119. listenKindFilter: function (kindarr) {
  120. this.nowPage = 1
  121. if (kindarr.length === 0) {
  122. delete this.filter.goods_kindId
  123. delete this.paramJSON.goods_kindid
  124. this.reloadKind()
  125. this.reloadBrand()
  126. this.reloadList()
  127. this.reloadStoreType()
  128. this.reloadCrname()
  129. } else {
  130. this.filter.goods_kindId = kindarr
  131. this.paramJSON.goods_kindid = kindarr
  132. this.reloadBrand()
  133. this.reloadList()
  134. this.reloadStoreType()
  135. this.reloadCrname()
  136. }
  137. },
  138. listenBrandFilter: function (brandarr) {
  139. this.nowPage = 1
  140. if (brandarr.length === 0) {
  141. delete this.filter.goods_brandId
  142. delete this.paramJSON.goods_brandid
  143. this.reloadKind()
  144. this.reloadBrand()
  145. this.reloadList()
  146. this.reloadStoreType()
  147. this.reloadCrname()
  148. } else {
  149. this.filter.goods_brandId = brandarr
  150. this.paramJSON.goods_brandid = brandarr
  151. this.reloadKind()
  152. this.reloadList()
  153. this.reloadStoreType()
  154. this.reloadCrname()
  155. }
  156. },
  157. listenTypeFilter: function (typearr) {
  158. this.nowPage = 1
  159. if (typearr.length === 0) {
  160. delete this.filter.goods_store_type
  161. delete this.paramJSON.goods_store_type
  162. this.reloadKind()
  163. this.reloadBrand()
  164. this.reloadList()
  165. this.reloadCrname()
  166. } else {
  167. this.filter.goods_store_type = typearr
  168. this.paramJSON.goods_store_type = typearr
  169. this.reloadKind()
  170. this.reloadBrand()
  171. this.reloadList()
  172. this.reloadCrname()
  173. }
  174. },
  175. listenCrnameFilter: function (crnamearr) {
  176. this.nowPage = 1
  177. if (crnamearr.length === 0) {
  178. delete this.filter.goods_crname
  179. delete this.paramJSON.goods_crname
  180. this.reloadKind()
  181. this.reloadBrand()
  182. this.reloadList()
  183. this.reloadStoreType()
  184. } else {
  185. this.filter.goods_crname = crnamearr
  186. this.paramJSON.goods_crname = crnamearr
  187. this.reloadKind()
  188. this.reloadBrand()
  189. this.reloadList()
  190. this.reloadStoreType()
  191. }
  192. },
  193. listenCrnameFlag: function (obj) {
  194. if (obj.rmb_click_flag && obj.usd_click_flag) {
  195. this.crname_click_flag.rmb_click_flag = false
  196. this.crname_click_flag.usd_click_flag = false
  197. } else {
  198. this.crname_click_flag.rmb_click_flag = obj.rmb_click_flag
  199. this.crname_click_flag.usd_click_flag = obj.usd_click_flag
  200. }
  201. }
  202. }
  203. }
  204. </script>