search.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <template>
  2. <view class="container">
  3. <navbar :config="config" backColor="#666"></navbar>
  4. <view class="zdtopbox">
  5. <view class="" style="display: flex;">
  6. <text class="iconfont position-ab u-mt15 u-ml30 u-D1D9D4">&#xe7a6;</text>
  7. <input placeholder="请输入搜索关键字" @confirm="confirmSubmit" @input="getMsg" class="intoColor"
  8. placeholder-class="pc" />
  9. <text style="color: #FFFFFF;font-size: 36rpx; font-weight: 500;margin-left: 20rpx;align-items: center;"
  10. @click="SearchContent">搜索</text>
  11. </view>
  12. </view>
  13. <view class="u-plr30 u-mt30">
  14. <view v-if="recordList.length > 0">
  15. <view class="u-font32 u-1A1A1A u-bold u-flex-center-sb">
  16. <text>历史记录</text>
  17. <text class="iconfont u-font36 u-999" @click="delStory">&#xe64d;</text>
  18. </view>
  19. <view class="u-flex u-flex-warp">
  20. <view class="oval u-999 u-font24" v-for="(item, index) in recordList" @click="goProductList(item)"
  21. :key="index">{{ item }}</view>
  22. </view>
  23. </view>
  24. <!-- <view class="u-mt40">
  25. <view class="u-font32 u-1A1A1A u-bold">热门搜索</view>
  26. <view class="u-flex u-flex-warp">
  27. <view class="oval u-999 u-font24" v-for="(item,index) in recommendList">{{item.name}}</view>
  28. </view>
  29. </view> -->
  30. </view>
  31. </view>
  32. </template>
  33. <script>
  34. export default {
  35. data() {
  36. return {
  37. config: {
  38. back: true, //false是tolbar页面 是则不写
  39. title: '商品列表',
  40. color: '#1a1a1a',
  41. //背景颜色;参数一:透明度(0-1);参数二:背景颜色(array则为线性渐变,string为单色背景)
  42. backgroundColor: [1, '#fff'],
  43. statusBarFontColor: '#FFFFFF'
  44. },
  45. recordList: [],
  46. recommendList: [{
  47. name: '厨房用具'
  48. },
  49. {
  50. name: '厨房用具'
  51. },
  52. {
  53. name: '厨房用具'
  54. }
  55. ],
  56. category_id: null,
  57. searchMsg: ''
  58. };
  59. },
  60. onLoad(options) {
  61. this.category_id = options.category_id;
  62. this.SearchContent();
  63. },
  64. onShow() {
  65. let history = uni.getStorageSync('history')
  66. if (history) {
  67. this.recordList = history
  68. }
  69. },
  70. methods: {
  71. confirmSubmit(e) {
  72. if (e.detail.value) {
  73. uni.navigateTo({
  74. url: './productList?keyword=' + e.detail.value + '&category_id=' + this.category_id
  75. });
  76. }
  77. },
  78. getMsg(e) {
  79. this.searchMsg = e.detail.value;
  80. },
  81. SearchContent() {
  82. uni.navigateTo({
  83. url: './productList?keyword=' + this.searchMsg + '&category_id=' + this.category_id
  84. });
  85. },
  86. //清空
  87. delStory() {
  88. uni.showModal({
  89. title: '提示',
  90. content: '确定清空历史记录?',
  91. success: res => {
  92. if (res.confirm) {
  93. this.recordList = [];
  94. uni.removeStorageSync('history');
  95. }
  96. }
  97. });
  98. },
  99. //搜索结果页
  100. goProductList(text) {
  101. uni.navigateTo({
  102. url: './productList?keyword=' + text
  103. });
  104. }
  105. }
  106. };
  107. </script>
  108. <style lang="scss">
  109. .position-ab {
  110. position: absolute;
  111. color: #fff;
  112. }
  113. .zdtopbox {
  114. background-color: #FA6138;
  115. padding: 8rpx 30rpx 30rpx;
  116. input {
  117. flex: 1;
  118. height: 60rpx;
  119. line-height: 60rpx;
  120. border-radius: 50rpx;
  121. color: #fff;
  122. background-color: #FA6138;
  123. border: 1rpx solid rgba(255, 255, 255, 0.42);
  124. // background-color: rgba($color: #abc5b5, $alpha: 0.4);
  125. padding-left: 78rpx;
  126. box-sizing: border-box;
  127. }
  128. .pc {
  129. font-size: 22rpx;
  130. color: #fff;
  131. }
  132. }
  133. .oval {
  134. background-color: #f5f5f5;
  135. padding: 18rpx 38rpx;
  136. border-radius: 50rpx;
  137. margin-top: 30rpx;
  138. margin-right: 22rpx;
  139. }
  140. </style>