_keyword.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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. <supplier-list></supplier-list>
  26. </template>
  27. </div>
  28. </template>
  29. <script>
  30. import { GoodList, ResultTitle, ForwardGoodsList, SupplierList } 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. SupplierList
  60. // DetailBrand
  61. },
  62. watch: {
  63. '$route.query': {
  64. handler: function (val) {
  65. this.key = val.w
  66. this.reloadAll()
  67. },
  68. immediate: false
  69. }
  70. },
  71. computed: {
  72. searchType () {
  73. return this.$route.query.type || 'component'
  74. },
  75. goods () {
  76. return this.$store.state.searchData.searchList.listNew.data
  77. },
  78. stockTotal () {
  79. return this.goods.stock.total || 0
  80. },
  81. futureTotal () {
  82. return this.goods.futures.total || 0
  83. },
  84. count () {
  85. return this.stockTotal + this.futureTotal
  86. }
  87. },
  88. methods: {
  89. reloadAll: function () {
  90. this.filter = {}
  91. this.sorting = {}
  92. this.paramJSON = {}
  93. this.reloadList()
  94. // this.reloadKind()
  95. // this.reloadBrand()
  96. // this.reloadStoreType()
  97. // this.reloadCrname()
  98. },
  99. reloadList: function () {
  100. if (this.sorting === {}) {
  101. this.sorting = {}
  102. }
  103. 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})
  104. },
  105. // reloadKind: function () {
  106. // if (!this.filter.goods_kindId) {
  107. // this.$store.dispatch('searchData/searchForKinds', {collectList: 'goods_kind', keyword: this.$route.query.w, paramJSON: this.paramJSON})
  108. // }
  109. // },
  110. // reloadBrand: function () {
  111. // if (!this.filter.goods_brandId) {
  112. // this.$store.dispatch('searchData/searchForBrands', {collectList: 'goods_brand', keyword: this.$route.query.w, paramJSON: this.paramJSON})
  113. // }
  114. // },
  115. // reloadStoreType: function () {
  116. // if (!this.filter.goods_store_type) {
  117. // this.$store.dispatch('searchData/searchForStoreType', {collectList: 'goods_store_type', keyword: this.$route.query.w, paramJSON: this.paramJSON})
  118. // }
  119. // },
  120. // reloadCrname: function () {
  121. // if (!this.filter.goods_crname) {
  122. // this.$store.dispatch('searchData/searchForCrname', {collectList: 'goods_crname', keyword: this.$route.query.w, paramJSON: this.paramJSON})
  123. // }
  124. // },
  125. listenPage: function (nPage) {
  126. this.nowPage = nPage
  127. this.reloadList()
  128. },
  129. listenSort: function (sortType) {
  130. this.sorting = sortType
  131. this.reloadList()
  132. },
  133. listenPriceFilter: function (filterType) {
  134. if (filterType.goods_minpricermb) {
  135. this.filter.goods_minpricermb = filterType.goods_minpricermb
  136. } else {
  137. delete this.filter.goods_minpricermb
  138. }
  139. if (filterType.goods_maxpricermb) {
  140. this.filter.goods_maxpricermb = filterType.goods_maxpricermb
  141. } else {
  142. delete this.filter.goods_maxpricermb
  143. }
  144. this.reloadList()
  145. },
  146. // listenKindFilter: function (kindarr) {
  147. // this.nowPage = 1
  148. // if (kindarr.length === 0) {
  149. // delete this.filter.goods_kindId
  150. // delete this.paramJSON.goods_kindid
  151. // this.reloadKind()
  152. // this.reloadBrand()
  153. // this.reloadList()
  154. // this.reloadStoreType()
  155. // this.reloadCrname()
  156. // } else {
  157. // this.filter.goods_kindId = kindarr
  158. // this.paramJSON.goods_kindid = kindarr
  159. // this.reloadBrand()
  160. // this.reloadList()
  161. // this.reloadStoreType()
  162. // this.reloadCrname()
  163. // }
  164. // },
  165. // listenBrandFilter: function (brandarr) {
  166. // this.nowPage = 1
  167. // if (brandarr.length === 0) {
  168. // delete this.filter.goods_brandId
  169. // delete this.paramJSON.goods_brandid
  170. // this.reloadKind()
  171. // this.reloadBrand()
  172. // this.reloadList()
  173. // this.reloadStoreType()
  174. // this.reloadCrname()
  175. // } else {
  176. // this.filter.goods_brandId = brandarr
  177. // this.paramJSON.goods_brandid = brandarr
  178. // this.reloadKind()
  179. // this.reloadList()
  180. // this.reloadStoreType()
  181. // this.reloadCrname()
  182. // }
  183. // },
  184. // listenTypeFilter: function (typearr) {
  185. // this.nowPage = 1
  186. // if (typearr.length === 0) {
  187. // delete this.filter.goods_store_type
  188. // delete this.paramJSON.goods_store_type
  189. // this.reloadKind()
  190. // this.reloadBrand()
  191. // this.reloadList()
  192. // this.reloadCrname()
  193. // } else {
  194. // this.filter.goods_store_type = typearr
  195. // this.paramJSON.goods_store_type = typearr
  196. // this.reloadKind()
  197. // this.reloadBrand()
  198. // this.reloadList()
  199. // this.reloadCrname()
  200. // }
  201. // },
  202. // listenCrnameFilter: function (crnamearr) {
  203. // this.nowPage = 1
  204. // if (crnamearr.length === 0) {
  205. // delete this.filter.goods_crname
  206. // delete this.paramJSON.goods_crname
  207. // this.reloadKind()
  208. // this.reloadBrand()
  209. // this.reloadList()
  210. // this.reloadStoreType()
  211. // } else {
  212. // this.filter.goods_crname = crnamearr
  213. // this.paramJSON.goods_crname = crnamearr
  214. // this.reloadKind()
  215. // this.reloadBrand()
  216. // this.reloadList()
  217. // this.reloadStoreType()
  218. // }
  219. // },
  220. // listenCrnameFlag: function (obj) {
  221. // if (obj.rmb_click_flag && obj.usd_click_flag) {
  222. // this.crname_click_flag.rmb_click_flag = false
  223. // this.crname_click_flag.usd_click_flag = false
  224. // } else {
  225. // this.crname_click_flag.rmb_click_flag = obj.rmb_click_flag
  226. // this.crname_click_flag.usd_click_flag = obj.usd_click_flag
  227. // }
  228. // },
  229. setResultType: function (resultType) {
  230. this.resultType = resultType
  231. }
  232. }
  233. }
  234. </script>
  235. <style lang="scss" scoped>
  236. .search-result-type {
  237. border-bottom: 2px solid #2e91f0;
  238. span {
  239. padding: 12px 37px;
  240. color: #666;
  241. font-size: 14px;
  242. border: 1px solid #ccc;
  243. cursor: pointer;
  244. &.active {
  245. color: #fff;
  246. background: #2e91f0;
  247. border-color: #2e91f0;
  248. }
  249. }
  250. }
  251. </style>