_keyword.vue 7.7 KB

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