_key.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <template>
  2. <div class="mobile-search-goods mobile-content mobile-content-long">
  3. <search-header
  4. :placeholder="'请输入您要采购的型号'"
  5. :outerKeyword="outerKeyword"
  6. :useMatchRule="false"
  7. :expandClass="'normal'"
  8. :similarType="'code'"
  9. @searchAction="onSearch"></search-header>
  10. <ul>
  11. <li v-for="goods in goodsList">
  12. <component-item :item="goods" @cancatSeller="concatSeller"></component-item>
  13. </li>
  14. </ul>
  15. <link-user :infoObj="currentStoreInfo"
  16. :showLink="showLink"
  17. @closeAction="showLink = false"></link-user>
  18. <pull-up
  19. :allPage="allPage"
  20. :page="page"
  21. @pullUpAction="onPullUpAction"
  22. :searchMore="fetching"></pull-up>
  23. </div>
  24. </template>
  25. <script>
  26. import {LinkUser, SearchHeader} from '~components/mobile/base'
  27. import componentItem from '~components/mobile/search/componet-item'
  28. import { PullUp } from '~components/mobile/common'
  29. export default {
  30. layout: 'mobile',
  31. components: {
  32. LinkUser,
  33. SearchHeader,
  34. componentItem,
  35. PullUp
  36. },
  37. data () {
  38. return {
  39. outerKeyword: '',
  40. currentStoreInfo: {},
  41. showLink: false,
  42. page: 1,
  43. goodsList: []
  44. }
  45. },
  46. fetch ({ store, params }) {
  47. return Promise.all([
  48. store.dispatch('searchData/searchForListNew', {count: 10, keyword: params.key, page: 1, type: 'component'})
  49. ])
  50. },
  51. watch: {
  52. '$route.params.key': {
  53. handler: function (val) {
  54. this.outerKeyword = val || ''
  55. },
  56. immediate: true
  57. },
  58. 'searchList': {
  59. handler: function (val) {
  60. if (val && val.stock && val.stock.content) {
  61. this.goodsList = [...this.goodsList, ...val.stock.content]
  62. }
  63. },
  64. immediate: true
  65. }
  66. },
  67. computed: {
  68. listData () {
  69. return this.$store.state.searchData.searchList.listNew
  70. },
  71. searchList () {
  72. return this.listData.data
  73. },
  74. fetching () {
  75. return this.listData.fetching
  76. },
  77. goods () {
  78. return this.searchList ? this.searchList.stock : {}
  79. },
  80. allPage () {
  81. return this.goods.total ? Math.ceil(this.goods.total / this.goods.size) : 0
  82. }
  83. },
  84. methods: {
  85. onSearch (searchObj) {
  86. if (searchObj.keyword) {
  87. this.$router.push(`/mobile/center/user/cart/${searchObj.keyword}`)
  88. }
  89. },
  90. concatSeller (item) {
  91. this.$http.get(`/api/store-service/stores?uuid=${item.storeid}`).then(res => {
  92. this.currentStoreInfo = res.data.enterprise
  93. this.showLink = true
  94. })
  95. },
  96. reloadList () {
  97. this.$store.dispatch('searchData/searchForListNew', {count: 10, keyword: this.$route.params.key, page: this.page, type: 'component'})
  98. },
  99. onPullUpAction () {
  100. this.page++
  101. this.reloadList()
  102. }
  103. }
  104. }
  105. </script>
  106. <style lang="scss" scoped>
  107. .mobile-search-goods {
  108. ul {
  109. li {
  110. border-bottom: .2rem solid #f1f3f6;
  111. }
  112. }
  113. }
  114. </style>