_keyword.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  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')">现货({{stockTotal}}条)</span>
  14. <span class="inline-block" :class="{active: resultType == 'forward'}" @click="setResultType('forward')">期货({{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.reloadAll()
  82. },
  83. immediate: false
  84. }
  85. },
  86. computed: {
  87. // 搜索类型
  88. searchType () {
  89. return this.$route.query.type || 'component'
  90. },
  91. // 搜索结果
  92. goods () {
  93. return this.$store.state.searchData.searchList.listNew.data
  94. },
  95. // 现货数量
  96. stockTotal () {
  97. return this.goods.stock ? this.goods.stock.total : 0
  98. },
  99. // 期货数量
  100. futureTotal () {
  101. return this.goods.futures ? this.goods.futures.total : 0
  102. },
  103. // 当前分页数
  104. currentCount () {
  105. if (this.goods.content) {
  106. return this.goods.total
  107. } else {
  108. return this.resultType === 'current' ? this.stockTotal : this.futureTotal
  109. }
  110. },
  111. // 总数
  112. count () {
  113. if (this.goods.content) {
  114. return this.goods.total
  115. } else {
  116. return this.stockTotal + this.futureTotal
  117. }
  118. }
  119. },
  120. methods: {
  121. initParams: function () {
  122. this.resultType = 'current'
  123. this.nowPage = 1
  124. },
  125. reloadAll: function () {
  126. this.filter = {}
  127. this.sorting = {}
  128. this.paramJSON = {}
  129. this.reloadList()
  130. // this.reloadKind()
  131. // this.reloadBrand()
  132. // this.reloadStoreType()
  133. // this.reloadCrname()
  134. },
  135. reloadList: function () {
  136. let params = {
  137. count: this.pageSize,
  138. keyword: this.$route.query.w,
  139. page: this.nowPage,
  140. type: this.searchType
  141. }
  142. if (this.searchType === 'component') {
  143. params.filter = this.filter
  144. params.sorting = this.sorting
  145. }
  146. return this.$store.dispatch('searchData/searchForListNew', params)
  147. },
  148. // reloadKind: function () {
  149. // if (!this.filter.goods_kindId) {
  150. // this.$store.dispatch('searchData/searchForKinds', {collectList: 'goods_kind', keyword: this.$route.query.w, paramJSON: this.paramJSON})
  151. // }
  152. // },
  153. // reloadBrand: function () {
  154. // if (!this.filter.goods_brandId) {
  155. // this.$store.dispatch('searchData/searchForBrands', {collectList: 'goods_brand', keyword: this.$route.query.w, paramJSON: this.paramJSON})
  156. // }
  157. // },
  158. // reloadStoreType: function () {
  159. // if (!this.filter.goods_store_type) {
  160. // this.$store.dispatch('searchData/searchForStoreType', {collectList: 'goods_store_type', keyword: this.$route.query.w, paramJSON: this.paramJSON})
  161. // }
  162. // },
  163. // reloadCrname: function () {
  164. // if (!this.filter.goods_crname) {
  165. // this.$store.dispatch('searchData/searchForCrname', {collectList: 'goods_crname', keyword: this.$route.query.w, paramJSON: this.paramJSON})
  166. // }
  167. // },
  168. listenPage: function (nPage) {
  169. this.nowPage = nPage
  170. return this.reloadList()
  171. },
  172. listenSort: function (sortType) {
  173. this.sorting = sortType
  174. this.reloadList()
  175. },
  176. listenPriceFilter: function (filterType) {
  177. if (filterType.goods_minpricermb) {
  178. this.filter.goods_minpricermb = filterType.goods_minpricermb
  179. } else {
  180. delete this.filter.goods_minpricermb
  181. }
  182. if (filterType.goods_maxpricermb) {
  183. this.filter.goods_maxpricermb = filterType.goods_maxpricermb
  184. } else {
  185. delete this.filter.goods_maxpricermb
  186. }
  187. this.reloadList()
  188. },
  189. // listenKindFilter: function (kindarr) {
  190. // this.nowPage = 1
  191. // if (kindarr.length === 0) {
  192. // delete this.filter.goods_kindId
  193. // delete this.paramJSON.goods_kindid
  194. // this.reloadKind()
  195. // this.reloadBrand()
  196. // this.reloadList()
  197. // this.reloadStoreType()
  198. // this.reloadCrname()
  199. // } else {
  200. // this.filter.goods_kindId = kindarr
  201. // this.paramJSON.goods_kindid = kindarr
  202. // this.reloadBrand()
  203. // this.reloadList()
  204. // this.reloadStoreType()
  205. // this.reloadCrname()
  206. // }
  207. // },
  208. // listenBrandFilter: function (brandarr) {
  209. // this.nowPage = 1
  210. // if (brandarr.length === 0) {
  211. // delete this.filter.goods_brandId
  212. // delete this.paramJSON.goods_brandid
  213. // this.reloadKind()
  214. // this.reloadBrand()
  215. // this.reloadList()
  216. // this.reloadStoreType()
  217. // this.reloadCrname()
  218. // } else {
  219. // this.filter.goods_brandId = brandarr
  220. // this.paramJSON.goods_brandid = brandarr
  221. // this.reloadKind()
  222. // this.reloadList()
  223. // this.reloadStoreType()
  224. // this.reloadCrname()
  225. // }
  226. // },
  227. // listenTypeFilter: function (typearr) {
  228. // this.nowPage = 1
  229. // if (typearr.length === 0) {
  230. // delete this.filter.goods_store_type
  231. // delete this.paramJSON.goods_store_type
  232. // this.reloadKind()
  233. // this.reloadBrand()
  234. // this.reloadList()
  235. // this.reloadCrname()
  236. // } else {
  237. // this.filter.goods_store_type = typearr
  238. // this.paramJSON.goods_store_type = typearr
  239. // this.reloadKind()
  240. // this.reloadBrand()
  241. // this.reloadList()
  242. // this.reloadCrname()
  243. // }
  244. // },
  245. // listenCrnameFilter: function (crnamearr) {
  246. // this.nowPage = 1
  247. // if (crnamearr.length === 0) {
  248. // delete this.filter.goods_crname
  249. // delete this.paramJSON.goods_crname
  250. // this.reloadKind()
  251. // this.reloadBrand()
  252. // this.reloadList()
  253. // this.reloadStoreType()
  254. // } else {
  255. // this.filter.goods_crname = crnamearr
  256. // this.paramJSON.goods_crname = crnamearr
  257. // this.reloadKind()
  258. // this.reloadBrand()
  259. // this.reloadList()
  260. // this.reloadStoreType()
  261. // }
  262. // },
  263. // listenCrnameFlag: function (obj) {
  264. // if (obj.rmb_click_flag && obj.usd_click_flag) {
  265. // this.crname_click_flag.rmb_click_flag = false
  266. // this.crname_click_flag.usd_click_flag = false
  267. // } else {
  268. // this.crname_click_flag.rmb_click_flag = obj.rmb_click_flag
  269. // this.crname_click_flag.usd_click_flag = obj.usd_click_flag
  270. // }
  271. // },
  272. setResultType: function (resultType) {
  273. if (this.nowPage > 1) {
  274. this.listenPage(1).then(() => {
  275. this.resultType = resultType
  276. })
  277. } else {
  278. this.resultType = resultType
  279. }
  280. // this.listenPage(1).then(() => {
  281. // this.resultType = resultType
  282. // })
  283. }
  284. }
  285. }
  286. </script>
  287. <style lang="scss" scoped>
  288. #searchResult {
  289. margin-bottom: 36px;
  290. .search-result-type {
  291. border-bottom: 2px solid #2e91f0;
  292. span {
  293. padding: 12px 37px;
  294. color: #666;
  295. font-size: 14px;
  296. border: 1px solid #ccc;
  297. cursor: pointer;
  298. &.active {
  299. color: #fff;
  300. background: #2e91f0;
  301. border-color: #2e91f0;
  302. }
  303. }
  304. }
  305. .empty {
  306. text-align: center;
  307. height: 200px;
  308. line-height: 200px;
  309. border: 1px solid #e8e8e8;
  310. margin-bottom: 10px;
  311. span {
  312. color: #999;
  313. margin-left: 10px;
  314. }
  315. }
  316. }
  317. </style>