searchPage.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 @clear='clear'></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. clear(){
  46. console.log(11111)
  47. },
  48. goBack() {
  49. uni.$emit('searchData', this.keyword)
  50. uni.navigateBack({})
  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.navigateBack({})
  63. },
  64. // 最近搜索点击关闭按钮
  65. tagClose(index) {
  66. this.recentSearches.splice(index, 1)
  67. uni.setStorageSync('recentSearches', this.recentSearches);
  68. },
  69. }
  70. }
  71. </script>
  72. <style lang="scss" scoped>
  73. .tagClass {
  74. display: flex;
  75. padding: 41rpx 63rpx;
  76. background-color: #fff;
  77. justify-content: space-around;
  78. ::v-deep .u-tag--mini {
  79. font-size: 28rpx;
  80. line-height: 22px;
  81. padding: 0rpx 24rpx;
  82. }
  83. }
  84. .recentSearches {
  85. padding: 38rpx 32rpx;
  86. background-color: #fff;
  87. .recentSearches-head {
  88. display: flex;
  89. align-items: center;
  90. justify-content: space-between;
  91. color: #C4C4C4;
  92. .recentSearches-headLeft {
  93. display: flex;
  94. align-items: center;
  95. }
  96. .recentSearches-headRight {}
  97. }
  98. .recentSearches-text {
  99. display: flex;
  100. flex-wrap: wrap;
  101. align-items: baseline;
  102. .recentSearches-textWidth {
  103. // width: 140rpx;
  104. }
  105. }
  106. }
  107. </style>