search.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <template>
  2. <view class="search-scenic">
  3. <view class="search-box">
  4. <view class="city-box">
  5. <image class="icon" src="@/static/blue-position.png" mode=""></image>
  6. <view class="city">
  7. {{city}}
  8. </view>
  9. </view>
  10. <input class="search" v-model="query.key" focus type="text" placeholder="景点名称" />
  11. </view>
  12. <zs-list class="list" mt="0" @load="loadMore" :status="status">
  13. <view class="item" v-for="item in list" :key="item.scenicId" @click="goDetail(item)">
  14. <zs-img :src="item.newPicUrl" width="200rpx" height="200rpx" radius="full" mode="center"></zs-img>
  15. <view class="info">
  16. <view class="title">
  17. {{item.scenicName}}
  18. </view>
  19. <view class="price-box">
  20. <view class="unit">
  21. </view>
  22. <view class="price">
  23. 580
  24. </view>
  25. <view class="text">
  26. </view>
  27. </view>
  28. <view class="address-box">
  29. <view class="address">
  30. 重庆
  31. </view>
  32. <view class="distance">
  33. {{item|filterDistance}} KM
  34. </view>
  35. </view>
  36. </view>
  37. </view>
  38. </zs-list>
  39. </view>
  40. </template>
  41. <script>
  42. import {debounce} from '@/utils/tool.js'
  43. import {getScenicList} from '@/api/scenic.js'
  44. export default {
  45. data() {
  46. return {
  47. city: uni.getStorageSync('city'),
  48. status:'more',
  49. list:[],
  50. query:{
  51. key: "",
  52. page: 1,
  53. pageSize: 10
  54. },
  55. }
  56. },
  57. watch: {
  58. 'query.key':debounce(function(val) {
  59. console.log(111111);
  60. this.query.page = 1
  61. this.list = []
  62. this.status = 'more'
  63. this.getScenicList()
  64. if(val){
  65. }
  66. })
  67. },
  68. filters: {
  69. filterDistance: function(item) {
  70. if(!item.glocation) return '-'
  71. let blocation = item.glocation.split(',')
  72. let location = JSON.parse(uni.getStorageSync('location'))
  73. /*参数:两地的经纬度数值*/
  74. var radLat1 = location.latitude * Math.PI / 180.0;
  75. var radLat2 = blocation[0]* Math.PI / 180.0;
  76. var a = radLat1 - radLat2;
  77. var b = location.longitude* Math.PI / 180.0 - blocation[1]* Math.PI / 180.0;
  78. var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) +
  79. Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
  80. s = s * 6378137.0;//地球半径 单位米;
  81. s = Math.round(s * 10000) / 10000 /1000 //输出为千米
  82. s = s.toFixed(0)
  83. return s
  84. }
  85. },
  86. methods: {
  87. loadMore(){
  88. this.getScenicList()
  89. },
  90. getScenicList(){
  91. // if(!this.query.key) return
  92. this.status = 'loading'
  93. getScenicList(this.query).then(res=>{
  94. if(res.state == 'Success'){
  95. this.list = this.list.concat(res.content.data.rows)
  96. if(this.list.length>= res.content.data.totalCount){
  97. this.status = 'noMore'
  98. }else{
  99. this.status = 'more'
  100. this.query.page++
  101. }
  102. }
  103. })
  104. },
  105. goDetail(item){
  106. uni.navigateTo({
  107. url:'/scenic/detail?id='+item.scenicId
  108. })
  109. }
  110. },
  111. onLoad() {
  112. uni.setNavigationBarTitle({
  113. title: uni.getStorageSync('city')
  114. });
  115. }
  116. }
  117. </script>
  118. <style lang="scss" >
  119. .search-scenic{
  120. min-height: 100vh;
  121. padding: 112rpx 24rpx 0;
  122. .search-box{
  123. position: fixed;
  124. top: 20rpx;
  125. left: 24rpx;
  126. width: 702rpx;
  127. height: 72rpx;
  128. // padding: 16rpx;
  129. box-sizing: border-box;
  130. z-index: 9;
  131. background: #F6F6F6;
  132. border-radius: 40rpx 40rpx 40rpx 40rpx;
  133. .city-box{
  134. position: absolute;
  135. left: 0;
  136. top: 50%;
  137. transform: translateY(-50%);
  138. display: flex;
  139. align-items: center;
  140. padding: 0 28rpx;
  141. border-right: 1rpx solid #F0F0F0;
  142. .icon{
  143. width: 30rpx;
  144. height: 30rpx;
  145. }
  146. .city{
  147. font-weight: 600;
  148. font-size: 28rpx;
  149. color: #222222;
  150. margin-left: 6rpx;
  151. }
  152. }
  153. .search{
  154. width: 702rpx;
  155. height: 72rpx;
  156. border-radius: 40rpx 40rpx 40rpx 40rpx;
  157. padding-left: 230rpx;
  158. padding-right: 100rpx;
  159. box-sizing: border-box;
  160. }
  161. }
  162. .zs-list{
  163. .item{
  164. background: #FFFFFF;
  165. border-radius: 16rpx;
  166. display: flex;
  167. padding: 12rpx 0;
  168. border-bottom: 1rpx solid #F0F0F0;
  169. .zs-img{
  170. width: 200rpx;
  171. }
  172. .info{
  173. flex: 1;
  174. padding: 30rpx 20rpx 20rpx;
  175. box-sizing: border-box;
  176. display: flex;
  177. flex-direction: column;
  178. justify-content: space-between;
  179. .title{
  180. font-weight: 400;
  181. font-size: 24rpx;
  182. color: #222222;
  183. width: 450rpx;
  184. white-space: nowrap;
  185. overflow: hidden;
  186. text-overflow: ellipsis;
  187. }
  188. .price-box{
  189. display: flex;
  190. align-items: flex-end;
  191. margin-top: 12rpx;
  192. .unit{
  193. font-weight: 600;
  194. font-size: 20rpx;
  195. color: $uni-color-primary;
  196. }
  197. .price{
  198. font-weight: 600;
  199. font-size: 36rpx;
  200. color: $uni-color-primary;
  201. }
  202. .text{
  203. font-weight: 300;
  204. font-size: 24rpx;
  205. color: #AAAAAA;
  206. margin-left: 6rpx;
  207. }
  208. }
  209. .address-box{
  210. display: flex;
  211. align-items: center;
  212. justify-content: space-between;
  213. font-weight: 300;
  214. font-size: 20rpx;
  215. color: #AAAAAA;
  216. margin-top: 12rpx;
  217. }
  218. }
  219. }
  220. }
  221. }
  222. </style>