SlyGoodsList.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <template>
  2. <view class="">
  3. <view :class="[attrs.queueing === 1 ? 'row-list':'column-list']" :style="$getStyle(styles.boxStyle)">
  4. <template v-for="item in goodsList">
  5. <view class="list-item-box" :style="getStyle(attrs)">
  6. <view class="list-item" :style="$getStyle(styles.goodsItem)">
  7. <image :mode="attrs.mode" :src="item.cover" :style="$getStyle(styles.goodsImage)"></image>
  8. <view class="item-details" :style="$getStyle(styles.goodsDetails)">
  9. <view class="">
  10. <view class="two-row" :style="$getStyle(styles.goodsTitle)">
  11. {{item.title}}
  12. </view>
  13. <view v-if="attrs.showSubhead" class="two-row" :style="$getStyle(styles.subheadTitle)">
  14. {{item.title}}
  15. </view>
  16. </view>
  17. <view class="goods-price" :style="$getStyle(styles.goodsPrice)">
  18. <view class="" :style="$getStyle(styles.price)">
  19. <text :style="$getStyle(styles.PriceTag)">¥</text>
  20. <text>{{item.min_sale_price}}</text>
  21. </view>
  22. <view class="original-price" :style="$getStyle(styles.originalPrice)">
  23. <text>¥</text>
  24. <text>{{item.max_market_price}}</text>
  25. </view>
  26. </view>
  27. </view>
  28. </view>
  29. </view>
  30. </template>
  31. </view>
  32. <u-loadmore :status="loadStatus" />
  33. </view>
  34. </template>
  35. <script>
  36. import Mixin from "./../Mixin.js"
  37. import {
  38. getGoodsListApi
  39. } from "./../api_list.js"
  40. export default {
  41. name: "SlyGoodsList",
  42. mixins: [Mixin],
  43. data() {
  44. return {
  45. page: 0,
  46. limit: 6,
  47. reachBottom: true,
  48. loadStatus: 'loadmore', // loading / nomore
  49. goodsList: []
  50. }
  51. },
  52. computed: {
  53. getStyle: () => {
  54. return (attrs) => {
  55. const styleObj = {};
  56. switch (attrs?.queueing) {
  57. case 1:
  58. const n = uni.upx2px(attrs?.gap || 0) + 'px'
  59. styleObj.padding = n
  60. break;
  61. case 2:
  62. const b = uni.upx2px(attrs?.gap || 0) + 'px'
  63. styleObj.paddingBottom = b
  64. break;
  65. };
  66. return styleObj
  67. }
  68. },
  69. },
  70. created() {
  71. this.getGoodsList()
  72. },
  73. methods: {
  74. onReachBottom() {
  75. if (this.loadStatus !== 'loadmore') return
  76. this.getGoodsList()
  77. },
  78. getGoodsList() {
  79. if (this.loadStatus === 'loading') return;
  80. this.loadStatus = 'loading'
  81. if (this.page < 1) {
  82. this.page = 0
  83. this.goodsList = []
  84. };
  85. this.page++;
  86. getGoodsListApi({
  87. page: this.page,
  88. limit: this.limit
  89. }).then(res => {
  90. const {
  91. page
  92. } = res;
  93. this.goodsList = this.goodsList.concat(page.list)
  94. if (this.page >= page.totalPage) {
  95. this.loadStatus = 'nomore'
  96. } else {
  97. this.loadStatus = 'loadmore'
  98. }
  99. }).catch(err => {
  100. if (this.page > 1) {
  101. this.page--;
  102. this.loadStatus = 'loadmore'
  103. } else {
  104. this.page = 0;
  105. this.loadStatus = 'nomore'
  106. }
  107. })
  108. }
  109. }
  110. }
  111. </script>
  112. <style lang="scss" scoped>
  113. @import url("../common.scss");
  114. .list-item-box {
  115. background-color: transparent;
  116. .list-item {
  117. overflow: hidden;
  118. image {
  119. flex-shrink: 0;
  120. }
  121. .original-price {
  122. text-decoration: line-through;
  123. padding-left: 8rpx;
  124. }
  125. }
  126. }
  127. .row-list {
  128. display: flex;
  129. justify-content: space-between;
  130. flex-wrap: wrap;
  131. align-items: stretch;
  132. .list-item-box {
  133. width: 50%;
  134. .list-item {
  135. width: 100%;
  136. }
  137. &:nth-child(odd) {
  138. padding-left: 0 !important;
  139. }
  140. &:nth-child(even) {
  141. padding-right: 0 !important;
  142. }
  143. &:nth-child(1),
  144. &:nth-child(2) {
  145. padding-top: 0 !important;
  146. }
  147. }
  148. .list-item {
  149. max-width: 100%;
  150. min-height: 100%;
  151. image {
  152. width: 100% !important;
  153. // margin: 0 auto;
  154. }
  155. .item-details {
  156. width: 100%;
  157. // text-align: left;
  158. display: flex;
  159. flex-direction: column;
  160. justify-content: space-between;
  161. // align-content: space-between;
  162. // justify-content: space-between;
  163. .goods-price {
  164. display: flex;
  165. align-items: flex-end;
  166. }
  167. }
  168. }
  169. }
  170. .column-list {
  171. .list-item {
  172. width: 100%;
  173. display: flex;
  174. align-items: stretch;
  175. image {
  176. max-width: 40%;
  177. height: auto !important;
  178. }
  179. .item-details {
  180. flex: 1;
  181. display: flex;
  182. flex-direction: column;
  183. justify-content: space-between;
  184. .goods-price {
  185. display: flex;
  186. align-items: flex-end;
  187. }
  188. }
  189. }
  190. }
  191. </style>