| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- <template>
- <router-link
- :to="{
- path: '/productDetail',
- query: {
- id: info.id
- }
- }"
- class="product"
- @click="click"
- >
- <van-image width="100%" height="calc(45vw - 21.6px)" :src="getImg(changeImgs(info.pics))" fit="cover" />
- <div class="content">
- <div class="name van-ellipsis">
- {{ info.name }}
- </div>
- <div class="price" v-if="info.salable"><i class="font_family icon-icon_jiage"></i>{{ info.price }}</div>
- <div class="status" v-else>仅展示</div>
- <div class="text">
- <div class="text1" v-if="info.salable">
- <span>{{ info.sale }}/</span>
- <span>{{ info.total }}</span>
- </div>
- <div class="flex1"></div>
- <like-button :isLike="info.liked" @click="likeProduct">
- {{ info.likes }}
- </like-button>
- </div>
- </div>
- </router-link>
- </template>
- <script>
- import product from '../../mixins/product';
- export default {
- mixins: [product],
- props: {
- info: {
- type: Object,
- default: () => {
- return {};
- }
- }
- },
- setup() {
- const click = function () {
- console.log('wyt6w');
- };
- return { click };
- },
- methods: {
- likeProduct() {
- if (!this.info.liked) {
- this.$http.get(`/collection/${this.info.id}/like`).then(() => {
- this.$emit('update:info', {
- ...this.info,
- liked: true,
- likes: this.info.likes + 1
- });
- this.$toast.success('收藏成功');
- });
- } else {
- this.$http.get(`/collection/${this.info.id}/unlike`).then(() => {
- this.$emit('update:info', {
- ...this.info,
- liked: false,
- likes: this.info.likes - 1
- });
- this.$toast.success('取消收藏');
- });
- }
- }
- }
- };
- </script>
- <style lang="less" scoped>
- .product {
- width: calc(50vw - 24px);
- margin: 8px;
- background-color: @bg2;
- display: inline-block;
- border-radius: 8px;
- overflow: hidden;
- .van-image {
- overflow: hidden;
- display: block;
- }
- .content {
- padding: 10px;
- .name {
- font-size: 16px;
- font-weight: bold;
- color: #ffffff;
- line-height: 24px;
- }
- .price {
- font-size: 24px;
- font-family: OSP;
- color: @prim;
- line-height: 22px;
- padding: 7px 0;
- i {
- vertical-align: text-bottom;
- font-size: 10px;
- }
- }
- .status {
- line-height: 22px;
- padding: 7px 0;
- color: #939599;
- font-size: 16px;
- }
- }
- .text {
- display: flex;
- justify-content: space-between;
- align-items: center;
- .text1 {
- font-weight: 400;
- color: #939599;
- line-height: 24px;
- span {
- &:last-child {
- color: #fff;
- font-size: 14px;
- }
- }
- }
- }
- }
- </style>
|