home-goods-item-test.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <template>
  2. <view class="px-12 mt-14">
  3. <view v-for="(product, index) in productList" :key="index" class="bg-white pb-10 rounded-8 overflow-hidden mb-14">
  4. <image class="w-all h-195" :src="product.firstImage || 'https://cdn.his.cdwjyyh.com/images/img.png'"></image>
  5. <view class="goods-count px-12 flex items-center justify-between text-white w-all h-32 rounded-6 mt--15 zi-2 relative">
  6. <view class="fw-500 fs-18">热卖爆品</view>
  7. <view class="fw-400 fs-13">已售{{ product.sales || '0' }}件</view>
  8. </view>
  9. <view class="fw-500 fs-13 text-333333 mt-11 px-12">
  10. {{ product.title || '产品名称' }}
  11. </view>
  12. <view class="flex items-center justify-between mt-8 px-12">
  13. <view class="flex items-end gap-8">
  14. <view class="text-FA341E">
  15. <text class="fs-12 fw-600">¥</text>
  16. <text class="fs-24 fw-600">{{ splitPrice(product.price).integer || '0' }}</text>
  17. <text class="fs-15 fw-600">{{ splitPrice(product.price).decimal || '0' }}</text>
  18. </view>
  19. </view>
  20. <view class="flex items-center w-110 h-34 rounded-34 overflow-hidden">
  21. <view class="w-44 h-all flex items-center justify-center bg-38D97D">
  22. <image class="w-20 h-20" src="https://cdn.his.cdwjyyh.com/images/shopping_car_icon.png"></image>
  23. </view>
  24. <view class="flex-1 h-all flex items-center justify-center bg-02B176 fw-500 text-white fs-14">
  25. 去购买
  26. </view>
  27. </view>
  28. </view>
  29. </view>
  30. <view v-if="productList.length === 0" class="bg-white pb-10 rounded-8 overflow-hidden mb-14 p-12">
  31. <view class="fw-500 fs-13 text-333333">暂无商品数据</view>
  32. </view>
  33. </view>
  34. </template>
  35. <script>
  36. export default {
  37. props: {
  38. productList: {
  39. type: Array,
  40. default: () => []
  41. }
  42. },
  43. mounted() {
  44. console.log("测试组件 - 商品列表", this.productList);
  45. console.log("测试组件 - 商品列表长度", this.productList.length);
  46. },
  47. watch: {
  48. productList: {
  49. immediate: true,
  50. handler(newVal) {
  51. console.log("测试组件 - 商品列表变化", newVal);
  52. console.log("测试组件 - 商品列表长度变化", newVal.length);
  53. }
  54. }
  55. },
  56. methods: {
  57. // 分割价格
  58. splitPrice(price) {
  59. const priceStr = parseFloat(price).toFixed(2).toString();
  60. return {
  61. integer: priceStr.split('.')[0],
  62. decimal: priceStr.split('.')[1]
  63. };
  64. }
  65. }
  66. };
  67. </script>
  68. <style scoped lang="scss">
  69. .goods-count {
  70. background: linear-gradient(to right, #FA341E, #F4A007);
  71. }
  72. </style>