| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- <template>
- <view class="width-100 height-100 view-page">
- <!-- <view class="p-10">
- <u-search :clearabled="true" placeholder="请输入搜索关键字" v-model="keyword" :shape="square" search="doRefresh"
- @custom="doRefresh"></u-search>
- </view> -->
- <u-list @scrolltolower="scrolltolower" height="calc(100% - 180px)" lowerThreshold="10">
- <u-list-item v-for="(item, index) in list" :key="index">
- <u-cell :title="item.name" @click="toDetail(item.id)">
- <u-avatar slot="icon" shape="square" size="35" :src="item.cover"
- customStyle="margin: -3px 5px -3px 0"></u-avatar>
- </u-cell>
- </u-list-item>
- <u-loadmore :status="page.status" :loading-text="page.loadingText" :loadmore-text="page.loadmoreText"
- :nomore-text="page.nomoreText" />
- </u-list>
- </view>
- </template>
- <script>
- import themeMixins from '@/pages/yuecai/mixins/themeMixins.js';
- export default {
- mixins: [themeMixins],
- data() {
- return {
- page: {
- loading: false,
- current: 1,
- size: 10,
- total: 0,
- // loadmore loading nomore
- status: 'loadmore',
- loadingText: '正在加载中',
- loadmoreText: '上拉加载更多',
- nomoreText: '没有更多了'
- },
- keyword: '',
- list: []
- }
- },
- onLoad(options) {
- this.collectionType = options.type || '';
- },
- onShow() {
- this.keyword = '';
- this.doRefresh();
- },
- methods: {
- scrolltolower() {
- this.loadmore()
- },
- loadmore() {
- this.page.current++;
- this.getCollectionList();
- },
- doRefresh() {
- this.page.current = 1;
- this.page.status = 'loadmore'
- this.list = [];
- this.getCollectionList();
- },
- getCollectionList() {
- if (this.page.status == 'loading' || this.page.status == 'nomore') {
- // 防止重复下拉
- return;
- }
- this.page.status = 'loading';
- //
- this.$u.api.getCollectionList(this.page.current, this.page.size, {
- collectType: this.collectionType || ''
- }).then(res => {
- if (res.data.records && res.data.records.length > 0) {
- this.list.push(...res.data.records)
- }
- this.page.total = res.data.total || 0;
- if (this.page.size * this.page.current >= res.data.total) {
- this.page.status = 'nomore'
- } else {
- this.page.status = 'loadmore'
- }
- }).catch(e=> {
- this.page.status = 'loadmore'
- })
- },
- toDetail(id) {
- if (this.collectionType == 'dish') {
- uni.navigateTo({
- url: "/pages/yuecai/dish/detail/index?id=" + id,
- })
- } else if (this.collectionType == 'snacks') {
- uni.navigateTo({
- url: "/pages/yuecai/snacks/detail/index?id=" + id,
- })
- } else if (this.collectionType == 'restaurant') {
- uni.navigateTo({
- url: "/pages/yuecai/restaurant/detail/index?id=" + id,
- })
- }
- },
- deleteCollection(id, index) {
- if (this.loading) {
- return;
- }
- this.loading = true;
- this.$u.api.deleteCollection(id).then(res => {
- this.list.splice(index, 1);
- this.loading = false;
- }).catch(e => {
- this.loading = false;
- })
- }
- },
- }
- </script>
- <style scoped lang="scss">
- .view-page {
- overflow: hidden;
- }
- </style>
|