waterFill.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. <template>
  2. <view class="flow-box" :style="'height: ' + loadingTop + 'px'">
  3. <view class="item"
  4. :class="left[index] == 1 ? 'left' : ''"
  5. :style="'top:' + top[index] + 'px;'"
  6. v-for="(item, index) in newList" :key="index"
  7. :data-index="index"
  8. @click="detail(item.id)">
  9. <view class="tui-pro-item" hover-class="hover" :hover-start-time="150">
  10. <image :src="item.pic" class="tui-pro-img" mode="widthFix" />
  11. <view class="tui-pro-content">
  12. <view class="tui-pro-tit">{{item.name}}</view>
  13. <view class="tui-pro-tit subTitle">{{item.subTitle}}</view>
  14. <view>
  15. <view class="tui-pro-price">
  16. <text class="tui-sale-price">¥{{item.price}}</text>
  17. <text class="tui-factory-price">¥{{item.originalPrice}}</text>
  18. </view>
  19. <view class="tui-pro-pay">{{item.stock}}人付款</view>
  20. </view>
  21. </view>
  22. </view>
  23. </view>
  24. <!-- <view class="loading" v-show="loading" :style="'top: ' + loadingTop + 'px'" >
  25. <image src="/static/loading.gif" style="width: 80rpx; height: 80rpx;"></image>
  26. </view> -->
  27. </view>
  28. </template>
  29. <script>
  30. export default {
  31. props: {
  32. // 数据列表
  33. list: {
  34. type: Array,
  35. default() {
  36. return []
  37. }
  38. },
  39. // 加载动画
  40. loading: {
  41. type: Boolean,
  42. default: false
  43. }
  44. },
  45. data() {
  46. return {
  47. mark: 0,
  48. newList: [],
  49. boxHeight: [],
  50. top: [],
  51. left: [],
  52. loadingTop: 0
  53. }
  54. },
  55. watch: {
  56. // 数据
  57. list: function (newVal, oldVal) {
  58. this.mark = oldVal.length;
  59. if (newVal != oldVal) {
  60. this.newList = this.list;
  61. this.$nextTick(function () {
  62. setTimeout(() => {
  63. this.waterFall();
  64. }, 120)
  65. })
  66. }
  67. }
  68. },
  69. created() {
  70. this.newList = this.list;
  71. this.waterFall();
  72. },
  73. methods: {
  74. // 瀑布流定位
  75. waterFall() {
  76. const query = uni.createSelectorQuery().in(this);
  77. query.selectAll('.flow-box .item').boundingClientRect(res => {
  78. let len = this.newList.length;
  79. console.log(this.newList)
  80. let height = 0;
  81. for (let i = this.mark; i < len; i++) {
  82. height = res[i].height;
  83. if (i < 2) {
  84. this.$set(this.newList[i], 'top', 0);
  85. this.$set(this.newList[i], 'left', i);
  86. this.boxHeight.push(height);
  87. this.top.push(0);
  88. this.left.push(i);
  89. } else {
  90. let minHeight = this.boxHeight[0];
  91. let index = 0;
  92. if (minHeight > this.boxHeight[1]) {
  93. minHeight = this.boxHeight[1];
  94. index = 1;
  95. }
  96. this.boxHeight[index] = minHeight + height + 5;
  97. this.top.push(minHeight + 5);
  98. this.left.push(index);
  99. this.$set(this.newList[i], 'top', minHeight + 5);
  100. this.$set(this.newList[i], 'left', index);
  101. this.loadingTop = this.boxHeight[index];
  102. }
  103. }
  104. }).exec();
  105. },
  106. detail: function(id) {
  107. this.$api.navigateTo(`/pages/goods/productDetail?id=${id}`)
  108. }
  109. }
  110. }
  111. </script>
  112. <style lang="scss" scoped>
  113. .flow-box {
  114. position: relative;
  115. color: #1a1a1a;
  116. padding-bottom: var(--window-bottom);
  117. }
  118. .flow-box .item {
  119. position: absolute;
  120. left: 0;
  121. width:350rpx;
  122. border: 1rpx solid #f9f9f9;
  123. background: #fff;
  124. border-radius: 10rpx;
  125. }
  126. .flow-box .left {
  127. left: 360rpx;
  128. }
  129. .flow-box .pic {
  130. background: #f6f6f6;
  131. position: relative;
  132. .image{
  133. width: 100%;
  134. display: block;
  135. border-radius: 12rpx 12rpx 0 0;
  136. }
  137. .flow-site{
  138. height: 40rpx;
  139. padding: 0 15rpx;
  140. border-radius: 20rpx;
  141. background: rgba(0,0,0,.3);
  142. position: absolute;
  143. left: 20rpx;
  144. bottom: 20rpx;
  145. line-height: 40rpx;
  146. color: #FFFFFF;
  147. .iconfont{
  148. font-size: $font-size-24;
  149. }
  150. .text{
  151. font-size: $font-size-24;
  152. margin:0 8rpx;
  153. }
  154. }
  155. }
  156. .flow-box .content {
  157. padding:10rpx;
  158. display: flex;
  159. justify-content: space-between;
  160. flex-wrap: wrap;
  161. border-radius: 0 0 12rpx 12rpx;
  162. &.bg{
  163. background: #FED100;
  164. }
  165. .content-title{
  166. width: 100%;
  167. font-size: $font-size-24;
  168. font-weight: bold;
  169. line-height: 30rpx;
  170. color: #333333;
  171. text-overflow:ellipsis;
  172. display: -webkit-box;
  173. word-break: break-all;
  174. -webkit-box-orient: vertical;
  175. -webkit-line-clamp: 2;
  176. overflow: hidden;
  177. margin-bottom: 10rpx;
  178. }
  179. .content-hot{
  180. height: 40rpx;
  181. margin-bottom: 10rpx;
  182. .hot{
  183. height: 40rpx;
  184. padding: 0 15rpx;
  185. border-radius: 6rpx;
  186. background: #FFF0E6;
  187. line-height: 40rpx;
  188. font-size: $font-size-24;
  189. color:#F07A22;
  190. text-align: center;
  191. }
  192. }
  193. .content-text{
  194. width: 100%;
  195. font-size: $font-size-24;
  196. line-height: 30rpx;
  197. color: #333333;
  198. text-overflow:ellipsis;
  199. display: -webkit-box;
  200. word-break: break-all;
  201. -webkit-box-orient: vertical;
  202. -webkit-line-clamp: 2;
  203. overflow: hidden;
  204. margin-bottom: 10rpx;
  205. }
  206. .content-price{
  207. font-size: $font-size-24;
  208. line-height: 30rpx;
  209. color: #333333;
  210. .price{
  211. color: #E84F13;
  212. }
  213. }
  214. .content-rank{
  215. line-height: 30rpx;
  216. font-size: 22rpx;
  217. color: #333333;
  218. margin-bottom: 10rpx;
  219. }
  220. .content-make{
  221. line-height: 30rpx;
  222. font-size: 22rpx;
  223. color: #666;
  224. }
  225. }
  226. .flow-box .content text {
  227. width: 100%;
  228. font-size: 24rpx;
  229. margin-bottom: 20rpx;
  230. }
  231. .flow-box .user {
  232. display: flex;
  233. width: 220rpx;
  234. overflow: hidden;
  235. font-size: 26rpx;
  236. color: #666;
  237. }
  238. .loading {
  239. position: absolute;
  240. width: 100%;
  241. text-align: center;
  242. padding: 20rpx 0;
  243. }
  244. </style>