feng-flow.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <template>
  2. <view>
  3. <view class="feng_flow">
  4. <view class="flow_block">
  5. <view class="flow_item" v-for="(item, i1) in lists1" :key="i1">
  6. <image :src="item.pic" mode="widthFix" style="width: 100%;"></image>
  7. <view class="flow_item_con">
  8. <view class="flow_item_title">¥{{ item.price }}</view>
  9. <view class="flow_item_des">{{ item.id }}{{ item.yishujia }}</view>
  10. <view class="flow_item_des">{{ item.timu }}</view>
  11. <view class="flow_item_des">{{ item.nianfen }}</view>
  12. <view class="flow_item_des">{{ item.caizhi }}</view>
  13. <view class="flow_item_des">{{ item.chicun }}</view>
  14. </view>
  15. </view>
  16. </view>
  17. <view class="flow_block">
  18. <view class="flow_item" v-for="(item2, i2) in lists2" :key="i2">
  19. <image :src="item2.pic" mode="widthFix" style="width: 100%;"></image>
  20. <view class="flow_item_con">
  21. <view class="flow_item_title">¥{{ item2.price }}</view>
  22. <view class="flow_item_des">{{ item2.id }}{{ item2.yishujia }}</view>
  23. <view class="flow_item_des">{{ item2.timu }}</view>
  24. <view class="flow_item_des">{{ item2.nianfen }}</view>
  25. <view class="flow_item_des">{{ item2.caizhi }}</view>
  26. <view class="flow_item_des">{{ item2.chicun }}</view>
  27. </view>
  28. </view>
  29. </view>
  30. </view>
  31. <view class="feng_flow" style="display: none;">
  32. <view class="flow_block">
  33. <view class="flow_item" v-for="(data,da_i) in dataLists" :key="da_i">
  34. <image :src="data.pic" @error="imgError" @load="imgLoad" :id="da_i" mode="widthFix" style="width:100%;"></image>
  35. </view>
  36. </view>
  37. <view class="flow_block"></view>
  38. </view>
  39. </view>
  40. </template>
  41. <script>
  42. export default {
  43. name: 'fengFlow',
  44. props: {
  45. dataLists: {
  46. default: []
  47. }
  48. },
  49. data() {
  50. return {
  51. lists1: [],
  52. lists2: [],
  53. list1Height:0,
  54. list2Height:0,
  55. tmp_data:[],
  56. loaded:[], //图片加载成功数组
  57. loadErr:[], //图片加载失败数组
  58. showLoad:false
  59. };
  60. },
  61. methods: {
  62. //处理数据
  63. refresData(){
  64. this.hideLoadFlag()
  65. if(this.loaded.length + this.loadErr.length < this.tmp_data.length) return;
  66. const that = this
  67. this.tmp_data.map((da,di)=>{
  68. if(that.list1Height > that.list2Height){
  69. that.list2Height += da.img_height
  70. that.lists2.push(da)
  71. }else{
  72. that.list1Height += da.img_height
  73. that.lists1.push(da)
  74. }
  75. })
  76. },
  77. //图片加载完成补齐数据
  78. imgLoad(e){
  79. this.loaded.push(e.target.id)
  80. //存储数据
  81. this.tmp_data[e.target.id]['img_width'] = e.detail.width
  82. this.tmp_data[e.target.id]['img_height'] = e.detail.height
  83. },
  84. //图片未加载成功触发
  85. imgError(e){
  86. console.log(e)
  87. this.loadErr.push(e.target.id)
  88. },
  89. showLoadFlag(){
  90. if(!this.showLoad){
  91. this.showLoad = true
  92. uni.showLoading({
  93. title:'loading...',
  94. mask:'none'
  95. })
  96. }
  97. },
  98. hideLoadFlag(){
  99. if(this.showLoad) {
  100. uni.hideLoading();
  101. this.showLoad = false;
  102. }
  103. }
  104. },
  105. mounted() {
  106. const that = this
  107. that.tmp_data = that.dataLists
  108. that.showLoadFlag()
  109. },
  110. watch: {
  111. dataLists() {
  112. console.log('数据变了触发');
  113. this.loaded = []
  114. this.loadErr = []
  115. this.tmp_data = this.dataLists
  116. this.showLoadFlag()
  117. },
  118. loaded(){
  119. console.log('加载标记变化')
  120. //最后一个加载完成负责刷新数据
  121. this.refresData()
  122. },
  123. loadErr(){
  124. //最后一个加载完成负责刷新数据
  125. this.refresData()
  126. }
  127. }
  128. };
  129. </script>
  130. <style>
  131. .feng_flow {
  132. display: flex;
  133. padding:15upx;
  134. }
  135. .flow_block {
  136. display: flex;
  137. flex: 1;
  138. flex-direction: column;
  139. }
  140. .flow_item {
  141. margin:15upx;
  142. border-radius: 20upx;
  143. background:#f4f4f4;
  144. overflow: hidden;
  145. }
  146. .flow_item_con{padding:10upx 20upx 20upx;}
  147. .flow_item_title{position: relative;font-size:32upx;font-weight: 700;margin-bottom:5upx;}
  148. .flow_item_des{font-size:24upx;}
  149. </style>