goodsWaterfall.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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. console.log(that.list1Height,that.list2Height)
  107. if (that.list1Height > that.list2Height) {
  108. that.list2Height += da.img_height
  109. that.lists2.push(da)
  110. } else {
  111. that.list1Height += da.img_height
  112. that.lists1.push(da)
  113. }
  114. })
  115. },
  116. //图片加载完成补齐数据
  117. imgLoad(e) {
  118. console.log(e.target.id,e.detail.width,e.detail.height)
  119. this.loaded.push(e.target.id)
  120. //存储数据
  121. // this.tmp_data[e.target.id]['img_width'] = e.detail.width
  122. this.tmp_data[e.target.id]['img_height'] = (167.5 * e.detail.height) / e.detail.width
  123. },
  124. //图片未加载成功触发
  125. imgError(e) {
  126. this.loadErr.push(e.target.id)
  127. },
  128. showLoadFlag() {
  129. if (!this.showLoad) {
  130. this.showLoad = true
  131. }
  132. },
  133. hideLoadFlag() {
  134. if (this.showLoad) {
  135. uni.hideLoading();
  136. this.showLoad = false;
  137. }
  138. }
  139. },
  140. mounted() {
  141. const that = this
  142. that.tmp_data = that.dataLists
  143. that.showLoadFlag()
  144. },
  145. watch: {
  146. dataLists() {
  147. this.loaded = []
  148. this.loadErr = []
  149. this.tmp_data = this.dataLists
  150. this.showLoadFlag()
  151. },
  152. loaded() {
  153. //最后一个加载完成负责刷新数据
  154. this.refresData()
  155. },
  156. loadErr() {
  157. //最后一个加载完成负责刷新数据
  158. this.refresData()
  159. }
  160. }
  161. };
  162. </script>
  163. <style lang="scss" scoped>
  164. .feng_flow {
  165. display: flex;
  166. margin: 0 30rpx;
  167. }
  168. .flow_block {
  169. display: flex;
  170. flex: 1;
  171. flex-direction: column;
  172. width: 100%;
  173. }
  174. .flow_item {
  175. margin: 15upx;
  176. border-radius: 20upx;
  177. background: #f4f4f4;
  178. overflow: hidden;
  179. }
  180. .flow_item_con {
  181. padding: 10upx 20upx 20upx;
  182. }
  183. .flow_item_title {
  184. position: relative;
  185. font-size: 32upx;
  186. font-weight: 700;
  187. margin-bottom: 5upx;
  188. }
  189. .flow_item_des {
  190. font-size: 24upx;
  191. }
  192. .pl10 {
  193. padding-left: 10rpx;
  194. }
  195. .pr10 {
  196. padding-right: 10rpx;
  197. }
  198. .product-list {
  199. display: flex;
  200. .product-item {
  201. position: relative;
  202. width: 100%;
  203. background: #fff;
  204. border-radius: 10rpx;
  205. margin-bottom: 20rpx;
  206. image {
  207. width: 100%;
  208. // height: 330rpx;
  209. border-radius: 10rpx 10rpx 0 0;
  210. }
  211. .info {
  212. padding: 14rpx 16rpx;
  213. .title {
  214. font-size: 28rpx;
  215. }
  216. .tag {
  217. border-radius: 4rpx;
  218. border: 1px solid var(--view-theme);
  219. color: var(--view-theme);
  220. font-size: 20rpx;
  221. padding: 0rpx 4rpx;
  222. margin: 10rpx 0;
  223. width: max-content;
  224. }
  225. .price-box {
  226. font-size: 34rpx;
  227. font-weight: 700;
  228. margin-top: 8px;
  229. color: var(--view-priceColor);
  230. display: flex;
  231. justify-content: space-between;
  232. // align-items: flex-end;
  233. align-items: center;
  234. text {
  235. font-size: 28rpx;
  236. }
  237. .sales {
  238. color: #999999;
  239. font-size: 24rpx;
  240. font-weight: 400;
  241. }
  242. }
  243. }
  244. }
  245. }
  246. </style>