123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300 |
- <template>
- <view class="main">
- <view class="one">
- <input type="text" v-model="searchInfo.name" @input="toInput" placeholder="搜索名称">
- </view>
- <view class="two">
- <scroll-view scroll-y="true" class="scroll-view" @scrolltolower="toPage" @scroll="toScroll">
- <view class="list-scroll-view">
- <view class="list" v-for="(item, index) in list" :key="index" @tap="toInfo(item)">
- <image class="image" :src="item.file&&item.file.length>0?item.file[0].url:''" mode="aspectFill">
- </image>
- <view class="list_1">
- <view class="top">
- <view class="name textOne">{{ item.name ||'暂无'}}</view>
- <view class="collect">
- <uni-fav :checked="item.is_collect" @tap.stop="onClick(item)" />
- </view>
- </view>
- <view class="other other_2">
- <text>入离时间:</text>{{ item.start_time||'暂无' }}-{{ item.end_time||'暂无' }}
- </view>
- <view class="other other_2"><text>联系电话:</text>{{ item.phone||'暂无' }}</view>
- <view class="other other_2 textOne">{{ item.address ||'暂无'}}</view>
- </view>
- </view>
- <view class="is_bottom" v-if="is_bottom">
- <text>{{config.bottom_title||'到底了!'}}</text>
- </view>
- </view>
- </scroll-view>
- </view>
- </view>
- </template>
- <script>
- import moment from 'moment';
- export default {
- data() {
- return {
- type: '',
- searchInfo: {},
- config: {},
- user: {},
- list: [],
- total: 0,
- skip: 0,
- limit: 10,
- page: 0,
- // 数据是否触底
- is_bottom: false,
- scrollTop: 0,
- }
- },
- onLoad: async function(e) {
- const that = this;
- that.$set(that, `type`, e && e.type || '');
- uni.setNavigationBarTitle({
- title: e && e.title || '分类'
- });
- that.searchConfig();
- },
- onShow: async function(e) {
- const that = this;
- await that.searchToken();
- await that.clearPage();
- await that.search();
- },
- methods: {
- searchToken() {
- const that = this;
- try {
- const res = uni.getStorageSync('token');
- if (res) that.$set(that, `user`, res);
- } catch (e) {
- uni.showToast({
- title: err.errmsg,
- icon: 'error',
- duration: 2000
- });
- }
- },
- searchConfig() {
- const that = this;
- try {
- const res = uni.getStorageSync('config');
- if (res) that.$set(that, `config`, res);
- } catch (e) {
- uni.showToast({
- title: err.errmsg,
- icon: 'error',
- duration: 2000
- });
- }
- },
- // 查询
- async search() {
- const that = this;
- let info = {
- skip: that.skip,
- limit: that.limit,
- is_use: '0',
- status: '1'
- }
- if (that.user._id) info.user = that.user._id
- const res = await that.$api(`/hotel/hotel`, 'GET', {
- ...info,
- ...that.searchInfo
- })
- if (res.errcode == '0') {
- let list = [...that.list, ...res.data];
- that.$set(that, `list`, list)
- that.$set(that, `total`, res.total)
- } else {
- uni.showToast({
- title: res.errmsg,
- });
- }
- },
- // 输入框
- toInput(e) {
- const that = this;
- if (that.searchInfo.name) that.$set(that.searchInfo, `name`, e.detail.value)
- else that.$set(that, `searchInfo`, {})
- that.clearPage();
- that.search();
- },
- // 详情
- toInfo(e) {
- uni.navigateTo({
- url: `/pagesHome/hotel/info?id=${e.id||e._id}`
- })
- },
- // 收藏
- async onClick(item) {
- const that = this;
- if (that.user && that.user._id) {
- let res;
- if (item.is_collect == false) {
- const form = {
- user: that.user._id,
- source: item._id,
- source_type: "hotel",
- type: '1',
- create_time: moment().format('YYYY-MM-DD HH:mm:ss'),
- }
- res = await that.$api(`/like`, 'POST', form);
- } else res = await that.$api(`/like/${item.collect}`, 'DELETE', {})
- if (res.errcode == '0') {
- that.clearPage();
- that.search()
- }
- } else {
- uni.navigateTo({
- url: `/pagesIndex/login/index`
- })
- }
- },
- // 分页
- toPage(e) {
- const that = this;
- let list = that.list;
- let limit = that.limit;
- if (that.total > list.length) {
- uni.showLoading({
- title: '加载中',
- mask: true
- })
- let page = that.page + 1;
- that.$set(that, `page`, page)
- let skip = page * limit;
- that.$set(that, `skip`, skip)
- that.searchComment();
- uni.hideLoading();
- } else that.$set(that, `is_bottom`, true)
- },
- // 触底
- toScroll(e) {
- const that = this;
- let up = that.scrollTop;
- that.$set(that, `scrollTop`, e.detail.scrollTop);
- let num = Math.sign(up - e.detail.scrollTop);
- if (num == 1) that.$set(that, `is_bottom`, false);
- },
- // 清空列表
- clearPage() {
- const that = this;
- that.$set(that, `list`, [])
- that.$set(that, `skip`, 0)
- that.$set(that, `limit`, 10)
- that.$set(that, `page`, 0)
- },
- }
- }
- </script>
- <style lang="scss" scoped>
- .main {
- display: flex;
- flex-direction: column;
- width: 100vw;
- height: 100vh;
- .one {
- display: flex;
- justify-content: center;
- align-items: center;
- padding: 2vw;
- input {
- width: 100%;
- padding: 2vw;
- background-color: var(--f1Color);
- font-size: var(--font14Size);
- border-radius: 5px;
- }
- }
- .two {
- position: relative;
- flex-grow: 1;
- background-color: var(--f9Color);
- margin: 2vw 0 0 0;
- .list {
- display: flex;
- background-color: var(--mainColor);
- border: 1px solid var(--f5Color);
- padding: 2vw;
- margin: 2vw 2vw 0 2vw;
- border-radius: 5px;
- .image {
- width: 22vw;
- height: 22vw;
- border-radius: 5px;
- }
- .list_1 {
- width: 67vw;
- padding: 0 0 0 2vw;
- .top {
- display: flex;
- justify-content: space-between;
- align-items: center;
- .name {
- width: 50vw;
- font-size: var(--font14Size);
- font-weight: bold;
- padding: 0 0 1vw 0;
- }
- }
- .other {
- font-size: var(--font12Size);
- padding: 0 0 2px 0;
- text {
- color: #000;
- }
- }
- .other_1 {
- color: red;
- }
- .other_2 {
- color: var(--f85Color);
- }
- }
- }
- }
- }
- .scroll-view {
- position: absolute;
- top: 0;
- left: 0;
- right: 0;
- bottom: 0;
- .list-scroll-view {
- display: flex;
- flex-direction: column;
- }
- }
- .is_bottom {
- width: 100%;
- text-align: center;
- text {
- padding: 2vw 0;
- display: inline-block;
- color: var(--f85Color);
- font-size: var(--font14Size);
- }
- }
- </style>
|