goodsLista.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <template>
  2. <view>
  3. <view class="feng_flow">
  4. <view class="flow_block">
  5. <view class="flow_item" v-for="(i, i1) in lists1" :key="i1">
  6. <image :src="Url" mode="widthFix" style="width: 100%;"></image>
  7. <view class="flow_item_con" v-if="false">
  8. <view class="flow_item_title">¥{{ type == 2 ? a.trade_price : a.cost_price }}</view>
  9. <view class="flow_item_des">{{ i.trade_give_num }}</view>
  10. </view>
  11. </view>
  12. </view>
  13. <view class="flow_block">
  14. <view class="flow_item" v-for="(a, i2) in lists2" :key="i2">
  15. <image :src="Url" mode="widthFix" style="width: 100%;"></image>
  16. <view class="flow_item_con" v-if="false">
  17. <view class="flow_item_title">¥{{ type == 2 ? a.trade_price : a.cost_price }}</view>
  18. <view class="flow_item_des">{{ a.trade_give_num }}</view>
  19. </view>
  20. </view>
  21. </view>
  22. </view>
  23. <view class="feng_flow" style="display: none;">
  24. <view class="flow_block">
  25. <view class="flow_item" v-for="(data,da_i) in dataLists" :key="da_i">
  26. <image :src="data.zipurl" @error="imgError" @load="imgLoad" :id="da_i" mode="widthFix" style="width:100%;"></image>
  27. </view>
  28. </view>
  29. <view class="flow_block"></view>
  30. </view>
  31. </view>
  32. </template>
  33. <script>
  34. import { get, post } from "@/request/api.js";
  35. export default {
  36. name: 'fengFlow',
  37. props: {
  38. long: {
  39. type: Number,
  40. default: 2,
  41. },
  42. type: {
  43. type: String,
  44. default: "3",
  45. },
  46. },
  47. data() {
  48. return {
  49. dataLists: [],
  50. lists1: [],
  51. lists2: [],
  52. list1Height: 0,
  53. list2Height: 0,
  54. tmp_data: [],
  55. loaded: [], //图片加载成功数组
  56. loadErr: [], //图片加载失败数组
  57. showLoad: false,
  58. Url: "https://teaclub.oss-cn-chengdu.aliyuncs.com/ShuZiTea/goods/20221008/bba4ab41-ec1a-462f-8d3c-5b36d81a3a1a.jpg"
  59. };
  60. },
  61. onLoad() {},
  62. methods: {
  63. // 获取作品列表
  64. loadData(page) {
  65. post("goods/goodsList",{
  66. type: this.type,
  67. page: page ? page : 1
  68. }).then((res) => {
  69. if(page == 1) this.dataLists = []
  70. if (res.code === 0) {
  71. this.dataLists = [...this.dataLists ,...res.data.data]
  72. }
  73. });
  74. },
  75. //处理数据
  76. refresData() {
  77. this.hideLoadFlag()
  78. if (this.loaded.length + this.loadErr.length < this.tmp_data.length) return;
  79. const that = this
  80. this.tmp_data.map((da, di) => {
  81. if (that.list1Height > that.list2Height) {
  82. that.list2Height += da.img_height
  83. that.lists2.push(da)
  84. } else {
  85. that.list1Height += da.img_height
  86. that.lists1.push(da)
  87. }
  88. })
  89. },
  90. //图片加载完成补齐数据
  91. imgLoad(e) {
  92. this.loaded.push(e.target.id)
  93. //存储数据
  94. this.tmp_data[e.target.id]['img_width'] = e.detail.width
  95. this.tmp_data[e.target.id]['img_height'] = e.detail.height
  96. },
  97. //图片未加载成功触发
  98. imgError(e) {
  99. this.loadErr.push(e.target.id)
  100. },
  101. showLoadFlag() {
  102. if (!this.showLoad) {
  103. this.showLoad = true
  104. uni.showLoading({
  105. title: 'loading...',
  106. mask: 'none'
  107. })
  108. }
  109. },
  110. hideLoadFlag() {
  111. if (this.showLoad) {
  112. uni.hideLoading();
  113. this.showLoad = false;
  114. }
  115. },
  116. },
  117. created () {
  118. this.loadData();
  119. },
  120. mounted() {
  121. const that = this
  122. that.tmp_data = that.dataLists
  123. that.showLoadFlag()
  124. },
  125. watch: {
  126. dataLists() {
  127. this.loaded = []
  128. this.loadErr = []
  129. this.tmp_data = this.dataLists
  130. this.showLoadFlag()
  131. },
  132. loaded() {
  133. //最后一个加载完成负责刷新数据
  134. this.refresData()
  135. },
  136. loadErr() {
  137. //最后一个加载完成负责刷新数据
  138. this.refresData()
  139. }
  140. }
  141. };
  142. </script>
  143. <style>
  144. .feng_flow {
  145. display: flex;
  146. padding: 15upx;
  147. }
  148. .flow_block {
  149. display: flex;
  150. flex: 1;
  151. flex-direction: column;
  152. }
  153. .flow_item {
  154. margin: 15upx;
  155. border-radius: 20upx;
  156. background: #f4f4f4;
  157. overflow: hidden;
  158. }
  159. .flow_item_con {
  160. padding: 10upx 20upx 20upx;
  161. }
  162. .flow_item_title {
  163. position: relative;
  164. font-size: 32upx;
  165. font-weight: 700;
  166. margin-bottom: 5upx;
  167. }
  168. .flow_item_des {
  169. font-size: 24upx;
  170. }
  171. </style>