productSearch.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <template>
  2. <view class="content">
  3. <!-- 搜索框 -->
  4. <view class="search-cont">
  5. <view class="inner">
  6. <image class="icon-search" src="../../static/images/search.png" mode=""></image>
  7. <input type="text" value="" :placeholder="storeId ? '搜索店内商品' : '输入商品名称'" confirm-type="搜索" @confirm="goSearch" :focus='setFocus' placeholder-style="font-size:28rpx;color:#BBBBBB;font-family: PingFang SC;" />
  8. </view>
  9. </view>
  10. <!-- 搜索历史 -->
  11. <view class="title-box">
  12. <text class="title">历史搜索</text>
  13. <image src="../../static/images/del.png" mode="" @click="clearHistory"></image>
  14. </view>
  15. <view class="data-list">
  16. <view class="item" v-for="(item,index) in searchHistory" :key="index" @click="doSearch(item)">
  17. {{ item }}
  18. </view>
  19. </view>
  20. <!-- 推荐搜索 -->
  21. <view class="title-box">
  22. <text class="title">推荐搜索</text>
  23. </view>
  24. <view class="data-list">
  25. <view class="item" v-for="(item,index) in topSearch" :key="index" @click="doSearch(item)">
  26. {{ item }}
  27. </view>
  28. </view>
  29. </view>
  30. </template>
  31. <script>
  32. export default {
  33. data() {
  34. return {
  35. setFocus: false,
  36. // 历史搜索
  37. searchHistory: [],
  38. // 推荐搜索
  39. topSearch: [],
  40. storeId: "",
  41. };
  42. },
  43. onLoad(options) {
  44. this.storeId = options.storeId || ""
  45. },
  46. onShow() {
  47. this.setFocus = true
  48. this.searchHistory=this.utils.getHisSearch();
  49. var config=uni.getStorageSync('config');
  50. if(config!=null&&config!=undefined&&config!=""){
  51. this.topSearch=JSON.parse(config).hotSearch.split(',');
  52. }
  53. },
  54. methods:{
  55. // 清空历史搜索数据
  56. clearHistory() {
  57. this.utils.clearHisSearch();
  58. this.searchHistory=this.utils.getHisSearch();
  59. },
  60. doSearch(item){
  61. uni.navigateTo({ url: './productList?key=' + item + `${this.storeId ? '&storeId='+this.storeId : ''}` })
  62. },
  63. goSearch(e) {
  64. if(e.detail.value!=null&&e.detail.value!=""){
  65. this.utils.addHisSearch(e.detail.value);
  66. }
  67. uni.navigateTo({
  68. url: './productList?key=' + e.detail.value + `${this.storeId ? '&storeId='+this.storeId : ''}`
  69. })
  70. }
  71. }
  72. }
  73. </script>
  74. <style lang="scss">
  75. .content{
  76. .search-cont{
  77. padding: 16upx 30upx;
  78. background-color: #FFFFFF;
  79. .inner{
  80. box-sizing: border-box;
  81. width: 100%;
  82. height: 72upx;
  83. background: #F7F7F7;
  84. border-radius: 36upx;
  85. display: flex;
  86. align-items: center;
  87. padding: 0 30upx;
  88. .icon-search{
  89. width: 28upx;
  90. height: 28upx;
  91. margin-right: 20upx;
  92. }
  93. input{
  94. height: 60upx;
  95. line-height: 60upx;
  96. flex: 1;
  97. }
  98. }
  99. }
  100. .title-box{
  101. padding: 30upx;
  102. display: flex;
  103. align-items: center;
  104. justify-content: space-between;
  105. .title{
  106. font-size: 30upx;
  107. font-family: PingFang SC;
  108. font-weight: bold;
  109. color: #111111;
  110. }
  111. image{
  112. width: 30upx;
  113. height: 30upx;
  114. }
  115. }
  116. .data-list{
  117. padding: 0upx 10upx 30upx;
  118. display: flex;
  119. flex-wrap: wrap;
  120. .item{
  121. padding: 0 30upx;
  122. height: 56upx;
  123. line-height: 56upx;
  124. font-size: 26upx;
  125. font-family: PingFang SC;
  126. font-weight: 500;
  127. color: #333333;
  128. background: #F5F5F5;
  129. border-radius: 28upx;
  130. margin: 0 20upx 20upx 0;
  131. }
  132. }
  133. }
  134. </style>