productInfo.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <template>
  2. <router-link
  3. :to="{
  4. path: '/productDetail',
  5. query: {
  6. id: info.id
  7. }
  8. }"
  9. class="product"
  10. @click="click"
  11. >
  12. <van-image width="100%" height="calc(45vw - 21.6px)" :src="getImg(changeImgs(info.pics))" fit="cover" />
  13. <div class="content">
  14. <div class="name van-ellipsis">
  15. {{ info.name }}
  16. </div>
  17. <div class="price" v-if="info.salable"><i class="font_family icon-icon_jiage"></i>{{ info.price }}</div>
  18. <div class="status" v-else>仅展示</div>
  19. <div class="text">
  20. <div class="text1" v-if="info.salable">
  21. <span>{{ info.sale }}/</span>
  22. <span>{{ info.total }}</span>
  23. </div>
  24. <div class="flex1"></div>
  25. <like-button :isLike="info.liked" @click="likeProduct">
  26. {{ info.likes }}
  27. </like-button>
  28. </div>
  29. </div>
  30. </router-link>
  31. </template>
  32. <script>
  33. import product from '../../mixins/product';
  34. export default {
  35. mixins: [product],
  36. props: {
  37. info: {
  38. type: Object,
  39. default: () => {
  40. return {};
  41. }
  42. }
  43. },
  44. setup() {
  45. const click = function () {
  46. console.log('wyt6w');
  47. };
  48. return { click };
  49. },
  50. methods: {
  51. likeProduct() {
  52. if (!this.info.liked) {
  53. this.$http.get(`/collection/${this.info.id}/like`).then(() => {
  54. this.$emit('update:info', {
  55. ...this.info,
  56. liked: true,
  57. likes: this.info.likes + 1
  58. });
  59. this.$toast.success('收藏成功');
  60. });
  61. } else {
  62. this.$http.get(`/collection/${this.info.id}/unlike`).then(() => {
  63. this.$emit('update:info', {
  64. ...this.info,
  65. liked: false,
  66. likes: this.info.likes - 1
  67. });
  68. this.$toast.success('取消收藏');
  69. });
  70. }
  71. }
  72. }
  73. };
  74. </script>
  75. <style lang="less" scoped>
  76. .product {
  77. width: calc(50vw - 24px);
  78. margin: 8px;
  79. background-color: @bg2;
  80. display: inline-block;
  81. border-radius: 8px;
  82. overflow: hidden;
  83. .van-image {
  84. overflow: hidden;
  85. display: block;
  86. }
  87. .content {
  88. padding: 10px;
  89. .name {
  90. font-size: 16px;
  91. font-weight: bold;
  92. color: #ffffff;
  93. line-height: 24px;
  94. }
  95. .price {
  96. font-size: 24px;
  97. font-family: OSP;
  98. color: @prim;
  99. line-height: 22px;
  100. padding: 7px 0;
  101. i {
  102. vertical-align: text-bottom;
  103. font-size: 10px;
  104. }
  105. }
  106. .status {
  107. line-height: 22px;
  108. padding: 7px 0;
  109. color: #939599;
  110. font-size: 16px;
  111. }
  112. }
  113. .text {
  114. display: flex;
  115. justify-content: space-between;
  116. align-items: center;
  117. .text1 {
  118. font-weight: 400;
  119. color: #939599;
  120. line-height: 24px;
  121. span {
  122. &:last-child {
  123. color: #fff;
  124. font-size: 14px;
  125. }
  126. }
  127. }
  128. }
  129. }
  130. </style>