_keyword.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  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. <brand-detail :supBrandObj="goods.brand" v-if="searchType == 'brand' && goods.brand"></brand-detail>
  12. <div class="search-result-type" v-if="!goods.content">
  13. <span class="inline-block" :class="{active: resultType == 'current'}" @click="setResultType('current')">{{searchType === 'component' ? '现货' : '现货卖家'}}({{stockTotal}}条)</span>
  14. <span class="inline-block" :class="{active: resultType == 'forward'}" @click="setResultType('forward')">{{searchType === 'component' ? '期货' : '期货卖家'}}({{futureTotal}}条)</span>
  15. </div>
  16. <template v-if="searchType == 'component'">
  17. <good-list v-if="resultType === 'current'"
  18. @pageEvent="listenPage"
  19. @sortEvent="listenSort"
  20. @filterPriceEvent="listenPriceFilter"
  21. :crname_click_flag="crname_click_flag"
  22. ></good-list>
  23. <forward-goods-list v-else></forward-goods-list>
  24. </template>
  25. <template v-if="searchType == 'kind' || searchType == 'store' || (searchType == 'brand' && goods.brand)">
  26. <supplier-list :resultType="resultType"></supplier-list>
  27. </template>
  28. <template v-if="searchType == 'brand' && !goods.brand">
  29. <brand-list></brand-list>
  30. </template>
  31. <page :total="currentCount" :page-size="pageSize"
  32. :current="nowPage" @childEvent="listenPage"></page>
  33. <div class="empty" v-if="currentCount === 0">
  34. <img src="/images/all/empty-cart.png" alt="">
  35. <span>暂无搜索结果</span>
  36. </div>
  37. </div>
  38. </template>
  39. <script>
  40. import { GoodList, ResultTitle, ForwardGoodsList, SupplierList, BrandList } from '~components/search'
  41. import { BrandDetail } from '~components/product'
  42. import Page from '~components/common/page/pageComponent.vue'
  43. // import DetailBrand from '~components/search/DetailBrand.vue'
  44. export default{
  45. layout: 'main',
  46. data () {
  47. return {
  48. key: this.$route.query.w,
  49. pageSize: 10,
  50. nowPage: 1,
  51. sorting: {},
  52. filter: {},
  53. paramJSON: {},
  54. crname_click_flag: {
  55. rmb_click_flag: false,
  56. usd_click_flag: false
  57. },
  58. // 现货:current, 期货:forward
  59. resultType: 'current'
  60. }
  61. },
  62. fetch ({store, route}) {
  63. return Promise.all([
  64. store.dispatch('searchData/searchForListNew', {count: 10, keyword: route.query.w, page: 1, type: route.query.type || 'component'})
  65. ])
  66. },
  67. components: {
  68. ResultTitle,
  69. GoodList,
  70. ForwardGoodsList,
  71. SupplierList,
  72. Page,
  73. BrandList,
  74. BrandDetail
  75. // DetailBrand
  76. },
  77. watch: {
  78. '$route.query': {
  79. handler: function (val) {
  80. this.key = val.w
  81. this.nowPage = 1
  82. this.reloadAll()
  83. },
  84. immediate: false
  85. }
  86. },
  87. computed: {
  88. // 搜索类型
  89. searchType () {
  90. return this.$route.query.type || 'component'
  91. },
  92. // 搜索结果
  93. goods () {
  94. return this.$store.state.searchData.searchList.listNew.data
  95. },
  96. // 现货数量
  97. stockTotal () {
  98. return this.goods.stock ? this.goods.stock.total : 0
  99. },
  100. // 期货数量
  101. futureTotal () {
  102. return this.goods.futures ? this.goods.futures.total : 0
  103. },
  104. // 当前分页数
  105. currentCount () {
  106. if (this.goods.content) {
  107. return this.goods.total
  108. } else {
  109. return this.resultType === 'current' ? this.stockTotal : this.futureTotal
  110. }
  111. },
  112. // 总数
  113. count () {
  114. if (this.goods.content) {
  115. return this.goods.total
  116. } else {
  117. return this.stockTotal + this.futureTotal
  118. }
  119. }
  120. },
  121. methods: {
  122. initParams: function () {
  123. this.resultType = 'current'
  124. this.nowPage = 1
  125. },
  126. reloadAll: function () {
  127. this.filter = {}
  128. this.sorting = {}
  129. this.paramJSON = {}
  130. this.reloadList()
  131. this.nowPage = 1
  132. // this.reloadKind()
  133. // this.reloadBrand()
  134. // this.reloadStoreType()
  135. // this.reloadCrname()
  136. },
  137. reloadList: function () {
  138. let params = {
  139. count: this.pageSize,
  140. keyword: this.$route.query.w,
  141. page: this.nowPage,
  142. type: this.searchType
  143. }
  144. if (this.searchType === 'component') {
  145. params.filter = this.filter
  146. params.sorting = this.sorting
  147. }
  148. return this.$store.dispatch('searchData/searchForListNew', params)
  149. },
  150. // reloadKind: function () {
  151. // if (!this.filter.goods_kindId) {
  152. // this.$store.dispatch('searchData/searchForKinds', {collectList: 'goods_kind', keyword: this.$route.query.w, paramJSON: this.paramJSON})
  153. // }
  154. // },
  155. // reloadBrand: function () {
  156. // if (!this.filter.goods_brandId) {
  157. // this.$store.dispatch('searchData/searchForBrands', {collectList: 'goods_brand', keyword: this.$route.query.w, paramJSON: this.paramJSON})
  158. // }
  159. // },
  160. // reloadStoreType: function () {
  161. // if (!this.filter.goods_store_type) {
  162. // this.$store.dispatch('searchData/searchForStoreType', {collectList: 'goods_store_type', keyword: this.$route.query.w, paramJSON: this.paramJSON})
  163. // }
  164. // },
  165. // reloadCrname: function () {
  166. // if (!this.filter.goods_crname) {
  167. // this.$store.dispatch('searchData/searchForCrname', {collectList: 'goods_crname', keyword: this.$route.query.w, paramJSON: this.paramJSON})
  168. // }
  169. // },
  170. listenPage: function (nPage) {
  171. this.nowPage = nPage
  172. return this.reloadList()
  173. },
  174. listenSort: function (sortType) {
  175. this.sorting = sortType
  176. this.reloadList()
  177. },
  178. listenPriceFilter: function (filterType) {
  179. if (filterType.goods_minpricermb) {
  180. this.filter.goods_minpricermb = filterType.goods_minpricermb
  181. } else {
  182. delete this.filter.goods_minpricermb
  183. }
  184. if (filterType.goods_maxpricermb) {
  185. this.filter.goods_maxpricermb = filterType.goods_maxpricermb
  186. } else {
  187. delete this.filter.goods_maxpricermb
  188. }
  189. this.reloadList()
  190. },
  191. // listenKindFilter: function (kindarr) {
  192. // this.nowPage = 1
  193. // if (kindarr.length === 0) {
  194. // delete this.filter.goods_kindId
  195. // delete this.paramJSON.goods_kindid
  196. // this.reloadKind()
  197. // this.reloadBrand()
  198. // this.reloadList()
  199. // this.reloadStoreType()
  200. // this.reloadCrname()
  201. // } else {
  202. // this.filter.goods_kindId = kindarr
  203. // this.paramJSON.goods_kindid = kindarr
  204. // this.reloadBrand()
  205. // this.reloadList()
  206. // this.reloadStoreType()
  207. // this.reloadCrname()
  208. // }
  209. // },
  210. // listenBrandFilter: function (brandarr) {
  211. // this.nowPage = 1
  212. // if (brandarr.length === 0) {
  213. // delete this.filter.goods_brandId
  214. // delete this.paramJSON.goods_brandid
  215. // this.reloadKind()
  216. // this.reloadBrand()
  217. // this.reloadList()
  218. // this.reloadStoreType()
  219. // this.reloadCrname()
  220. // } else {
  221. // this.filter.goods_brandId = brandarr
  222. // this.paramJSON.goods_brandid = brandarr
  223. // this.reloadKind()
  224. // this.reloadList()
  225. // this.reloadStoreType()
  226. // this.reloadCrname()
  227. // }
  228. // },
  229. // listenTypeFilter: function (typearr) {
  230. // this.nowPage = 1
  231. // if (typearr.length === 0) {
  232. // delete this.filter.goods_store_type
  233. // delete this.paramJSON.goods_store_type
  234. // this.reloadKind()
  235. // this.reloadBrand()
  236. // this.reloadList()
  237. // this.reloadCrname()
  238. // } else {
  239. // this.filter.goods_store_type = typearr
  240. // this.paramJSON.goods_store_type = typearr
  241. // this.reloadKind()
  242. // this.reloadBrand()
  243. // this.reloadList()
  244. // this.reloadCrname()
  245. // }
  246. // },
  247. // listenCrnameFilter: function (crnamearr) {
  248. // this.nowPage = 1
  249. // if (crnamearr.length === 0) {
  250. // delete this.filter.goods_crname
  251. // delete this.paramJSON.goods_crname
  252. // this.reloadKind()
  253. // this.reloadBrand()
  254. // this.reloadList()
  255. // this.reloadStoreType()
  256. // } else {
  257. // this.filter.goods_crname = crnamearr
  258. // this.paramJSON.goods_crname = crnamearr
  259. // this.reloadKind()
  260. // this.reloadBrand()
  261. // this.reloadList()
  262. // this.reloadStoreType()
  263. // }
  264. // },
  265. // listenCrnameFlag: function (obj) {
  266. // if (obj.rmb_click_flag && obj.usd_click_flag) {
  267. // this.crname_click_flag.rmb_click_flag = false
  268. // this.crname_click_flag.usd_click_flag = false
  269. // } else {
  270. // this.crname_click_flag.rmb_click_flag = obj.rmb_click_flag
  271. // this.crname_click_flag.usd_click_flag = obj.usd_click_flag
  272. // }
  273. // },
  274. setResultType: function (resultType) {
  275. if (this.nowPage > 1) {
  276. this.listenPage(1).then(() => {
  277. this.resultType = resultType
  278. })
  279. } else {
  280. this.resultType = resultType
  281. }
  282. // this.listenPage(1).then(() => {
  283. // this.resultType = resultType
  284. // })
  285. }
  286. }
  287. }
  288. </script>
  289. <style lang="scss" scoped>
  290. #searchResult {
  291. margin-bottom: 36px;
  292. .search-result-type {
  293. border-bottom: 2px solid #2e91f0;
  294. span {
  295. padding: 12px 37px;
  296. color: #666;
  297. font-size: 14px;
  298. border: 1px solid #ccc;
  299. cursor: pointer;
  300. &.active {
  301. color: #fff;
  302. background: #2e91f0;
  303. border-color: #2e91f0;
  304. }
  305. }
  306. }
  307. .empty {
  308. text-align: center;
  309. height: 200px;
  310. line-height: 200px;
  311. border: 1px solid #e8e8e8;
  312. margin-bottom: 10px;
  313. span {
  314. color: #999;
  315. margin-left: 10px;
  316. }
  317. }
  318. }
  319. </style>