my-card.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. <template>
  2. <view class="card" :style="{ width: cardWidth, height: cardHeight }">
  3. <!-- <view class="product-info">-->
  4. <!-- <view class="product-name">{{ product.productName }}</view>-->
  5. <!-- <view class="product-price">售价:{{ product.productSellPrice }}元</view>-->
  6. <!-- <view v-if="product.productState === '售空'" class="product-state">{{ product.productState }}</view>-->
  7. <!-- </view>-->
  8. <!-- <view class="product-bid-price">原价:{{ product.productBidPrice }}元</view>-->
  9. <!-- <view v-if="product.productInfo" class="product-info">{{ product.productInfo }}</view>-->
  10. <!-- <view class="product-icon" @click.stop="goToDetailPage">-->
  11. <!-- <image :src="product.productIcons" class="plus-icon"></image>-->
  12. <!-- <text class="select-spec">选择规格</text>-->
  13. <!-- </view>-->
  14. <view class="img">
  15. <image :src="product.productIcons" lazy-load="true" style="border-radius: 10px"></image>
  16. </view>
  17. <view class="info">
  18. <view class="title">{{ product.productName }}</view>
  19. <view v-if="product.productState === '售空'" class="state">{{ product.productState }}</view>
  20. <view class="price">售价:{{ product.productSellPrice }}元</view>
  21. <!-- 一个加号按钮表示添加商品 -->
  22. <view class="add" @click.stop="addCart">+</view>
  23. </view>
  24. </view>
  25. </template>
  26. <script>
  27. import { mapMutations } from 'vuex';
  28. export default {
  29. props: {
  30. product:
  31. {
  32. type: Object,
  33. default: null
  34. },
  35. cardWidth: {
  36. type: String,
  37. default: '100%'
  38. },
  39. cardHeight: {
  40. type: String,
  41. default: 'auto'
  42. }
  43. },
  44. methods: {
  45. ...mapMutations('m_cart',['addToCart']),
  46. addCart() {
  47. let goods = {
  48. goods_id: this.product.id,
  49. goods_name: this.product.productName,
  50. goods_price: this.product.productSellPrice,
  51. goods_count: 1,
  52. goods_small_logo: this.product.productIcons,
  53. goods_state: true
  54. }
  55. this.addToCart(goods)
  56. },
  57. goToDetailPage() {
  58. // 跳转到商品详情页面,可以根据实际需求处理
  59. uni.navigateTo({
  60. url: `/pages/detail/detail?id=${this.id}`
  61. });
  62. },
  63. }
  64. }
  65. </script>
  66. <style lang="scss" scoped>
  67. .card {
  68. display: flex;
  69. flex-direction: column;
  70. padding: 20rpx;
  71. border-bottom: 1px solid #eee;
  72. cursor: pointer;
  73. }
  74. .product-info {
  75. display: flex;
  76. justify-content: space-between;
  77. align-items: center;
  78. }
  79. .product-name {
  80. font-size: 16px;
  81. font-weight: bold;
  82. }
  83. .product-price {
  84. color: #f60;
  85. }
  86. .product-state {
  87. color: #f00;
  88. }
  89. .product-bid-price {
  90. color: #999;
  91. margin-top: 5rpx;
  92. }
  93. .product-info {
  94. font-size: 12px;
  95. color: #999;
  96. margin-top: 5rpx;
  97. }
  98. .product-icon {
  99. display: flex;
  100. justify-content: center;
  101. align-items: center;
  102. margin-top: 10rpx;
  103. }
  104. .plus-icon {
  105. width: 20rpx;
  106. height: 20rpx;
  107. margin-right: 5rpx;
  108. }
  109. .select-spec {
  110. font-size: 14px;
  111. color: #333;
  112. }
  113. .card {
  114. display: flex;
  115. //align-items: first;
  116. flex-direction: row;
  117. padding: 10px;
  118. border-radius: 8px;
  119. box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  120. background-color: #fff;
  121. }
  122. .img {
  123. width: 80px;
  124. height: 80px;
  125. border-radius: 4px;
  126. //overflow: hidden;
  127. }
  128. .img image {
  129. width: 100%;
  130. height: 100%;
  131. }
  132. .info {
  133. flex: 1;
  134. padding-left: 10px;
  135. display: flex;
  136. flex-direction: column;
  137. }
  138. .title {
  139. font-size: 16px;
  140. font-weight: bold;
  141. margin-bottom: 5px;
  142. }
  143. .state {
  144. color: #ff0000;
  145. font-size: 12px;
  146. margin-bottom: 5px;
  147. }
  148. .price {
  149. font-size: 14px;
  150. color: #666;
  151. margin-bottom: 5px;
  152. }
  153. .add {
  154. width: 24px;
  155. height: 24px;
  156. line-height: 24px;
  157. text-align: center;
  158. border-radius: 50%;
  159. background-color: #07c160;
  160. color: #fff;
  161. font-size: 16px;
  162. font-weight: bold;
  163. }
  164. </style>
  165. <!--<template>-->
  166. <!-- <view class="card" :style="{ width: cardWidth, height: cardHeight }" @click="handleClick">-->
  167. <!-- <view class="product-info">-->
  168. <!-- <view class="product-name">{{ product.productName }}</view>-->
  169. <!-- <view class="product-price">售价:{{ product.productSellPrice }}元</view>-->
  170. <!-- <view v-if="product.productState === '售空'" class="product-state">{{ product.productState }}</view>-->
  171. <!-- </view>-->
  172. <!-- <view class="product-bid-price">原价:{{ product.productBidPrice }}元</view>-->
  173. <!-- <view v-if="product.productInfo" class="product-info">{{ product.productInfo }}</view>-->
  174. <!-- </view>-->
  175. <!--</template>-->
  176. <!--<script>-->
  177. <!--export default {-->
  178. <!-- props: {-->
  179. <!-- product: {-->
  180. <!-- type: Object,-->
  181. <!-- required: true-->
  182. <!-- },-->
  183. <!-- cardWidth: {-->
  184. <!-- type: String,-->
  185. <!-- default: '100%'-->
  186. <!-- },-->
  187. <!-- cardHeight: {-->
  188. <!-- type: String,-->
  189. <!-- default: 'auto'-->
  190. <!-- }-->
  191. <!-- },-->
  192. <!-- methods: {-->
  193. <!-- handleClick() {-->
  194. <!-- // 处理点击事件,可以在父组件中监听该事件-->
  195. <!-- this.$emit('click', this.id);-->
  196. <!-- }-->
  197. <!-- }-->
  198. <!--}-->
  199. <!--</script>-->
  200. <!--<style lang="scss" scoped>-->
  201. <!--.card {-->
  202. <!-- display: flex;-->
  203. <!-- flex-direction: column;-->
  204. <!-- padding: 20rpx;-->
  205. <!-- border-bottom: 1px solid #eee;-->
  206. <!-- cursor: pointer;-->
  207. <!--}-->
  208. <!--.product-info {-->
  209. <!-- display: flex;-->
  210. <!-- justify-content: space-between;-->
  211. <!-- align-items: center;-->
  212. <!--}-->
  213. <!--.product-name {-->
  214. <!-- font-size: 16px;-->
  215. <!-- font-weight: bold;-->
  216. <!--}-->
  217. <!--.product-price {-->
  218. <!-- color: #f60;-->
  219. <!--}-->
  220. <!--.product-state {-->
  221. <!-- color: #f00;-->
  222. <!--}-->
  223. <!--.product-bid-price {-->
  224. <!-- color: #999;-->
  225. <!-- margin-top: 5rpx;-->
  226. <!--}-->
  227. <!--.product-info {-->
  228. <!-- font-size: 12px;-->
  229. <!-- color: #999;-->
  230. <!-- margin-top: 5rpx;-->
  231. <!--}-->
  232. <!--</style>-->
  233. <!--<template>-->
  234. <!-- <view class="card">-->
  235. <!-- </view>-->
  236. <!--</template>-->
  237. <!--<script>-->
  238. <!--export default {-->
  239. <!-- data() {-->
  240. <!-- return {};-->
  241. <!-- },-->
  242. <!-- props: {-->
  243. <!-- id: {-->
  244. <!-- type: Number,-->
  245. <!-- default: 0-->
  246. <!-- },-->
  247. <!-- productState: {-->
  248. <!-- type: String,-->
  249. <!-- default: '充足'-->
  250. <!-- },-->
  251. <!-- productName: {-->
  252. <!-- type: String,-->
  253. <!-- default: '默认名称'-->
  254. <!-- },-->
  255. <!-- productBidPrice: {-->
  256. <!-- type: Number,-->
  257. <!-- default: 0-->
  258. <!-- },-->
  259. <!-- productSellPrice: {-->
  260. <!-- type: Number,-->
  261. <!-- default: 0-->
  262. <!-- },-->
  263. <!-- productInfo:{-->
  264. <!-- type:String,-->
  265. <!-- default:''-->
  266. <!-- }-->
  267. <!-- }-->
  268. <!--}-->
  269. <!--</script>-->
  270. <!--<style lang="scss">-->
  271. <!--</style>-->