CargoFull.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <template>
  2. <el-card shadow="hover" :body-style="cardBody">
  3. <div class="cargo">
  4. <!-- 内容区 -->
  5. <!-- 商品图片区 -->
  6. <div class="img" @click="handleCargoContentClick"><el-image fit="scale-down" :src="$img(cargo.sku_image, { size: 'mid' })" lazy :alt="cargo.introduction" @error="cargo.sku_image=defaultGoodsImage"></el-image></div>
  7. <!-- 价格展示区 -->
  8. <div class="price" @click="handleCargoContentClick">
  9. <!-- 价格 -->
  10. <div>
  11. <span class="main_price">¥{{ cargo.price }}</span>
  12. </div>
  13. <!-- 活动 -->
  14. <div><!-- <el-tag type="danger" hit size="mini" effect="plain">活动名称</el-tag> --></div>
  15. </div>
  16. <!-- 商品名称 -->
  17. <div class="name" @click="handleCargoContentClick">
  18. <span>{{ cargo.sku_name || cargo.goods_name || '' }}</span>
  19. <span>
  20. <el-link type="warning">{{ cargo.introduction }}</el-link>
  21. </span>
  22. </div>
  23. <!-- 成交记录 -->
  24. <div class="saling">
  25. <div>
  26. <span class="num">{{ cargo.sale_num || 0 }}</span>
  27. 人付款
  28. </div>
  29. <div>
  30. 库存剩余
  31. <span class="num">{{ cargo.stock || 0 }}</span>
  32. </div>
  33. </div>
  34. <!-- 店铺名称 -->
  35. <div class="shop" v-if="cargo.is_own">
  36. <el-tag type="danger" size="mini" effect="dark">自营</el-tag>
  37. <div>{{ cargo.site_name || '' }}</div>
  38. </div>
  39. <!-- 特殊图标区 -->
  40. <div class="tags">
  41. <el-tag v-if="cargo.is_free_shipping" type="warning" size="mini" effect="dark">包邮</el-tag>
  42. <el-tag v-if="cargo.is_virtual" type="warning" size="mini" effect="dark">虚拟商品</el-tag>
  43. </div>
  44. <!-- 按钮区 -->
  45. <div>
  46. <el-button-group class="button-group">
  47. <!-- <el-button size="mini" icon="el-icon-edit">客服</el-button> -->
  48. <el-button plain size="mini" icon="el-icon-star-off" @click="addToCollection">收藏</el-button>
  49. <el-button plain size="mini" icon="el-icon-shopping-cart-full" class="item" @click="addToCart">加入购物车</el-button>
  50. </el-button-group>
  51. </div>
  52. </div>
  53. </el-card>
  54. </template>
  55. <script>
  56. import { mapGetters } from 'vuex';
  57. import { addCollect } from "@/api/goods/goods_collect"
  58. export default {
  59. props: {
  60. cargo: {
  61. type: Object,
  62. required: true
  63. },
  64. path: {
  65. type: String,
  66. default: '/sku/'
  67. },
  68. newTab: {
  69. // 是否新窗口打开页面
  70. type: Boolean,
  71. default: true
  72. }
  73. },
  74. data() {
  75. return {
  76. cardBody: {
  77. width: '228px',
  78. height: '440px',
  79. padding: '5px'
  80. },
  81. isAdding: false // 添加操作是否进行中
  82. };
  83. },
  84. created() {},
  85. computed: {
  86. ...mapGetters(['defaultGoodsImage'])
  87. },
  88. methods: {
  89. addToCart() {
  90. if (this.isAdding) return;
  91. this.isAdding = true;
  92. this.$store
  93. .dispatch('cart/add_to_cart', this.cargo)
  94. .then((this.isAdding = false))
  95. .catch(err => err);
  96. },
  97. addToCollection() {
  98. if (this.isAdding) return;
  99. this.isAdding = true;
  100. const { goods_id, sku_id, site_id, sku_name, sku_price, sku_image } = this.cargo;
  101. addCollect({ goods_id, sku_id, site_id, sku_name, sku_price, sku_image })
  102. .then(res => {
  103. this.$message({
  104. message: '收藏成功',
  105. type: 'success'
  106. });
  107. })
  108. .catch(err => err);
  109. },
  110. handleCargoContentClick() {
  111. if (this.newTab) this.$util.pushToTab(`${this.path}${this.cargo.sku_id}`);
  112. else this.$router.push(`${this.path}${this.cargo.sku_id}`);
  113. }
  114. },
  115. };
  116. </script>
  117. <style lang="scss" scoped>
  118. .el-card {
  119. display: inline-block;
  120. }
  121. .cargo {
  122. .el-button {
  123. padding: 7px 10px;
  124. }
  125. .img {
  126. width: 100%;
  127. height: 100%;
  128. .el-image {
  129. width: 100%;
  130. height: 220px;
  131. .el-image__error {
  132. width: 100%;
  133. height: 100%;
  134. }
  135. }
  136. }
  137. .price {
  138. display: flex;
  139. flex-direction: row;
  140. justify-content: space-between;
  141. align-items: center;
  142. .main_price {
  143. color: $base-color;
  144. font-size: 24px;
  145. font-weight: 500;
  146. }
  147. }
  148. .name {
  149. font-size: 14px;
  150. line-height: 1.4;
  151. height: 40px;
  152. margin-bottom: 8px;
  153. white-space: normal;
  154. overflow: hidden;
  155. }
  156. .tags {
  157. height: 25px;
  158. margin: 5px auto;
  159. }
  160. .saling {
  161. display: flex;
  162. flex-direction: row;
  163. .num {
  164. font-size: 14px;
  165. color: #646fb0;
  166. padding: auto 3px auto 0;
  167. font-weight: 600;
  168. }
  169. div {
  170. margin: 0 10px 5px 10px;
  171. }
  172. }
  173. .shop {
  174. display: flex;
  175. flex-direction: row;
  176. align-items: center;
  177. margin: auto;
  178. div {
  179. margin-left: 15px;
  180. }
  181. }
  182. .button-group {
  183. display: flex;
  184. flex-direction: row;
  185. .item {
  186. flex-grow: 1;
  187. }
  188. }
  189. }
  190. </style>