index.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. <template>
  2. <view class="goods-hotel">
  3. <view class="search">
  4. <u-input placeholder="搜索" border='none' v-model="search" @input="searchText">
  5. <template slot="suffix" style='margin-right:40rpx;'>
  6. <u-image :showLoading="true" :showError='true' src="/static/icon/search.png" width="40rpx"
  7. height="32rpx"></u-image>
  8. </template>
  9. </u-input>
  10. </view>
  11. <view class="content">
  12. <view class="content-item" v-for="item in hotelList" :key="item.id" @click="selected(item.id)">
  13. <image style="flex: none;width: 112rpx;height: 112rpx;border-radius: 50%;" :src="item.logo"
  14. mode=""></image>
  15. <view class="content-item-main">
  16. <text class="content-item-main-text">{{item.name}}</text>
  17. <view class="content-item-main-call" style="margin: 20rpx 0 12rpx;">
  18. <image style="width: 26rpx;height: 26rpx; margin-right: 8rpx;" src="/static/icon/phone02.png"
  19. mode=""></image>
  20. <text>{{item.phone?item.phone:""}}</text>
  21. </view>
  22. <view class="content-item-main-call">
  23. <image style="width: 24rpx;height: 28rpx; margin-right: 8rpx; " src="/static/icon/address01.png"
  24. mode=""></image>
  25. <text>{{item.distanceToMe?item.distanceToMe+"km":""}}</text>
  26. </view>
  27. </view>
  28. <view class="content-item-right">
  29. <image style="width: 50rpx;height: 48rpx;" src="/static/icon/navigation.png" mode=""></image>
  30. <text class="content-item-right-text">去这里</text>
  31. </view>
  32. </view>
  33. </view>
  34. <!-- 触底 -->
  35. <view class="home-bottom">
  36. <uni-load-more :status="status" color="#CCCCCC" :content-text="contentText" />
  37. </view>
  38. </view>
  39. </template>
  40. <script>
  41. import util from '../../../utils/util.js'
  42. export default {
  43. data() {
  44. return {
  45. // 搜索
  46. search:'',
  47. // 组价uni-load-more
  48. status: 'noMore',
  49. contentText: {
  50. contentdown: '查看更多',
  51. contentrefresh: '加载中',
  52. contentnomore: '—— 已经到底啦 ——'
  53. },
  54. // 酒店列表
  55. hotelList:[],
  56. //______________
  57. product_id:-1, // 产品id
  58. //______________
  59. geo: {},
  60. }
  61. },
  62. onLoad(op) {
  63. this.product_id=op.product_id
  64. this.init();
  65. },
  66. methods: {
  67. //初始化
  68. async init(){
  69. await this.getGeo();
  70. await this.getHotelList();
  71. },
  72. //获取地理位置
  73. getGeo(callback){
  74. return new Promise((resolve,reject)=>{
  75. uni.getLocation({
  76. type: "gcj02", //返回可以用于wx.openLocation的经纬度
  77. success: (res) => {
  78. const {latitude, longitude} = res;
  79. this.geo.latitude = latitude
  80. this.geo.longitude = longitude
  81. resolve(true);
  82. },
  83. fail: function(res) {
  84. console.error(res);
  85. reject(res)
  86. }
  87. })
  88. })
  89. },
  90. //选择
  91. selected(id){
  92. this.$store.commit("tab/SET_SELECTEDHOTELId", id)
  93. uni.navigateBack({
  94. fail: ()=>{
  95. uni.switchTab({
  96. url: "/pages/index/index"
  97. })
  98. }
  99. })
  100. },
  101. // 获取酒店列表
  102. getHotelList(page=1){
  103. if(page==1){
  104. this.hotelList = [];
  105. }
  106. const tempobj = {};
  107. if(this.geo.latitude&&this.geo.longitude){
  108. tempobj['latitude'] = this.geo.latitude;
  109. tempobj['longitude'] = this.geo.longitude;
  110. }
  111. this.$api.hotel.getHotelList({
  112. page:page,
  113. product_id:this.product_id,
  114. ...tempobj
  115. }).then(res=>{
  116. console.log(res,"酒店列表")
  117. if(res.code==0){
  118. let hotelList = res.data.data
  119. hotelList = this.calcDistance(hotelList);
  120. this.hotelList.push(...hotelList);
  121. if(hotelList.length >= 15){
  122. this.getHotelList(page + 1);
  123. }
  124. }
  125. })
  126. },
  127. //计算距离
  128. calcDistance(hotel){
  129. let target = hotel
  130. if(this.geo.latitude && this.geo.longitude){
  131. target.map(item=>{
  132. item.distanceToMe=this.$utils.calcDistance(this.geo.latitude,this.geo.longitude,item.latitude,item.longitude).toFixed(1);
  133. return item;
  134. })
  135. }
  136. return target;
  137. },
  138. // 搜索防抖
  139. searchText:util.debounce(function(){
  140. this.goSearch()
  141. },1000),
  142. // 搜索
  143. goSearch(page=1){
  144. if(page==1){
  145. this.hotelList = [];
  146. }
  147. const tempobj = {};
  148. if(this.search){
  149. tempobj['name'] = this.search;
  150. }
  151. this.$api.hotel.getHotelList({
  152. page:page,
  153. product_id:this.product_id,
  154. ...tempobj
  155. }).then(res=>{
  156. console.log(res,'搜索酒店列表')
  157. if(res.code==0){
  158. let hotelList=res.data.data
  159. hotelList = this.calcDistance(hotelList);
  160. this.hotelList.push(...hotelList);
  161. if(hotelList.length >= 15){
  162. this.getHotelList(page + 1);
  163. }
  164. }
  165. })
  166. },
  167. },
  168. }
  169. </script>
  170. <style lang="scss" scoped>
  171. $pageColor:#F9F9F9;
  172. $bgColor:#FFFFFF;
  173. @mixin flexlayout {
  174. display: flex;
  175. align-items: center;
  176. justify-content: center;
  177. }
  178. page {
  179. height: 100% !important;
  180. background: #F9F9F9 !important;
  181. }
  182. .goods-hotel {
  183. height: 100%;
  184. background: #F9F9F9;
  185. }
  186. .home-bottom {
  187. background-color: #f9f9f9;
  188. }
  189. .content {
  190. width: 100%;
  191. padding: 24rpx 30rpx;
  192. padding-bottom: 30rpx;
  193. background-color: #F9F9F9;
  194. .content-item {
  195. margin-bottom: 24rpx;
  196. padding: 0 24rpx;
  197. padding-top: 20rpx;
  198. padding-bottom: 20rpx;
  199. height: 204rpx;
  200. background: #FFFFFF;
  201. box-shadow: 0px 4rpx 24rpx -10rpx rgba(101, 95, 90, 0.3);
  202. border-radius: 12rpx;
  203. display: flex;
  204. align-items: center;
  205. justify-content: space-between;
  206. .content-item-main {
  207. flex: 1;
  208. display: flex;
  209. flex-direction: column;
  210. align-items: flex-start;
  211. justify-content: center;
  212. margin-left: 20rpx;
  213. margin-top: 12rpx;
  214. .content-item-main-text {
  215. font-weight: 500;
  216. color: #333333;
  217. font-size: 30rpx;
  218. }
  219. .content-item-main-call {
  220. font-weight: 500;
  221. color: #666666;
  222. font-size: 26rpx;
  223. display: flex;
  224. align-items: center;
  225. justify-content: flex-start;
  226. }
  227. }
  228. .content-item-right {
  229. flex: none;
  230. display: flex;
  231. flex-direction: column;
  232. align-items: center;
  233. justify-content: center;
  234. .content-item-right-text {
  235. font-weight: bold;
  236. color: #FF6201;
  237. font-size: 24rpx;
  238. margin-top: 16rpx;
  239. }
  240. }
  241. }
  242. }
  243. .search {
  244. padding: 0 30rpx;
  245. height: 124rpx;
  246. background: #FFFFFF;
  247. box-shadow: 0px 4rpx 8rpx 0px rgba(0, 0, 0, 0.04);
  248. display: flex;
  249. align-items: center;
  250. justify-content: center;
  251. ::v-deep .u-input {
  252. width: 690rpx !important;
  253. height: 68rpx !important;
  254. background: #F1F1F1;
  255. border-radius: 74rpx;
  256. }
  257. ::v-deep .u-input__content__field-wrapper {
  258. padding-left: 36rpx;
  259. }
  260. ::v-deep .u-input__content__field-wrapper__field {
  261. color: #999999 !important;
  262. font-size: 28rpx !important;
  263. }
  264. }
  265. </style>