index.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. <template>
  2. <view class="goods-hotel">
  3. <view class="search">
  4. <u-input placeholderStyle='color:#999' 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" mode="">
  14. </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 style="font-size: 26rpx; color: #666; ">{{item.phone?item.phone:""}}</text>
  21. </view>
  22. <view class="content-item-main-call">
  23. <image style="width: 24rpx;height: 28rpx; margin-right: 10rpx; " src="/static/icon/address01.png"
  24. mode=""></image>
  25. <text style="font-size: 26rpx; color: #999; ">{{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 {
  79. latitude,
  80. longitude
  81. } = res;
  82. this.geo.latitude = latitude
  83. this.geo.longitude = longitude
  84. resolve(true);
  85. },
  86. fail: function(res) {
  87. console.error(res);
  88. reject(res)
  89. }
  90. })
  91. })
  92. },
  93. //选择
  94. selected(id) {
  95. this.$store.commit("tab/SET_SELECTEDHOTELId", id)
  96. uni.navigateBack({
  97. fail: () => {
  98. uni.switchTab({
  99. url: "/pages/index/index"
  100. })
  101. }
  102. })
  103. },
  104. // 获取酒店列表
  105. getHotelList(page = 1) {
  106. if (page == 1) {
  107. this.hotelList = [];
  108. }
  109. const tempobj = {};
  110. if (this.geo.latitude && this.geo.longitude) {
  111. tempobj['latitude'] = this.geo.latitude;
  112. tempobj['longitude'] = this.geo.longitude;
  113. }
  114. this.$api.hotel.getHotelList({
  115. page: page,
  116. product_id: this.product_id,
  117. ...tempobj
  118. }).then(res => {
  119. console.log(res, "酒店列表")
  120. if (res.code == 0) {
  121. let hotelList = res.data.data
  122. hotelList = this.calcDistance(hotelList);
  123. this.hotelList.push(...hotelList);
  124. if (hotelList.length >= 15) {
  125. this.getHotelList(page + 1);
  126. }
  127. }
  128. })
  129. },
  130. //计算距离
  131. calcDistance(hotel) {
  132. let target = hotel
  133. if (this.geo.latitude && this.geo.longitude) {
  134. target.map(item => {
  135. item.distanceToMe = this.$utils.calcDistance(this.geo.latitude, this.geo.longitude, item
  136. .latitude, item.longitude).toFixed(1);
  137. return item;
  138. })
  139. }
  140. return target;
  141. },
  142. // 搜索防抖
  143. searchText: util.debounce(function() {
  144. this.goSearch()
  145. }, 1000),
  146. // 搜索
  147. goSearch(page = 1) {
  148. if (page == 1) {
  149. this.hotelList = [];
  150. }
  151. const tempobj = {};
  152. if (this.search) {
  153. tempobj['name'] = this.search;
  154. }
  155. this.$api.hotel.getHotelList({
  156. page: page,
  157. product_id: this.product_id,
  158. ...tempobj
  159. }).then(res => {
  160. console.log(res, '搜索酒店列表')
  161. if (res.code == 0) {
  162. let hotelList = res.data.data
  163. hotelList = this.calcDistance(hotelList);
  164. this.hotelList.push(...hotelList);
  165. if (hotelList.length >= 15) {
  166. this.getHotelList(page + 1);
  167. }
  168. }
  169. })
  170. },
  171. },
  172. }
  173. </script>
  174. <style lang="scss" scoped>
  175. $pageColor:#F9F9F9;
  176. $bgColor:#FFFFFF;
  177. @mixin flexlayout {
  178. display: flex;
  179. align-items: center;
  180. justify-content: center;
  181. }
  182. page {
  183. height: 100% !important;
  184. background: #F9F9F9 !important;
  185. }
  186. .goods-hotel {
  187. height: 100%;
  188. background: #F9F9F9;
  189. }
  190. .home-bottom {
  191. background-color: #f9f9f9;
  192. }
  193. .content {
  194. width: 100%;
  195. margin-top: 24rpx;
  196. padding: 0 30rpx;
  197. padding-bottom: 30rpx;
  198. background-color: #F9F9F9;
  199. .content-item {
  200. margin-bottom: 24rpx;
  201. padding: 0 24rpx;
  202. padding-top: 20rpx;
  203. padding-bottom: 20rpx;
  204. height: 204rpx;
  205. background: #FFFFFF;
  206. box-shadow: 0px 4rpx 24rpx -10rpx rgba(101, 95, 90, 0.2);
  207. border-radius: 12rpx;
  208. display: flex;
  209. align-items: center;
  210. justify-content: space-between;
  211. .content-item-main {
  212. flex: 1;
  213. display: flex;
  214. flex-direction: column;
  215. align-items: flex-start;
  216. justify-content: center;
  217. margin-left: 20rpx;
  218. margin-top: 12rpx;
  219. .content-item-main-text {
  220. color: #333333;
  221. font-size: 30rpx;
  222. }
  223. .content-item-main-call {
  224. color: #666666;
  225. font-size: 26rpx;
  226. display: flex;
  227. align-items: center;
  228. justify-content: flex-start;
  229. }
  230. }
  231. .content-item-right {
  232. flex: none;
  233. display: flex;
  234. flex-direction: column;
  235. align-items: center;
  236. justify-content: center;
  237. .content-item-right-text {
  238. font-weight: bold;
  239. color: #FF6201;
  240. font-size: 24rpx;
  241. margin-top: 16rpx;
  242. }
  243. }
  244. }
  245. }
  246. // 搜索
  247. .search {
  248. padding: 0 30rpx;
  249. height: 124rpx;
  250. background-color: $bgColor;
  251. box-shadow: 0px 4rpx 8rpx 0px rgba(0, 0, 0, 0.04);
  252. @include flexlayout;
  253. ::v-deep .u-input {
  254. width: 690rpx !important;
  255. height: 68rpx !important;
  256. background: #F1F1F1;
  257. border-radius: 74rpx;
  258. }
  259. ::v-deep .u-input__content__field-wrapper {
  260. padding-left: 36rpx;
  261. }
  262. ::v-deep .u-input__content__field-wrapper__field {
  263. color: #999999 !important;
  264. font-size: 28rpx !important;
  265. }
  266. }
  267. </style>