productSearch.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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="输入药品名称" 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. };
  41. },
  42. onShow() {
  43. this.setFocus = true
  44. this.searchHistory=this.utils.getHisSearch();
  45. var config=uni.getStorageSync('config');
  46. if(config!=null&&config!=undefined&&config!=""){
  47. this.topSearch=JSON.parse(config).hotSearch.split(',');
  48. }
  49. },
  50. methods:{
  51. // 清空历史搜索数据
  52. clearHistory() {
  53. this.utils.clearHisSearch();
  54. this.searchHistory=this.utils.getHisSearch();
  55. },
  56. doSearch(item){
  57. uni.navigateTo({ url: './productList?key=' + item })
  58. },
  59. goSearch(e) {
  60. if(e.detail.value!=null&&e.detail.value!=""){
  61. this.utils.addHisSearch(e.detail.value);
  62. }
  63. uni.navigateTo({
  64. url: './productList?key=' + e.detail.value
  65. })
  66. }
  67. }
  68. }
  69. </script>
  70. <style lang="scss">
  71. .content{
  72. .search-cont{
  73. padding: 16upx 30upx;
  74. background-color: #FFFFFF;
  75. .inner{
  76. box-sizing: border-box;
  77. width: 100%;
  78. height: 72upx;
  79. background: #F7F7F7;
  80. border-radius: 36upx;
  81. display: flex;
  82. align-items: center;
  83. padding: 0 30upx;
  84. .icon-search{
  85. width: 28upx;
  86. height: 28upx;
  87. margin-right: 20upx;
  88. }
  89. input{
  90. height: 60upx;
  91. line-height: 60upx;
  92. flex: 1;
  93. }
  94. }
  95. }
  96. .title-box{
  97. padding: 30upx;
  98. display: flex;
  99. align-items: center;
  100. justify-content: space-between;
  101. .title{
  102. font-size: 30upx;
  103. font-family: PingFang SC;
  104. font-weight: bold;
  105. color: #111111;
  106. }
  107. image{
  108. width: 30upx;
  109. height: 30upx;
  110. }
  111. }
  112. .data-list{
  113. padding: 0upx 10upx 30upx;
  114. display: flex;
  115. flex-wrap: wrap;
  116. .item{
  117. padding: 0 30upx;
  118. height: 56upx;
  119. line-height: 56upx;
  120. font-size: 26upx;
  121. font-family: PingFang SC;
  122. font-weight: 500;
  123. color: #333333;
  124. background: #F5F5F5;
  125. border-radius: 28upx;
  126. margin: 0 20upx 20upx 0;
  127. }
  128. }
  129. }
  130. </style>