searchPage.vue 2.9 KB

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