pk-search.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <template>
  2. <view class="pk-search">
  3. <view class="search-box u-flex u-row-between">
  4. <u-icon name="search" color="#CCCCCC" size="36"></u-icon>
  5. <input type="text" placeholder="搜索楼盘" class="input" v-model="keyword1">
  6. <text class="text" @click="tosearch">搜索</text>
  7. </view>
  8. <view class="lishi-box">
  9. <view class="lishi-title">
  10. 历史搜索
  11. </view>
  12. <view class="u-flex u-flex-wrap">
  13. <text v-for="(item,index) in lishilist" :key="index" class="lishi-item" @click="lishisearch(item)">{{item}}</text>
  14. </view>
  15. </view>
  16. <view class="search-list">
  17. <view class="search-item u-flex u-row-between" v-for="(item,index) in list" :key="index">
  18. <text>{{item.name}}</text>
  19. <text @click="addpk(item)">添加</text>
  20. </view>
  21. </view>
  22. </view>
  23. </template>
  24. <script>
  25. export default {
  26. data() {
  27. return {
  28. lishilist: [],
  29. keyword:'',
  30. keyword1:'',
  31. page:1,
  32. list:[]
  33. }
  34. },
  35. onLoad() {
  36. this.lishilist = uni.getStorageSync("lishi") || []
  37. this.getlist()
  38. },
  39. onReachBottom() {
  40. if(this.list.length % 20 == 0){
  41. this.page++
  42. this.getlist()
  43. }
  44. },
  45. methods: {
  46. lishisearch(item){
  47. this.keyword = item
  48. this.keyword1 = item
  49. this.page = 1
  50. this.list = []
  51. this.getlist()
  52. },
  53. addpk(item){
  54. var list = uni.getStorageSync("pklist") || []
  55. var index = list.findIndex(value => value.id == item.id)
  56. console.log(index);
  57. if(index == -1){
  58. list.unshift(item)
  59. uni.setStorageSync("pklist",list)
  60. uni.navigateBack()
  61. }else{
  62. uni.showModal({
  63. content:"该楼盘已添加!"
  64. })
  65. }
  66. },
  67. setlishi() {
  68. if (this.keyword) {
  69. if (this.lishilist.indexOf(this.keyword) == -1) {
  70. this.lishilist.unshift(this.keyword)
  71. uni.setStorageSync("lishi", this.lishilist)
  72. }
  73. }
  74. },
  75. tosearch() {
  76. this.keyword = this.$u.trim(this.keyword1)
  77. this.setlishi()
  78. this.page = 1
  79. this.list = []
  80. this.getlist()
  81. },
  82. getlist(){
  83. this.$u.post('/api/Index/property_list', {
  84. page: this.page,
  85. page_num: 20,
  86. keyword: this.keyword
  87. }).then(res => {
  88. if (this.page == 1) {
  89. this.list = res.data
  90. } else {
  91. this.list = this.list.concat(res.data)
  92. }
  93. })
  94. }
  95. }
  96. }
  97. </script>
  98. <style lang="scss">
  99. .pk-search {
  100. .search-list {
  101. padding: 0 24rpx;
  102. .search-item {
  103. padding: 18rpx 0;
  104. border-bottom: 1rpx solid #F2F2F2;
  105. text:first-child {
  106. font-size: 24rpx;
  107. font-family: PingFangSC-Regular, PingFang SC;
  108. font-weight: 400;
  109. color: #333333;
  110. }
  111. text:last-child {
  112. width: 80rpx;
  113. line-height: 46rpx;
  114. background: #1F7EFF;
  115. border-radius: 8rpx;
  116. text-align: center;
  117. font-size: 24rpx;
  118. font-family: PingFangSC-Regular, PingFang SC;
  119. font-weight: 400;
  120. color: #FFFFFF;
  121. }
  122. }
  123. }
  124. .lishi-box {
  125. padding: 0 24rpx;
  126. .lishi-item {
  127. line-height: 44rpx;
  128. background: #E5E5E5;
  129. border-radius: 22rpx;
  130. padding: 0 30rpx;
  131. font-size: 18rpx;
  132. font-family: PingFangSC-Regular, PingFang SC;
  133. font-weight: 400;
  134. color: #999999;
  135. margin-bottom: 20rpx;
  136. margin-right: 20rpx;
  137. }
  138. .lishi-title {
  139. font-size: 24rpx;
  140. font-family: PingFangSC-Medium, PingFang SC;
  141. font-weight: 500;
  142. color: #333333;
  143. margin-bottom: 14rpx;
  144. }
  145. }
  146. .search-box {
  147. width: 702rpx;
  148. height: 72rpx;
  149. background: #FFFFFF;
  150. border-radius: 20rpx;
  151. margin: 24rpx auto;
  152. padding-left: 24rpx;
  153. border: 2rpx solid #CCCCCC;
  154. position: sticky;
  155. top: 0;
  156. left: 0;
  157. .input {
  158. flex: 1;
  159. margin: 0 10rpx;
  160. }
  161. .text {
  162. padding: 0 24rpx;
  163. border-left: 1rpx solid #E5E7ED;
  164. line-height: 36rpx;
  165. font-size: 28rpx;
  166. font-family: PingFangSC-Medium, PingFang SC;
  167. font-weight: 500;
  168. color: #1E7DFF;
  169. }
  170. }
  171. }
  172. </style>