goodsWaterfall.vue 6.4 KB

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