index.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <template>
  2. <div>
  3. <div class="goods-recommend">{{title ? `--${title}-- `:''}}</div>
  4. <div class="goods-list">
  5. <div @click="handleClick(item)" class="goods-item" v-for="(item, item_index) in goodsList" :key="item_index">
  6. <div class="goods-img">
  7. <u-image :src="item.thumbnail" mode="aspectFill" height="350rpx" width="100%">
  8. <u-loading slot="loading"></u-loading>
  9. </u-image>
  10. </div>
  11. <div class="goods-desc">
  12. <div class="goods-title">
  13. {{ item.goodsName }}
  14. </div>
  15. <div class="goods-bottom">
  16. <div class="goods-price">¥{{ item.price | unitPrice }}</div>
  17. </div>
  18. </div>
  19. </div>
  20. </div>
  21. </div>
  22. </template>
  23. <script>
  24. import { getGoodsList } from "@/api/goods.js";
  25. export default {
  26. data() {
  27. return {
  28. goodsList: [],
  29. params: {
  30. pageNumber: 1,
  31. },
  32. };
  33. },
  34. props: {
  35. title: {
  36. type: String,
  37. default: "",
  38. },
  39. pageSize: {
  40. type: null,
  41. default: 12,
  42. },
  43. categoryId: {
  44. type: null,
  45. default: "",
  46. },
  47. storeId: {
  48. type: null,
  49. default: "",
  50. },
  51. },
  52. mounted() {
  53. this.initGoods();
  54. },
  55. methods: {
  56. /**
  57. * 初始化商品
  58. */
  59. async initGoods() {
  60. let submit = JSON.parse(
  61. JSON.stringify(
  62. Object.assign(this.params, {
  63. pageSize: this.pageSize,
  64. categoryId: this.categoryId,
  65. storeId: this.storeId,
  66. })
  67. )
  68. );
  69. Object.keys(submit).map((key) => {
  70. if (!submit[key] || submit[key].length == 0) {
  71. delete submit[key];
  72. }
  73. });
  74. let goodsList = await getGoodsList(submit);
  75. this.goodsList.push(...goodsList.data.result.content);
  76. },
  77. handleClick(item) {
  78. uni.navigateTo({
  79. url: `/pages/product/goods?id=${item.id}&goodsId=${item.goodsId}`,
  80. });
  81. },
  82. },
  83. };
  84. </script>
  85. <style scoped lang="scss">
  86. /**商品代码 */
  87. $w_94: 94%;
  88. .goods-recommend {
  89. background: #f7f7f7;
  90. height: 100rpx;
  91. line-height: 100rpx;
  92. text-align: center;
  93. font-size: 30rpx;
  94. font-weight: bold;
  95. }
  96. .goods-list {
  97. display: flex;
  98. flex-wrap: wrap;
  99. background: #f7f7f7;
  100. }
  101. .goods-item {
  102. width: 50%;
  103. margin-bottom: 10px;
  104. border-radius: 0.4em;
  105. overflow: hidden;
  106. }
  107. .goods-img {
  108. position: relative;
  109. margin: 0 auto;
  110. width: $w_94;
  111. height: 350rpx;
  112. border-top-left-radius: 20rpx;
  113. border-top-right-radius: 20rpx;
  114. overflow: hidden;
  115. > img {
  116. width: 100%;
  117. height: 100%;
  118. }
  119. }
  120. .goods-desc {
  121. border-bottom-left-radius: 20rpx;
  122. border-bottom-right-radius: 20rpx;
  123. width: $w_94;
  124. background: #fff;
  125. padding: 8rpx 0 8rpx 8rpx;
  126. margin: 0 auto;
  127. > .goods-title {
  128. font-size: 12px;
  129. height: 70rpx;
  130. display: -webkit-box;
  131. font-weight: 500;
  132. -webkit-box-orient: vertical;
  133. -webkit-line-clamp: 2;
  134. overflow: hidden;
  135. }
  136. > .goods-bottom {
  137. display: flex;
  138. font-weight: bold;
  139. > .goods-price {
  140. line-height: 2;
  141. color: $main-color;
  142. }
  143. }
  144. }
  145. </style>