homeSearch.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <template>
  2. <view>
  3. <view style="background-color: #E75F37;padding: 20rpx;">
  4. <u-search placeholder="请输入商品名称" bgColor="#fff" searchIconColor='#E75F37' :actionStyle="{color:'#FFF'}"
  5. :searchIconSize='24' v-model="keyword" @search="goBack()" @custom="goBack()" focus></u-search>
  6. </view>
  7. <view class="recentSearches" v-if="recentSearches.length != 0">
  8. <view class="recentSearches-head">
  9. <view class="recentSearches-headLeft">
  10. <u-icon name="clock" color="#C4C4C4"></u-icon>
  11. <view style="font-size: 26rpx;margin-left: 6rpx;">最近搜索</view>
  12. </view>
  13. <view class="recentSearches-headRight">
  14. <u-icon name="trash" size="20px" @click="searchDeleteShow = true" color="#C4C4C4"></u-icon>
  15. </view>
  16. </view>
  17. <view class="recentSearches-text">
  18. <u-tag v-for="(item,index) in recentSearches" :key="index" :text="item" bgColor="#EFEFEF"
  19. color="#414141" borderColor="#EFEFEF" size="medium" closable :show="item" @close="tagClose(index)"
  20. shape="circle" @click.stop="tagSearches(item)"></u-tag>
  21. </view>
  22. <u-modal :show="searchDeleteShow" content="确认删除搜索记录吗?" showCancelButton @confirm="searchDeletefun"
  23. @cancel="searchDeleteShow = false" ref="uModal" :asyncClose="true">
  24. </u-modal>
  25. </view>
  26. </view>
  27. </template>
  28. <script>
  29. export default {
  30. data() {
  31. return {
  32. keyword: '',
  33. recentSearches: [], // 搜索数据
  34. searchDeleteShow: false, // 搜索全部删除弹窗
  35. homePage: false,
  36. }
  37. },
  38. onLoad(data) {
  39. if (uni.getStorageSync('recentSearches')) {
  40. this.recentSearches = uni.getStorageSync('recentSearches').slice(0, 10);
  41. }
  42. this.keyword = data.searchData
  43. },
  44. methods: {
  45. goBack() {
  46. uni.$emit('searchData', this.keyword)
  47. uni.setStorageSync('homeSearch', this.keyword);
  48. uni.switchTab({
  49. url: '/pages/tabBar/classification'
  50. });
  51. },
  52. // 搜索全部删除
  53. searchDeletefun() {
  54. this.recentSearches = []
  55. uni.setStorageSync('recentSearches', this.recentSearches);
  56. this.searchDeleteShow = false
  57. },
  58. // 点击搜索
  59. tagSearches(name) {
  60. this.keyword = name;
  61. uni.$emit('searchData', name)
  62. uni.setStorageSync('homeSearch', name);
  63. uni.switchTab({
  64. url: '/pages/tabBar/classification'
  65. });
  66. },
  67. // 最近搜索点击关闭按钮
  68. tagClose(index) {
  69. this.recentSearches.splice(index, 1)
  70. uni.setStorageSync('recentSearches', this.recentSearches);
  71. },
  72. }
  73. }
  74. </script>
  75. <style lang="scss" scoped>
  76. .tagClass {
  77. display: flex;
  78. padding: 41rpx 63rpx;
  79. background-color: #fff;
  80. justify-content: space-around;
  81. ::v-deep .u-tag--mini {
  82. font-size: 28rpx;
  83. line-height: 22px;
  84. padding: 0rpx 24rpx;
  85. }
  86. }
  87. .recentSearches {
  88. padding: 38rpx 32rpx;
  89. background-color: #fff;
  90. .recentSearches-head {
  91. display: flex;
  92. align-items: center;
  93. justify-content: space-between;
  94. color: #C4C4C4;
  95. .recentSearches-headLeft {
  96. display: flex;
  97. align-items: center;
  98. }
  99. .recentSearches-headRight {}
  100. }
  101. .recentSearches-text {
  102. display: flex;
  103. flex-wrap: wrap;
  104. align-items: baseline;
  105. .recentSearches-textWidth {
  106. // width: 140rpx;
  107. }
  108. }
  109. }
  110. </style>