shop_uniapp/components/collection-list/collection-list.vue

215 lines
7.8 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<mescroll-uni ref="mescrollRef" top="80rpx" @init="mescrollInit" @down="downCallback" @up="upCallback"
:down="downOption" :up="upOption">
<view class="collection-list">
<view class="goods-list p-t-20" v-show="type == 1">
<view v-for="(item, index) in collectionList" :key="item.id">
<u-swipe-action :show="selectIndex == item.id" :index="item.id" bg-color="transparent"
:btn-width="130" @click="clickBtn" @open="open" :options="options">
<view class="collection-item flex bg-white" @tap="toGoods(item)">
<u-image width="160rpx" height="160rpx" border-radius="6rpx" lazy-load class="m-r-20"
:src="item.image" />
<view class="info flex-1">
<view class="flex row-between">
<view class="name line-2">{{item.name}}</view>
</view>
<view class="flex row-between m-t-20">
<price-format :first-size="30" :second-size="26" :price="item.min_price"
:weight="400" :subscript-size="30" :color="colorConfig.primary" />
<view class="btn primary flex row-center br60 sm"
:class="{'valid muted': item.is_valid == 0}">
{{ item.is_valid == 0 ? '已失效' : '去购买'}}
</view>
</view>
</view>
</view>
</u-swipe-action>
</view>
</view>
<view class="store-list" v-show="type == 2">
<view class="m-t-20" v-for="(item, index) in collectionList" :key="item.id">
<u-swipe-action :show="selectIndex == item.id" :index="item.id" bg-color="transparent"
:btn-width="130" @click="clickBtn" @open="open" :options="options">
<view class="store-item bg-white flex" @tap="toShop(item)">
<u-image width="80rpx" height="80rpx" border-radius="60rpx" :src="item.logo" />
<view class="flex-1 m-l-10">
<view class="store-name lg">
{{item.name}}<text class="xxs tag white m-l-10 line-1"
v-if="item.type == 1">自营</text>
</view>
<view class="m-t-12 xs muted flex row-between">
主营行业:{{item.cid_desc}}
<view class="xs" v-if="item.score!=0">
评分:
<text style="color: #ffa200">
{{item.score}}
</text>
</view>
</view>
</view>
</view>
</u-swipe-action>
</view>
</view>
</view>
</mescroll-uni>
</template>
<script>
import {
getCollectGoods,
getCollectShop,
collectGoods
} from '@/api/user'
import {
changeShopFollow
} from '@/api/shop'
import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
import MescrollMoreItemMixin from "@/components/mescroll-uni/mixins/mescroll-more-item.js";
export default {
mixins: [MescrollMixin, MescrollMoreItemMixin],
name: "collection-list",
props: {
type: {
type: [String, Number]
}
},
data() {
return {
collectionList: [],
downOption: {
auto: false
},
upOption: {
auto: false,
noMoreSize: 4,
empty: {
icon: 'https://zjeloong.oss-cn-hangzhou.aliyuncs.com/uniapp/goods_null.png',
tip: '暂无收藏~',
fixed: true
}
},
options: [{
text: '取消收藏',
style: {
backgroundColor: '#FF2C3C'
}
}],
selectIndex: -1
};
},
methods: {
async upCallback(page) {
let pageNum = page.num;
let pageSize = page.size;
let {
type,
} = this;
const {
data,
code
} = type == 1 ? await getCollectGoods({
page_size: pageSize,
page_no: pageNum
}) : await getCollectShop({
page_size: pageSize,
page_no: pageNum
})
if (code == 1) {
let curPageData = data.lists;
let curPageLen = curPageData.length;
let hasNext = !!data.more;
if (page.num == 1) this.collectionList = [];
this.collectionList = this.collectionList.concat(curPageData);
this.mescroll.endSuccess(curPageLen, hasNext);
}
},
toGoods(item) {
if (item.is_valid) {
this.$Router.push({
path: '/pages/goods_details/goods_details',
query: {
id: item.id
}
})
}
},
toShop(item) {
this.$Router.push({
path: '/pages/store_index/store_index',
query: {
id: item.id
}
})
},
open(index) {
this.selectIndex = index;
},
async clickBtn(index) {
const {
code,
data,
msg
} = this.type == 1 ? await collectGoods({
goods_id: index
}) : await changeShopFollow({
shop_id: index
})
if (code == 1) {
this.$toast({
title: msg
})
this.downCallback()
}
}
},
}
</script>
<style lang="scss">
.collection-list {
width: 100%;
.goods-list {
.collection-item {
padding: 20rpx;
&:not(:last-of-type) {
border-bottom: $-solid-border;
}
.btn {
width: 148rpx;
height: 52rpx;
border: 1px solid $-color-primary;
&.valid {
background-color: #f2f2f2;
border-color: transparent;
}
}
}
}
.store-list {
margin: 0 20rpx;
.store-item {
padding: 15rpx 20rpx;
border-radius: 16rpx;
.store-name {}
.tag {
background: linear-gradient(267deg, #FF2C3C 0%, #F52E99 100%);
border-radius: 6rpx;
padding: 0 9rpx;
vertical-align: 5rpx;
}
}
}
}
</style>