Blame view

apps/components/products/product-group-item.vue 3.71 KB
陈峰 authored
1 2 3
<template>
  <div
    class="product-item"
htoooth authored
4 5
    :class="{single}"
    @click="onClick">
陈峰 authored
6 7 8 9 10 11 12
    <div class="product-content">
      <ImageFormat :lazy="lazy" class="product-image" :src="product.productImage" :width="136" :height="180"></ImageFormat>
      <div class="product-info">
        <p class="product-name">{{product.productName}}</p>
        <p class="price">¥{{product.salesPrice}}</p>
      </div>
    </div>
陈峰 authored
13
    <AuthComponent
陈峰 authored
14
      class="btn-fav hover-opacity"
陈峰 authored
15 16
      @click="onFav"
      :class="favClass">{{favText}}</AuthComponent>
陈峰 authored
17 18 19 20 21
  </div>
</template>

<script>
import {createNamespacedHelpers} from 'vuex';
TaoHuang authored
22
const {mapActions} = createNamespacedHelpers('product');
陈峰 authored
23 24 25 26 27 28

export default {
  name: 'ProductGroupItem',
  props: {
    single: Boolean,
    lazy: Boolean,
陈峰 authored
29 30
    product: Object,
    share: Boolean
陈峰 authored
31 32 33 34 35 36 37
  },
  data() {
    return {
      posting: false,
      favorite: this.product.favorite
    };
  },
陈峰 authored
38 39 40 41 42
  watch: {
    'product.favorite'(val) {
      this.favorite = val;
    }
  },
陈峰 authored
43 44 45 46 47 48
  computed: {
    favClass() {
      return {'btn-is-fav': this.favorite, loading: this.posting};
    },
    favText() {
      return this.favorite ? '已收藏' : '收藏';
TaoHuang authored
49
    }
陈峰 authored
50 51 52 53
  },
  methods: {
    ...mapActions(['postProductFav']),
    async onFav() {
陈峰 authored
54 55 56
      if (this.share) {
        return this.$links.toDownloadApp();
      }
陈峰 authored
57 58 59
      if (this.posting) {
        return;
      }
TaoHuang authored
60
陈峰 authored
61 62 63 64
      this.posting = true;
      const favorite = !this.favorite;

      const result = await this.postProductFav({
陈峰 authored
65
        productId: this.product.productId,
陈峰 authored
66 67 68 69 70 71 72
        favorite,
        productType: this.product.productType
      });

      this.posting = false;

      if (result.code === 200) {
yyq authored
73 74 75 76
        if (favorite) {
          this.prompt = this.$grassPrompt({
            img: this.product.productImage,
            title: '收藏成功',
TaoHuang authored
77 78 79 80 81 82
            desc: '可在 [我的-商品收藏] 页面查看',
            onClick: () => {
              this.$yoho.goPage('go.fav', {
                favType: 0
              });
            }
TaoHuang authored
83
          }, 3000);
yyq authored
84 85 86 87 88 89 90 91 92
        } else {
          this.prompt && this.prompt.hide();
          this.$createToast({
            txt: '取消收藏成功',
            type: 'success',
            time: 1000
          }).show();
        }
陈峰 authored
93 94 95 96 97 98 99 100
        this.favorite = favorite;
      } else {
        this.$createToast({
          txt: result.message || '服务器开小差了',
          type: 'warn',
          time: 1000
        }).show();
      }
htoooth authored
101 102
    },
    onClick() {
htoooth authored
103
      this.product.product_skn && this.$yoho.goProductDetail(this.product.product_skn);
陈峰 authored
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
    }
  }
};
</script>

<style lang="scss" scoped>
.product-item {
  position: relative;
  margin-top: 20px;
  margin-right: 20px;
  margin-left: 30px;
  height: 180px;
  width: 580px;
  background-color: #fff;
  box-shadow: 0 5px 10px 0 rgba(107, 95, 95, 0.2);
  display: inline-block;
  padding: 10px 20px;
  white-space: initial;

  &:last-child {
陈峰 authored
124
    margin-right: 50px;
陈峰 authored
125 126 127
  }

  &.single {
陈峰 authored
128
    width: 670px;
陈峰 authored
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
  }
}

.product-content {
  display: flex;
  width: 100%;
  height: 100%;
}

.product-image {
  width: 136px;
  height: 180px;
  margin-top: -30px;
}

.product-info {
  padding-left: 20px;
  flex: 1;

  .product-name {
    font-size: 24px;
    color: #9b9b9b;
    letter-spacing: -0.25PX;
    height: 104px;
    display: flex;
    align-content: center;
  }

  .price {
    font-size: 32px;
    color: #d0021b;
    letter-spacing: -0.34PX;
  }
}

.btn-fav {
  position: absolute;
  bottom: 20px;
  right: -20px;
  width: 120px;
  height: 50px;
  padding: 0;
  font-size: 24px;
  background-color: #444;
  background-size: contain;
  display: flex;
  justify-content: center;
  align-items: center;
  color: #fff;

  &.btn-is-fav {
    background-color: #b0b0b0;
  }

  & /deep/ .iconfont {
    margin: 0;
  }
}
</style>