123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292 |
- <template>
- <view class="goods-hotel">
- <view class="search">
- <u-input placeholderStyle='color:#999' placeholder="搜索" border='none' v-model="search" @input="searchText">
- <template slot="suffix" style='margin-right:40rpx;'>
- <u-image :showLoading="true" :showError='true' src="/static/icon/search.png" width="40rpx"
- height="32rpx"></u-image>
- </template>
- </u-input>
- </view>
- <view class="content">
- <view class="content-item" v-for="item in hotelList" :key="item.id" @click="selected(item.id)">
- <image style="flex: none;width: 112rpx;height: 112rpx;border-radius: 50%;" :src="item.logo" mode="">
- </image>
- <view class="content-item-main">
- <text class="content-item-main-text">{{item.name}}</text>
- <view class="content-item-main-call" style="margin: 20rpx 0 12rpx;">
- <image style="width: 26rpx;height: 26rpx; margin-right: 8rpx;" src="/static/icon/phone02.png"
- mode=""></image>
- <text style="font-size: 26rpx; color: #666; ">{{item.phone?item.phone:""}}</text>
- </view>
- <view class="content-item-main-call">
- <image style="width: 24rpx;height: 28rpx; margin-right: 10rpx; " src="/static/icon/address01.png"
- mode=""></image>
- <text style="font-size: 26rpx; color: #999; ">{{item.distanceToMe?item.distanceToMe+"km":""}}</text>
- </view>
- </view>
- <view class="content-item-right">
- <image style="width: 50rpx;height: 48rpx;" src="/static/icon/navigation.png" mode=""></image>
- <text class="content-item-right-text">去这里</text>
- </view>
- </view>
- </view>
- <!-- 触底 -->
- <view class="home-bottom">
- <uni-load-more :status="status" color="#CCCCCC" :content-text="contentText" />
- </view>
- </view>
- </template>
- <script>
- import util from '../../../utils/util.js'
- export default {
- data() {
- return {
- // 搜索
- search: '',
- // 组价uni-load-more
- status: 'noMore',
- contentText: {
- contentdown: '查看更多',
- contentrefresh: '加载中',
- contentnomore: '—— 已经到底啦 ——'
- },
- // 酒店列表
- hotelList: [],
- //______________
- product_id: -1, // 产品id
- //______________
- geo: {},
- }
- },
- onLoad(op) {
- this.product_id = op.product_id
- this.init();
- },
- methods: {
- //初始化
- async init() {
- await this.getGeo();
- await this.getHotelList();
- },
- //获取地理位置
- getGeo(callback) {
- return new Promise((resolve, reject) => {
- uni.getLocation({
- type: "gcj02", //返回可以用于wx.openLocation的经纬度
- success: (res) => {
- const {
- latitude,
- longitude
- } = res;
- this.geo.latitude = latitude
- this.geo.longitude = longitude
- resolve(true);
- },
- fail: function(res) {
- console.error(res);
- reject(res)
- }
- })
- })
- },
- //选择
- selected(id) {
- this.$store.commit("tab/SET_SELECTEDHOTELId", id)
- uni.navigateBack({
- fail: () => {
- uni.switchTab({
- url: "/pages/index/index"
- })
- }
- })
- },
- // 获取酒店列表
- getHotelList(page = 1) {
- if (page == 1) {
- this.hotelList = [];
- }
- const tempobj = {};
- if (this.geo.latitude && this.geo.longitude) {
- tempobj['latitude'] = this.geo.latitude;
- tempobj['longitude'] = this.geo.longitude;
- }
- this.$api.hotel.getHotelList({
- page: page,
- product_id: this.product_id,
- ...tempobj
- }).then(res => {
- console.log(res, "酒店列表")
- if (res.code == 0) {
- let hotelList = res.data.data
- hotelList = this.calcDistance(hotelList);
- this.hotelList.push(...hotelList);
- if (hotelList.length >= 15) {
- this.getHotelList(page + 1);
- }
- }
- })
- },
- //计算距离
- calcDistance(hotel) {
- let target = hotel
- if (this.geo.latitude && this.geo.longitude) {
- target.map(item => {
- item.distanceToMe = this.$utils.calcDistance(this.geo.latitude, this.geo.longitude, item
- .latitude, item.longitude).toFixed(1);
- return item;
- })
- }
- return target;
- },
- // 搜索防抖
- searchText: util.debounce(function() {
- this.goSearch()
- }, 1000),
- // 搜索
- goSearch(page = 1) {
- if (page == 1) {
- this.hotelList = [];
- }
- const tempobj = {};
- if (this.search) {
- tempobj['name'] = this.search;
- }
- this.$api.hotel.getHotelList({
- page: page,
- product_id: this.product_id,
- ...tempobj
- }).then(res => {
- console.log(res, '搜索酒店列表')
- if (res.code == 0) {
- let hotelList = res.data.data
- hotelList = this.calcDistance(hotelList);
- this.hotelList.push(...hotelList);
- if (hotelList.length >= 15) {
- this.getHotelList(page + 1);
- }
- }
- })
- },
- },
- }
- </script>
- <style lang="scss" scoped>
- $pageColor:#F9F9F9;
- $bgColor:#FFFFFF;
- @mixin flexlayout {
- display: flex;
- align-items: center;
- justify-content: center;
- }
- page {
- height: 100% !important;
- background: #F9F9F9 !important;
- }
- .goods-hotel {
- height: 100%;
- background: #F9F9F9;
- }
- .home-bottom {
- background-color: #f9f9f9;
- }
- .content {
- width: 100%;
- margin-top: 24rpx;
- padding: 0 30rpx;
- padding-bottom: 30rpx;
- background-color: #F9F9F9;
-
- .content-item {
- margin-bottom: 24rpx;
- padding: 0 24rpx;
- padding-top: 20rpx;
- padding-bottom: 20rpx;
- height: 204rpx;
- background: #FFFFFF;
- box-shadow: 0px 4rpx 24rpx -10rpx rgba(101, 95, 90, 0.2);
- border-radius: 12rpx;
- display: flex;
- align-items: center;
- justify-content: space-between;
- .content-item-main {
- flex: 1;
- display: flex;
- flex-direction: column;
- align-items: flex-start;
- justify-content: center;
- margin-left: 20rpx;
- margin-top: 12rpx;
- .content-item-main-text {
- color: #333333;
- font-size: 30rpx;
- }
- .content-item-main-call {
- color: #666666;
- font-size: 26rpx;
- display: flex;
- align-items: center;
- justify-content: flex-start;
- }
- }
- .content-item-right {
- flex: none;
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- .content-item-right-text {
- font-weight: bold;
- color: #FF6201;
- font-size: 24rpx;
- margin-top: 16rpx;
- }
- }
- }
- }
- // 搜索
- .search {
- padding: 0 30rpx;
- height: 124rpx;
- background-color: $bgColor;
- box-shadow: 0px 4rpx 8rpx 0px rgba(0, 0, 0, 0.04);
- @include flexlayout;
- ::v-deep .u-input {
- width: 690rpx !important;
- height: 68rpx !important;
- background: #F1F1F1;
- border-radius: 74rpx;
- }
- ::v-deep .u-input__content__field-wrapper {
- padding-left: 36rpx;
- }
- ::v-deep .u-input__content__field-wrapper__field {
- color: #999999 !important;
- font-size: 28rpx !important;
- }
- }
- </style>
|