search.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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.queryName" focus type="text" placeholder="景点名称" />
  11. </view>
  12. <zs-list class="list" mt="0" @load="loadMore" :status="status">
  13. <view class="item" v-for="(item,index) in list" :key="index" @click="goDetail(item)">
  14. <zs-img :src="item.logoPath" width="200rpx" height="200rpx" radius="full" mode="center"></zs-img>
  15. <view class="info">
  16. <view class="title">
  17. {{item.tripartiteJson.scenicName}}
  18. </view>
  19. <view class="address-box">
  20. <view class="price-box">
  21. <view class="unit">
  22. </view>
  23. <view class="price">
  24. {{item.tripartiteJson.ticketList | filterMinPrice}}
  25. </view>
  26. <view class="text">
  27. </view>
  28. </view>
  29. <!-- <view class="address">
  30. 重庆
  31. </view> -->
  32. <view class="distance">
  33. {{(item.shopVo.distance/1000).toFixed(2)}} 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 { search } from '@/api/shop.js';
  44. export default {
  45. data() {
  46. return {
  47. city: uni.getStorageSync('city'),
  48. status:'more',
  49. list:[],
  50. query:{
  51. queryName:'',
  52. menuId: 1,
  53. range:1000,
  54. 'location.lat':0,
  55. 'location.lon':0,
  56. pageCurrent:1,
  57. pageSize:10
  58. },
  59. }
  60. },
  61. watch: {
  62. 'query.queryName':debounce(function(val) {
  63. this.query.pageCurrent = 1
  64. this.list = []
  65. this.status = 'more'
  66. if(val){
  67. this.query.range = 9999
  68. }else{
  69. this.query.range = 1000
  70. }
  71. this.search()
  72. })
  73. },
  74. filters: {
  75. filterDistance: function(item) {
  76. if(!item.glocation) return '-'
  77. let blocation = item.glocation.split(',')
  78. let location = JSON.parse(uni.getStorageSync('location'))
  79. /*参数:两地的经纬度数值*/
  80. var radLat1 = location.latitude * Math.PI / 180.0;
  81. var radLat2 = blocation[0]* Math.PI / 180.0;
  82. var a = radLat1 - radLat2;
  83. var b = location.longitude* Math.PI / 180.0 - blocation[1]* Math.PI / 180.0;
  84. var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) +
  85. Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
  86. s = s * 6378137.0;//地球半径 单位米;
  87. s = Math.round(s * 10000) / 10000 /1000 //输出为千米
  88. s = s.toFixed(0)
  89. return s
  90. },
  91. filterMinPrice(list){
  92. if(list.length){
  93. let arr = JSON.parse(JSON.stringify(list))
  94. arr.sort(function(a,b){ return a.salePrice - b.salePrice})
  95. return arr[0].salePrice
  96. console.log(arr);
  97. }else{
  98. return 0
  99. }
  100. }
  101. },
  102. methods: {
  103. loadMore(){
  104. this.search()
  105. },
  106. // getScenicList(){
  107. // // if(!this.query.key) return
  108. // this.status = 'loading'
  109. // getScenicList(this.query).then(res=>{
  110. // if(res.state == 'Success'){
  111. // this.list = this.list.concat(res.content.data.rows)
  112. // if(this.list.length>= res.content.data.totalCount){
  113. // this.status = 'noMore'
  114. // }else{
  115. // this.status = 'more'
  116. // this.query.page++
  117. // }
  118. // }
  119. // })
  120. // },
  121. search() {
  122. if(this.status == 'noMore' || this.status == 'loading' || !this.query['location.lat']) return
  123. this.status = 'loading'
  124. search(this.query).then(res=>{
  125. if(res.state == 'Success'){
  126. let data = res.content.records
  127. data.map((item,index)=>{
  128. item.tripartiteJson = JSON.parse(item.tripartiteJson)
  129. })
  130. this.list = this.list.concat(data)
  131. console.log('加载数据',this.status,this.list,this.query.pageCurrent);
  132. if(this.query.pageCurrent >= res.content.pages){
  133. this.status = 'noMore'
  134. }else{
  135. this.status = 'more'
  136. this.query.pageCurrent++
  137. }
  138. }
  139. })
  140. },
  141. goDetail(item){
  142. uni.navigateTo({
  143. url:`/scenic/detail?id=${item.tripartiteJson.scenicId}&epId=${item.shopVo.shopId}`
  144. })
  145. }
  146. },
  147. onLoad() {
  148. uni.setNavigationBarTitle({
  149. title: uni.getStorageSync('city')
  150. });
  151. uni.getLocation({
  152. type: 'gcj02',
  153. success: (res) => {
  154. // 解析地址
  155. this.query['location.lat'] = res.latitude
  156. this.query['location.lon'] = res.longitude
  157. console.log(this);
  158. // 存储经纬度
  159. uni.setStorageSync('location',JSON.stringify({latitude:res.latitude,longitude:res.longitude}))
  160. this.search()
  161. }
  162. })
  163. }
  164. }
  165. </script>
  166. <style lang="scss" >
  167. .search-scenic{
  168. min-height: 100vh;
  169. padding: 112rpx 24rpx 0;
  170. .search-box{
  171. position: fixed;
  172. top: 0;
  173. left: 0;
  174. width: 100%;
  175. height: 72rpx;
  176. padding: 20rpx 24rpx;
  177. z-index: 9;
  178. background: #fff;
  179. .city-box{
  180. position: absolute;
  181. left: 20rpx;
  182. top: 50%;
  183. transform: translateY(-50%);
  184. display: flex;
  185. align-items: center;
  186. padding: 0 28rpx;
  187. border-right: 1rpx solid #F0F0F0;
  188. .icon{
  189. width: 30rpx;
  190. height: 30rpx;
  191. }
  192. .city{
  193. font-weight: 600;
  194. font-size: 28rpx;
  195. color: #222222;
  196. margin-left: 6rpx;
  197. }
  198. }
  199. .search{
  200. width: 702rpx;
  201. height: 72rpx;
  202. border-radius: 40rpx 40rpx 40rpx 40rpx;
  203. padding-left: 230rpx;
  204. padding-right: 100rpx;
  205. box-sizing: border-box;
  206. background: #F6F6F6;
  207. }
  208. }
  209. .zs-list{
  210. .item{
  211. background: #FFFFFF;
  212. border-radius: 16rpx;
  213. display: flex;
  214. padding: 12rpx 0;
  215. border-bottom: 1rpx solid #F0F0F0;
  216. .zs-img{
  217. width: 200rpx;
  218. }
  219. .info{
  220. flex: 1;
  221. padding: 30rpx 20rpx 20rpx;
  222. box-sizing: border-box;
  223. display: flex;
  224. flex-direction: column;
  225. justify-content: space-between;
  226. .title{
  227. font-weight: 400;
  228. font-size: 24rpx;
  229. color: #222222;
  230. width: 450rpx;
  231. white-space: nowrap;
  232. overflow: hidden;
  233. text-overflow: ellipsis;
  234. }
  235. .price-box{
  236. display: flex;
  237. align-items: flex-end;
  238. margin-top: 12rpx;
  239. .unit{
  240. font-weight: 600;
  241. font-size: 20rpx;
  242. color: $uni-color-primary;
  243. }
  244. .price{
  245. font-weight: 600;
  246. font-size: 36rpx;
  247. color: $uni-color-primary;
  248. }
  249. .text{
  250. font-weight: 300;
  251. font-size: 24rpx;
  252. color: #AAAAAA;
  253. margin-left: 6rpx;
  254. }
  255. }
  256. .address-box{
  257. display: flex;
  258. align-items: flex-end;
  259. justify-content: space-between;
  260. font-weight: 300;
  261. font-size: 20rpx;
  262. color: #AAAAAA;
  263. margin-top: 12rpx;
  264. }
  265. }
  266. }
  267. }
  268. }
  269. </style>