_keyword.vue 7.9 KB

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