goodsWaterfall.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. <template>
  2. <view>
  3. <view class="feng_flow">
  4. <view class="flow_block">
  5. <view class="product-list pr10" v-for="(item, i1) in lists1" :key="i1" @click="goGoodsDetail(item)">
  6. <view class="product-item">
  7. <image :src="item.image" mode="widthFix" style="width: 100%;"></image>
  8. <view class="info">
  9. <view class="title line2">{{ item.store_name }}</view>
  10. <view class="tag" v-if="item.activity && item.activity.type === '1'">秒杀</view>
  11. <view class="tag" v-if="item.activity && item.activity.type === '2'">砍价</view>
  12. <view class="tag" v-if="item.activity && item.activity.type === '3'">拼团</view>
  13. <view class="price-box">
  14. <view>
  15. <text>¥</text>
  16. {{ item.price }}
  17. </view>
  18. <view class="sales">
  19. 已售 {{item.sales}}
  20. </view>
  21. </view>
  22. </view>
  23. </view>
  24. </view>
  25. </view>
  26. <view class="flow_block">
  27. <view class="product-list pl10" v-for="(item2, i2) in lists2" :key="i2" @click="goGoodsDetail(item2)">
  28. <view class="product-item">
  29. <image :src="item2.image" mode="widthFix" style="width: 100%;"></image>
  30. <view class="info">
  31. <view class="title line2">{{ item2.store_name }}</view>
  32. <view class="tag" v-if="item2.activity && item2.activity.type === '1'">秒杀</view>
  33. <view class="tag" v-if="item2.activity && item2.activity.type === '2'">砍价</view>
  34. <view class="tag" v-if="item2.activity && item2.activity.type === '3'">拼团</view>
  35. <view class="price-box">
  36. <view>
  37. <text>¥</text>
  38. {{ item2.price }}
  39. </view>
  40. <view class="sales">
  41. 已售 {{item2.sales}}
  42. </view>
  43. </view>
  44. </view>
  45. </view>
  46. </view>
  47. </view>
  48. </view>
  49. <view class="feng_flow" style="display: none;">
  50. <view class="flow_block">
  51. <view class="flow_item" v-for="(data,da_i) in dataLists" :key="da_i">
  52. <image :src="data.image" @error="imgError" @load="imgLoad" :id="da_i" mode="widthFix"
  53. style="width:100%;"></image>
  54. </view>
  55. </view>
  56. <view class="flow_block"></view>
  57. </view>
  58. </view>
  59. </template>
  60. <script>
  61. import {
  62. goShopDetail,
  63. goPage
  64. } from '@/libs/order.js'
  65. export default {
  66. name: 'goodsWaterfall',
  67. props: {
  68. dataLists: {
  69. default: []
  70. }
  71. },
  72. data() {
  73. return {
  74. lists1: [],
  75. lists2: [],
  76. list1Height: 0,
  77. list2Height: 0,
  78. tmp_data: [],
  79. loaded: [], //图片加载成功数组
  80. loadErr: [], //图片加载失败数组
  81. showLoad: false
  82. };
  83. },
  84. methods: {
  85. goGoodsDetail(item) {
  86. goPage().then(res => {
  87. goShopDetail(item, this.uid).then(res => {
  88. uni.navigateTo({
  89. url: `/pages/goods_details/index?id=${item.id}`
  90. })
  91. })
  92. })
  93. },
  94. //处理数据
  95. refresData() {
  96. this.hideLoadFlag()
  97. if (this.loaded.length + this.loadErr.length < this.tmp_data.length) return;
  98. const that = this
  99. if (!this.tmp_data.length) {
  100. that.list1Height = 0
  101. that.list2Height = 0
  102. that.lists1 = []
  103. that.lists2 = []
  104. }
  105. this.tmp_data.map((da, di) => {
  106. if (that.list1Height > that.list2Height) {
  107. that.list2Height += da.img_height
  108. that.lists2.push(da)
  109. } else {
  110. that.list1Height += da.img_height
  111. that.lists1.push(da)
  112. }
  113. })
  114. },
  115. //图片加载完成补齐数据
  116. imgLoad(e) {
  117. this.loaded.push(e.target.id)
  118. //存储数据
  119. this.tmp_data[e.target.id]['img_width'] = e.detail.width
  120. this.tmp_data[e.target.id]['img_height'] = e.detail.height
  121. },
  122. //图片未加载成功触发
  123. imgError(e) {
  124. this.loadErr.push(e.target.id)
  125. },
  126. showLoadFlag() {
  127. if (!this.showLoad) {
  128. this.showLoad = true
  129. }
  130. },
  131. hideLoadFlag() {
  132. if (this.showLoad) {
  133. uni.hideLoading();
  134. this.showLoad = false;
  135. }
  136. }
  137. },
  138. mounted() {
  139. const that = this
  140. that.tmp_data = that.dataLists
  141. that.showLoadFlag()
  142. },
  143. watch: {
  144. dataLists() {
  145. this.loaded = []
  146. this.loadErr = []
  147. this.tmp_data = this.dataLists
  148. this.showLoadFlag()
  149. },
  150. loaded() {
  151. //最后一个加载完成负责刷新数据
  152. this.refresData()
  153. },
  154. loadErr() {
  155. //最后一个加载完成负责刷新数据
  156. this.refresData()
  157. }
  158. }
  159. };
  160. </script>
  161. <style lang="scss" scoped>
  162. .feng_flow {
  163. display: flex;
  164. margin: 0 30rpx;
  165. }
  166. .flow_block {
  167. display: flex;
  168. flex: 1;
  169. flex-direction: column;
  170. width: 100%;
  171. }
  172. .flow_item {
  173. margin: 15upx;
  174. border-radius: 20upx;
  175. background: #f4f4f4;
  176. overflow: hidden;
  177. }
  178. .flow_item_con {
  179. padding: 10upx 20upx 20upx;
  180. }
  181. .flow_item_title {
  182. position: relative;
  183. font-size: 32upx;
  184. font-weight: 700;
  185. margin-bottom: 5upx;
  186. }
  187. .flow_item_des {
  188. font-size: 24upx;
  189. }
  190. .pl10 {
  191. padding-left: 10rpx;
  192. }
  193. .pr10 {
  194. padding-right: 10rpx;
  195. }
  196. .product-list {
  197. display: flex;
  198. .product-item {
  199. position: relative;
  200. width: 100%;
  201. background: #fff;
  202. border-radius: 10rpx;
  203. margin-bottom: 20rpx;
  204. image {
  205. width: 100%;
  206. height: 330rpx;
  207. border-radius: 10rpx 10rpx 0 0;
  208. }
  209. .info {
  210. padding: 14rpx 16rpx;
  211. .title {
  212. font-size: 28rpx;
  213. }
  214. .tag {
  215. border-radius: 4rpx;
  216. border: 1px solid var(--view-theme);
  217. color: var(--view-theme);
  218. font-size: 20rpx;
  219. padding: 0rpx 4rpx;
  220. margin: 10rpx 0;
  221. width: max-content;
  222. }
  223. .price-box {
  224. font-size: 34rpx;
  225. font-weight: 700;
  226. margin-top: 8px;
  227. color: var(--view-priceColor);
  228. display: flex;
  229. justify-content: space-between;
  230. // align-items: flex-end;
  231. align-items: center;
  232. text {
  233. font-size: 28rpx;
  234. }
  235. .sales {
  236. color: #999999;
  237. font-size: 24rpx;
  238. font-weight: 400;
  239. }
  240. }
  241. }
  242. }
  243. }
  244. </style>