search.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. <template>
  2. <view class="page">
  3. <view class="p-bar flex-row">
  4. <view class="align-center justify-between bar">
  5. <view class="align-center">
  6. <image
  7. src="/static/mang-sear.png"
  8. class="image_5"
  9. />
  10. <input type="text" placeholder="请输入商家或商品名称" class="inpt" v-model="keyword">
  11. </view>
  12. <image
  13. src="/static/mang-quxiao.png"
  14. class="image_6"
  15. v-if="hasKeyword"
  16. />
  17. </view>
  18. <!-- <text class="text_3" v-if="hasKeyword">取消</text> -->
  19. <text class="text_3" @tap="search">搜索</text>
  20. </view>
  21. <!-- v-if="!hasKeyword" -->
  22. <view class="p-history" v-if="true && search_lishi.length>0">
  23. <view class="title">
  24. 历史搜索
  25. </view>
  26. <view class="item-wrap align-center">
  27. <view class="item" v-for="(item,i) in search_lishi" :key="i">
  28. {{item}}
  29. </view>
  30. </view>
  31. </view>
  32. <view class="p-content" v-else-if="false">
  33. <view class="item-wrap flex-row justify-between" v-for="(item,i) in 3" :key="i">
  34. <view class="flex-row">
  35. <image
  36. src="/static/temp/pro.png"
  37. class="image_7"
  38. mode="aspectFill"
  39. />
  40. <view class="flex-col group_8">
  41. <view class="flex-col items-start">
  42. <text class="text_4 clamp">幸福西饼Rice盲盒</text>
  43. <view class="stars align-center">
  44. <image
  45. src="/static/mang_star.png"
  46. class="image_8"
  47. v-for="(item,idx) in 3"
  48. :key="idx"
  49. />
  50. </view>
  51. <text class="text_5">随机搭配</text>
  52. </view>
  53. <view class="flex-row group_10">
  54. <view class="group_11">
  55. <text class="text_6">¥</text>
  56. <text class="text_7">18.8</text>
  57. </view>
  58. <text class="text_8">¥24~33</text>
  59. </view>
  60. </view>
  61. </view>
  62. <text class="text_9">1.5km</text>
  63. </view>
  64. </view>
  65. </view>
  66. </template>
  67. <script>
  68. export default {
  69. data() {
  70. return {
  71. keyword:'',
  72. search_lishi:[],
  73. };
  74. },
  75. computed:{
  76. hasKeyword(){
  77. if(this.keyword){
  78. return true;
  79. }
  80. return false;
  81. }
  82. },
  83. onShow(){ //这里一进来就查询之前留下的搜索内容 别忘了退出登录的时候删掉
  84. // console.log(uni.getStorageSync('history'))
  85. this.search_lishi = uni.getStorageSync('history') || [] //存放历史记录的数组
  86. },
  87. methods:{
  88. search(){
  89. if(this.hasKeyword){
  90. this.add_history(this.keyword)
  91. }
  92. },
  93. //添加新的历史记录 当有搜索新的历史记录时就会进入这个方法
  94. add_history(e){
  95. //存在,flag1==0
  96. try{
  97. let flag1= this.search_lishi.findIndex(item => item=== e) //判断数组里面有没有重复查询过的内容
  98. if(flag1 != -1){ //有重复内容
  99. // if(flag1 != 0){ //如果删除0会出错
  100. this.search_lishi.splice(flag1,1) //删除重复重新添加一个
  101. this.search_lishi.unshift(e) //添加一个内容
  102. // }
  103. }else{
  104. if(this.search_lishi.length >= 16){
  105. this.search_lishi.splice(15,1) //删除最后一个新添加一个
  106. this.search_lishi.unshift(e) //添加一个内容
  107. }else{
  108. this.search_lishi.unshift(e) //添加一个内容
  109. }
  110. }
  111. uni.setStorageSync('history', this.search_lishi);//保存用户搜索历史
  112. this.search_lishi = uni.getStorageSync('history') //存放历史记录的数组
  113. }catch(e){
  114. this.search_lishi.push(e) //添加一个内容
  115. //TODO handle the exception
  116. }
  117. },
  118. },
  119. }
  120. </script>
  121. <style lang="scss">
  122. page{
  123. background-color: #f8f8f8;
  124. }
  125. .page{
  126. padding: 30rpx;
  127. }
  128. .p-bar{
  129. .bar {
  130. flex: 1 1 auto;
  131. border-radius: 32rpx;
  132. height: 64rpx;
  133. border: solid 2rpx #92b99c;
  134. padding: 0 20rpx;
  135. }
  136. .image_5 {
  137. flex-shrink: 0;
  138. width: 31rpx;
  139. height: 31rpx;
  140. }
  141. .inpt {
  142. margin-left: 17rpx;
  143. height: 60rpx;
  144. line-height: 60rpx;
  145. color: #333;
  146. font-size: 28rpx;
  147. font-family: PingFang;
  148. letter-spacing: 1.12rpx;
  149. }
  150. .image_6 {
  151. margin-bottom: 3rpx;
  152. width: 28rpx;
  153. height: 28rpx;
  154. }
  155. .text_3 {
  156. margin-left: 28rpx;
  157. margin-right: 4rpx;
  158. align-self: center;
  159. color: #92b99c;
  160. font-size: 28rpx;
  161. font-family: PingFang;
  162. line-height: 27rpx;
  163. letter-spacing: 1.12rpx;
  164. }
  165. }
  166. .p-history{
  167. padding-top: 10rpx;
  168. .title{
  169. height: 90rpx;
  170. line-height: 90rpx;
  171. font-size: 32rpx;
  172. font-family: PingFang SC;
  173. font-weight: bold;
  174. color: #333333;
  175. }
  176. .item-wrap{
  177. flex-wrap: wrap;
  178. }
  179. .item{
  180. height: 54rpx;
  181. line-height: 54rpx;
  182. padding: 0 20rpx;
  183. background: #ECEFED;
  184. border-radius: 27px;
  185. margin-right: 24rpx;
  186. margin-bottom: 24rpx;
  187. font-size: 24rpx;
  188. font-family: PingFang SC;
  189. font-weight: 500;
  190. color: #333333;
  191. }
  192. }
  193. .p-content{
  194. padding-top: 40rpx;
  195. .item-wrap{
  196. padding: 24rpx 14rpx 24rpx 24rpx;
  197. background-color: #ffffff;
  198. box-shadow: 0px 6rpx 10rpx #2a2a2a14;
  199. border-radius: 20rpx;
  200. margin-bottom: 24rpx;
  201. .image_7 {
  202. width: 200rpx;
  203. height: 200rpx;
  204. }
  205. .group_8 {
  206. margin-left: 18rpx;
  207. margin-bottom: 3rpx;
  208. }
  209. .text_4 {
  210. color: #333333;
  211. font-size: 30rpx;
  212. font-family: PingFang;
  213. max-width: 400rpx;
  214. }
  215. .image_8 {
  216. margin-top: 14rpx;
  217. width: 28rpx;
  218. height: 28rpx;
  219. margin-right: 4rpx;
  220. }
  221. .text_5 {
  222. margin-left: 3rpx;
  223. margin-top: 18rpx;
  224. color: #999999;
  225. font-size: 24rpx;
  226. font-family: PingFang;
  227. }
  228. .group_10 {
  229. margin-top: 57rpx;
  230. padding: 0 3rpx;
  231. }
  232. .group_11 {
  233. line-height: 28rpx;
  234. height: 29rpx;
  235. }
  236. .text_6 {
  237. color: #ff3e3e;
  238. font-size: 24rpx;
  239. font-family: PingFang;
  240. }
  241. .text_7 {
  242. color: #ff3e3e;
  243. font-size: 36rpx;
  244. font-family: PingFang;
  245. }
  246. .text_8 {
  247. margin-left: 10rpx;
  248. margin-top: 9rpx;
  249. color: #999999;
  250. font-size: 24rpx;
  251. font-family: PingFang;
  252. text-decoration: line-through;
  253. }
  254. .text_9 {
  255. align-self: center;
  256. color: #999999;
  257. font-size: 24rpx;
  258. font-family: PingFang;
  259. }
  260. }
  261. }
  262. </style>