homeSearch.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. }
  36. },
  37. mounted() {},
  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('inSearch',this.keyword)
  47. uni.navigateTo({
  48. url: '/pages/integralMall/index'
  49. })
  50. },
  51. // 搜索全部删除
  52. searchDeletefun() {
  53. this.recentSearches = []
  54. uni.setStorageSync('recentSearches', this.recentSearches);
  55. this.searchDeleteShow = false
  56. },
  57. // 点击搜索
  58. tagSearches(name) {
  59. this.keyword = name;
  60. uni.$emit('jfSearchData', name)
  61. uni.navigateTo({
  62. url: '/pages/integralMall/index'
  63. })
  64. },
  65. // 最近搜索点击关闭按钮
  66. tagClose(index) {
  67. this.recentSearches.splice(index, 1)
  68. uni.setStorageSync('recentSearches', this.recentSearches);
  69. },
  70. }
  71. }
  72. </script>
  73. <style lang="scss" scoped>
  74. .tagClass {
  75. display: flex;
  76. padding: 41rpx 63rpx;
  77. background-color: #fff;
  78. justify-content: space-around;
  79. ::v-deep .u-tag--mini {
  80. font-size: 28rpx;
  81. line-height: 22px;
  82. padding: 0rpx 24rpx;
  83. }
  84. }
  85. .recentSearches {
  86. padding: 38rpx 32rpx;
  87. background-color: #fff;
  88. .recentSearches-head {
  89. display: flex;
  90. align-items: center;
  91. justify-content: space-between;
  92. color: #C4C4C4;
  93. .recentSearches-headLeft {
  94. display: flex;
  95. align-items: center;
  96. }
  97. .recentSearches-headRight {}
  98. }
  99. .recentSearches-text {
  100. display: flex;
  101. flex-wrap: wrap;
  102. align-items: baseline;
  103. .recentSearches-textWidth {
  104. // width: 140rpx;
  105. }
  106. }
  107. }
  108. </style>