index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. <template>
  2. <!-- 商品列表 -->
  3. <view class="goods-container">
  4. <mescroll-body ref="mescrollRef" :sticky="true" @init="mescrollInit" :down="{ native: true }" @down="downCallback" :up="upOption" @up="upCallback">
  5. <view class="diy-goods" :style="{ background: itemStyle.background }">
  6. <view class="goods-list" :class="[`display__${itemStyle.display}`, `column__${itemStyle.column}`]">
  7. <scroll-view :scroll-x="itemStyle.display === 'slide'">
  8. <view class="goods-item" v-for="(dataItem, index) in list.content" :key="index" @click="onTargetGoods(dataItem.id)">
  9. <!-- 单列商品 -->
  10. <block v-if="itemStyle.column === 1">
  11. <view class="dis-flex">
  12. <!-- 商品图片 -->
  13. <view class="goods-item_left">
  14. <image class="image" lazy-load :lazy-load-margin="0" :src="dataItem.logo"></image>
  15. </view>
  16. <view class="goods-item_right">
  17. <!-- 商品名称 -->
  18. <view v-if="itemStyle.show.includes('goodsName')" class="goods-name twoline-hide">
  19. <text>{{ dataItem.name }}</text>
  20. </view>
  21. <view class="goods-item_desc">
  22. <!-- 商品卖点 -->
  23. <view v-if="itemStyle.show.includes('sellingPoint')" class="desc-selling_point dis-flex">
  24. <text class="oneline-hide">{{ dataItem.salePoint ? dataItem.salePoint : '' }}</text>
  25. </view>
  26. <!-- 商品销量 -->
  27. <view v-if="itemStyle.show.includes('goodsSales')" class="desc-goods_sales dis-flex">
  28. <text>已售{{ dataItem.initSale ? dataItem.initSale : 0 }}件</text>
  29. </view>
  30. <!-- 商品价格 -->
  31. <view class="desc_footer">
  32. <text v-if="itemStyle.show.includes('goodsPrice')" class="price_x">¥{{ dataItem.price ? dataItem.price : '0.00' }}</text>
  33. <text class="price_y col-9" v-if="itemStyle.show.includes('linePrice') && dataItem.linePrice > 0">¥{{ dataItem.linePrice }}</text>
  34. <view class="buy-now">去购买</view>
  35. </view>
  36. </view>
  37. </view>
  38. </view>
  39. </block>
  40. <!-- 多列商品 -->
  41. <block v-else>
  42. <!-- 商品图片 -->
  43. <view class="goods-image">
  44. <image class="image" lazy-load :lazy-load-margin="0" mode="aspectFill" :src="dataItem.logo"></image>
  45. </view>
  46. <view class="detail">
  47. <!-- 商品标题 -->
  48. <view v-if="itemStyle.show.includes('goodsName')" class="goods-name twoline-hide">
  49. {{ dataItem.name }}
  50. </view>
  51. <!-- 商品价格 -->
  52. <view class="detail-price oneline-hide">
  53. <text v-if="itemStyle.show.includes('goodsPrice')" class="goods-price f-30 col-m">¥{{ dataItem.price }}</text>
  54. <text v-if="itemStyle.show.includes('linePrice') && dataItem.linePrice > 0" class="line-price col-9 f-24">¥{{ dataItem.linePrice }}</text>
  55. </view>
  56. </view>
  57. </block>
  58. </view>
  59. </scroll-view>
  60. </view>
  61. </view>
  62. </mescroll-body>
  63. </view>
  64. </template>
  65. <script>
  66. import MescrollBody from '@/components/mescroll-uni/mescroll-body.vue'
  67. import MescrollMixin from '@/components/mescroll-uni/mescroll-mixins'
  68. import { getEmptyPaginateObj, getMoreListData } from '@/utils/app'
  69. import * as GoodsApi from '@/api/goods'
  70. const pageSize = 10;
  71. export default {
  72. name: "Goods",
  73. /**
  74. * 组件的属性列表
  75. * 用于组件自定义设置
  76. */
  77. props: {
  78. itemIndex: String,
  79. itemStyle: Object,
  80. params: Object,
  81. isReflash: Boolean
  82. },
  83. components: {
  84. MescrollBody
  85. },
  86. mixins: [MescrollMixin],
  87. data() {
  88. return {
  89. list: getEmptyPaginateObj(),
  90. // 上拉加载配置
  91. upOption: {
  92. // 首次自动执行
  93. auto: true,
  94. // 每页数据的数量; 默认10
  95. page: { size: pageSize },
  96. // 数量要大于1条才显示无更多数据
  97. noMoreSize: 1,
  98. }
  99. }
  100. },
  101. watch: {
  102. isReflash(value) {
  103. if (value) {
  104. this.getGoodsList(1);
  105. }
  106. }
  107. },
  108. /**
  109. * 组件的方法列表
  110. * 更新属性和数据的方法与更新页面数据的方法类似
  111. */
  112. methods: {
  113. /**
  114. * 跳转商品详情页
  115. */
  116. onTargetGoods(goodsId) {
  117. this.$navTo(`pages/goods/detail`, { goodsId })
  118. },
  119. /**
  120. * 上拉加载的回调 (页面初始化时也会执行一次)
  121. * 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10
  122. * @param {Object} page
  123. */
  124. upCallback(page) {
  125. const app = this
  126. // 设置列表数据
  127. app.getGoodsList(page.num)
  128. .then(list => {
  129. const curPageLen = list.content.length;
  130. const totalSize = list.totalElements;
  131. app.mescroll.endBySize(curPageLen, totalSize);
  132. })
  133. .catch(() => {
  134. app.mescroll.endErr();
  135. })
  136. },
  137. /**
  138. * 获取商品列表
  139. * @param {number} pageNo 页码
  140. */
  141. getGoodsList(pageNo) {
  142. const app = this
  143. console.log('pageNo==', pageNo);
  144. const param = { page: pageNo, pageSize: pageSize }
  145. return new Promise((resolve, reject) => {
  146. GoodsApi.search(param)
  147. .then(result => {
  148. // 合并新数据
  149. const newList = result.data;
  150. app.list.content = getMoreListData(newList, app.list, pageNo)
  151. resolve(newList)
  152. })
  153. .catch(reject)
  154. })
  155. }
  156. }
  157. }
  158. </script>
  159. <style lang="scss" scoped>
  160. .goods-container {
  161. .diy-goods {
  162. .goods-list {
  163. padding: 4rpx;
  164. box-sizing: border-box;
  165. .goods-item {
  166. box-sizing: border-box;
  167. padding: 6rpx;
  168. .goods-image {
  169. position: relative;
  170. width: 100%;
  171. height: 0;
  172. padding-bottom: 100%;
  173. overflow: hidden;
  174. background: #fff;
  175. &:after {
  176. content: '';
  177. display: block;
  178. margin-top: 100%;
  179. }
  180. .image {
  181. position: absolute;
  182. width: 100%;
  183. height: 100%;
  184. top: 0;
  185. left: 0;
  186. -o-object-fit: cover;
  187. object-fit: cover;
  188. }
  189. }
  190. .detail {
  191. padding: 8rpx;
  192. background: #fff;
  193. .goods-name {
  194. height: 64rpx;
  195. line-height: 1.3;
  196. white-space: normal;
  197. color: #484848;
  198. font-size: 26rpx;
  199. font-weight: bold;
  200. }
  201. .detail-price {
  202. .goods-price {
  203. margin-right: 8rpx;
  204. }
  205. .line-price {
  206. text-decoration: line-through;
  207. }
  208. }
  209. }
  210. }
  211. &.display__slide {
  212. white-space: nowrap;
  213. font-size: 0;
  214. .goods-item {
  215. display: inline-block;
  216. }
  217. }
  218. &.display__list {
  219. .goods-item {
  220. float: left;
  221. }
  222. }
  223. &.column__2 {
  224. .goods-item {
  225. width: 50%;
  226. }
  227. }
  228. &.column__3 {
  229. .goods-item {
  230. width: 33.33333%;
  231. }
  232. }
  233. &.column__1 {
  234. .goods-item {
  235. width: 100%;
  236. height: 250rpx;
  237. margin-bottom: 10rpx;
  238. padding: 20rpx;
  239. box-sizing: border-box;
  240. background: #fff;
  241. line-height: 1.6;
  242. border: 1rpx #F5f5f5 solid;
  243. &:last-child {
  244. margin-bottom: 0;
  245. }
  246. }
  247. .goods-item_left {
  248. display: flex;
  249. width: 40%;
  250. background: #fff;
  251. align-items: center;
  252. .image {
  253. display: block;
  254. width: 220rpx;
  255. height: 200rpx;
  256. border-radius: 10rpx;
  257. border: 1rpx #cccccc solid;
  258. }
  259. }
  260. .goods-item_right {
  261. position: relative;
  262. width: 60%;
  263. .goods-name {
  264. margin-top: 20rpx;
  265. max-height: 69rpx;
  266. line-height: 1.3;
  267. white-space: normal;
  268. color: #484848;
  269. font-size: 30rpx;
  270. font-weight: bold;
  271. overflow: hidden;
  272. display: -webkit-box;
  273. -webkit-box-orient: vertical;
  274. -webkit-line-clamp: 2;
  275. }
  276. }
  277. .goods-item_desc {
  278. margin-top: 0rpx;
  279. }
  280. .desc-selling_point {
  281. width: 400rpx;
  282. font-size: 24rpx;
  283. color: #e49a3d;
  284. }
  285. .desc-goods_sales {
  286. color: #999;
  287. font-size: 24rpx;
  288. }
  289. .desc_footer {
  290. font-size: 24rpx;
  291. .price_x {
  292. margin-right: 16rpx;
  293. color: #f03c3c;
  294. font-size: 33rpx;
  295. font-weight: bold;
  296. }
  297. .price_y {
  298. text-decoration: line-through;
  299. }
  300. .buy-now {
  301. color: #FFFFFF;
  302. float: right;
  303. margin-right: 20rpx;
  304. border: solid 1rpx $fuint-theme;
  305. background: $fuint-theme;
  306. padding: 8rpx 20rpx 8rpx 20rpx;
  307. border-radius: 5rpx;
  308. display: block;
  309. }
  310. }
  311. }
  312. }
  313. }
  314. }
  315. </style>