HomeCommonSearch.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <template>
  2. <view class="div">
  3. <view class="div header-holder"></view>
  4. <view :style="'height:'+navHeight+'px'"></view>
  5. <view class="product-list-header-wrapper">
  6. <title-header />
  7. <view class="div product-list-header" :class="'logo'">
  8. <view class="div slot" v-if='config' >
  9. <image mode="aspectFit" class="img" v-if="from=='home'" :src='config.site_mobile_logo'>
  10. <view class="div" v-else style="text-align: left"><text class="span iconfont" @click="goBack()">&#xe67f;</text></view>
  11. </view>
  12. <view class="div common-search">
  13. <input v-if="from=='search'" type="text" placeholder="请输入您要搜索的商品" v-model="keyword" @confirm="goSearch(keyword)">
  14. <input v-else-if="from=='store'" type="text" placeholder="搜索店铺商品" v-model="keyword" @confirm="goStoreGoods(keyword)">
  15. <input v-else type="text" placeholder="请输入您要搜索的商品" readonly="true" autocomplete="off" v-model="keyword" @click="onSearch">
  16. </view>
  17. <view class="div right iconfont popup-menu-area" @click="popupMore">&#xe680;<view v-if="showDot" class="div dot"></view></view>
  18. </view>
  19. </view>
  20. <header-more v-show="popupVisible" @blur.native="popupVisible = false" :showDot="showDot"></header-more>
  21. </view>
  22. </template>
  23. <script>
  24. import TitleHeader from '../../TitleHeader'
  25. import { urlencode } from '@/util/common'
  26. import { mapState, mapMutations } from 'vuex'
  27. import { getChatCount } from '../../../api/memberInstantMessage'
  28. import HeaderMore from '../../HeaderMore'
  29. export default {
  30. name:'HomeCommonSearch',
  31. components: {
  32. HeaderMore,
  33. TitleHeader
  34. },
  35. props: ['value', 'from'],
  36. watch: {
  37. value: function (value) {
  38. if (value) {
  39. this.keyword = value
  40. }
  41. }
  42. },
  43. data () {
  44. return {
  45. navHeight: 0,
  46. query:{},
  47. keyword: this.value ? this.value : '', // 关键字
  48. popupVisible: false,
  49. showDot: false
  50. }
  51. },
  52. mounted(){
  53. // #ifdef MP-WEIXIN
  54. this.navHeight = uni.getMenuButtonBoundingClientRect().top
  55. // #endif
  56. var pages = getCurrentPages()
  57. var page = pages[pages.length - 1]
  58. this.query = page.options
  59. if (this.isOnline) {
  60. getChatCount().then(res => {
  61. if (res.result) {
  62. if (!this.showDot) {
  63. this.showDot = {}
  64. }
  65. this.showDot['chat'] = true
  66. }
  67. })
  68. }
  69. },
  70. computed: {
  71. ...mapState({
  72. config: state => state.config.config,
  73. isOnline: state => state.member.isOnline,
  74. currenKeywords: state => state.homesearch.currenKeywords
  75. })
  76. },
  77. methods:{
  78. ...mapMutations({
  79. 'saveKeywords': 'saveKeywords'
  80. }),
  81. goBack(){uni.navigateBack({delta:1})},
  82. onSearch () {
  83. uni.navigateTo({url: '/pages/home/search/Search', params: { isFromHome: true } })
  84. },
  85. goStoreGoods () {
  86. uni.navigateTo({url: '/pages/home/storegoodslist/Goodslist'+'?'+urlencode( { id: this.query.id, keyword: this.keyword })})
  87. },
  88. goSearch (value) {
  89. if (value.replace(/\s+/g, '').length <= 0) {
  90. uni.showToast({icon:'none',title: '请输入您要搜索的关键字'})
  91. return false
  92. } else {
  93. this.keywords = value
  94. }
  95. if (value) {
  96. let data = this.utils.arrayFilter(this.currenKeywords.concat(value))
  97. this.saveKeywords(data)
  98. }
  99. uni.navigateTo({url: '/pages/home/goodslist/Goodslist'+'?'+urlencode( { keywords: this.keywords })})
  100. },
  101. popupMore () {
  102. if (!this.popupVisible) {
  103. this.popupVisible = true
  104. } else {
  105. this.popupVisible = false
  106. }
  107. }
  108. }
  109. }
  110. </script>
  111. <style scoped lang="scss">
  112. .dot{position:absolute;width:.5rem;height:.5rem;background:red;border-radius:50%;top:.2rem;right:0;}
  113. .product-list-header.logo{
  114. .slot{width:2.5rem;height: 1.6rem;text-align:center;line-height:1.6rem;
  115. .img{max-height:100%;max-width:100%;}
  116. }
  117. .common-search{
  118. padding:0;
  119. padding-left: $pageSpace;
  120. padding-right: $pageSpace;
  121. }
  122. }
  123. .header-holder{height: $headerHeight;}
  124. .product-list-header-wrapper{
  125. position: fixed;
  126. left:0;
  127. right:0;
  128. top:0;
  129. padding-top:var(--status-bar-height);
  130. z-index: 10;
  131. background: #fff;
  132. }
  133. .product-list-header {
  134. display: flex;
  135. height: $headerHeight;
  136. padding-top: 0.25rem;
  137. padding-bottom: 0.25rem;
  138. padding-left: $pageSpace;
  139. padding-right: $pageSpace;
  140. justify-content: space-between;
  141. align-items: center;
  142. box-shadow: 0px 4px 4px #f7f7f7;
  143. box-sizing: border-box;
  144. .slot{width:1.6rem;font-size:$h2}
  145. }
  146. .common-search{
  147. flex:1;
  148. padding: 0.35rem 0.3rem 0.35rem 0;
  149. }
  150. .common-search input {
  151. box-sizing: border-box;
  152. width: 100%;
  153. height: 1.6rem;
  154. border-radius: 1.6rem;
  155. background: #F4F4F4 url(../../../static/image/home/icon_search.png) no-repeat 0.6rem center;
  156. background-size:0.55rem;
  157. font-size:$fontSize;
  158. color: #999;
  159. padding-left:1.6rem;
  160. border: 0;
  161. }
  162. .right{width:1.6rem;height: 1.6rem;text-align:center;line-height: 1.6rem;position:relative}
  163. </style>