index.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. <template>
  2. <view class="wrap">
  3. <u-waterfall v-model="flowList" ref="uWaterfall">
  4. <template v-slot:left="{ leftList }">
  5. <view class="demo-warter" v-for="(item, index) in leftList" :key="index">
  6. <!-- 微信小程序需要hx2.8.11版本才支持在template中引入其他组件,比如下方的u-lazy-load组件 -->
  7. <u-lazy-load threshold="-450" border-radius="10" :image="item.image" :index="index"></u-lazy-load>
  8. <view class="demo-title">{{ item.title }}</view>
  9. <view class="demo-price">{{ item.price }}元</view>
  10. <view class="demo-tag">
  11. <view class="demo-tag-owner">自营</view>
  12. <view class="demo-tag-text">放心购</view>
  13. </view>
  14. <view class="demo-shop">{{ item.shop }}</view>
  15. <view class="u-close">
  16. <u-icon name="close-circle-fill" color="#fa3534" size="34" @click="remove(item.id)"></u-icon>
  17. </view>
  18. </view>
  19. </template>
  20. <template v-slot:right="{ rightList }">
  21. <view class="demo-warter" v-for="(item, index) in rightList" :key="index">
  22. <u-lazy-load threshold="-450" border-radius="10" :image="item.image" :index="index"></u-lazy-load>
  23. <view class="demo-title">{{ item.title }}</view>
  24. <view class="demo-price">{{ item.price }}元</view>
  25. <view class="demo-tag">
  26. <view class="demo-tag-owner">自营</view>
  27. <view class="demo-tag-text">放心购</view>
  28. </view>
  29. <view class="demo-shop">{{ item.shop }}</view>
  30. <view class="u-close">
  31. <u-icon name="close-circle-fill" color="#fa3534" size="34" @click="remove(item.id)"></u-icon>
  32. </view>
  33. </view>
  34. </template>
  35. </u-waterfall>
  36. <u-loadmore bg-color="rgb(240, 240, 240)" :status="loadStatus" @loadmore="addRandomData"></u-loadmore>
  37. </view>
  38. </template>
  39. <script>
  40. export default {
  41. data() {
  42. return {
  43. loadStatus: 'loadmore',
  44. flowList: [],
  45. list: [
  46. {
  47. price: 35,
  48. title: '北国风光,千里冰封,万里雪飘',
  49. shop: '李白杜甫白居易旗舰店',
  50. image: 'http://pic.sc.chinaz.com/Files/pic/pic9/202002/zzpic23327_s.jpg'
  51. },
  52. {
  53. price: 75,
  54. title: '望长城内外,惟余莽莽',
  55. shop: '李白杜甫白居易旗舰店',
  56. image: 'http://pic.sc.chinaz.com/Files/pic/pic9/202002/zzpic23325_s.jpg'
  57. },
  58. {
  59. price: 385,
  60. title: '大河上下,顿失滔滔',
  61. shop: '李白杜甫白居易旗舰店',
  62. image: 'http://pic2.sc.chinaz.com/Files/pic/pic9/202002/hpic2119_s.jpg'
  63. },
  64. {
  65. price: 784,
  66. title: '欲与天公试比高',
  67. shop: '李白杜甫白居易旗舰店',
  68. image: 'http://pic2.sc.chinaz.com/Files/pic/pic9/202002/zzpic23369_s.jpg'
  69. },
  70. {
  71. price: 7891,
  72. title: '须晴日,看红装素裹,分外妖娆',
  73. shop: '李白杜甫白居易旗舰店',
  74. image: 'http://pic2.sc.chinaz.com/Files/pic/pic9/202002/hpic2130_s.jpg'
  75. },
  76. {
  77. price: 2341,
  78. shop: '李白杜甫白居易旗舰店',
  79. title: '江山如此多娇,引无数英雄竞折腰',
  80. image: 'http://pic1.sc.chinaz.com/Files/pic/pic9/202002/zzpic23346_s.jpg'
  81. },
  82. {
  83. price: 661,
  84. shop: '李白杜甫白居易旗舰店',
  85. title: '惜秦皇汉武,略输文采',
  86. image: 'http://pic1.sc.chinaz.com/Files/pic/pic9/202002/zzpic23344_s.jpg'
  87. },
  88. {
  89. price: 1654,
  90. title: '唐宗宋祖,稍逊风骚',
  91. shop: '李白杜甫白居易旗舰店',
  92. image: 'http://pic1.sc.chinaz.com/Files/pic/pic9/202002/zzpic23343_s.jpg'
  93. },
  94. {
  95. price: 1678,
  96. title: '一代天骄,成吉思汗',
  97. shop: '李白杜甫白居易旗舰店',
  98. image: 'http://pic1.sc.chinaz.com/Files/pic/pic9/202002/zzpic23343_s.jpg'
  99. },
  100. {
  101. price: 924,
  102. title: '只识弯弓射大雕',
  103. shop: '李白杜甫白居易旗舰店',
  104. image: 'http://pic1.sc.chinaz.com/Files/pic/pic9/202002/zzpic23343_s.jpg'
  105. },
  106. {
  107. price: 8243,
  108. title: '俱往矣,数风流人物,还看今朝',
  109. shop: '李白杜甫白居易旗舰店',
  110. image: 'http://pic1.sc.chinaz.com/Files/pic/pic9/202002/zzpic23343_s.jpg'
  111. }
  112. ]
  113. };
  114. },
  115. onLoad() {
  116. this.addRandomData();
  117. },
  118. onReachBottom() {
  119. this.loadStatus = 'loading';
  120. // 模拟数据加载
  121. setTimeout(() => {
  122. this.addRandomData();
  123. this.loadStatus = 'loadmore';
  124. }, 1000);
  125. },
  126. methods: {
  127. addRandomData() {
  128. for (let i = 0; i < 10; i++) {
  129. let index = this.$u.random(0, this.list.length - 1);
  130. // 先转成字符串再转成对象,避免数组对象引用导致数据混乱
  131. let item = JSON.parse(JSON.stringify(this.list[index]));
  132. item.id = this.$u.guid();
  133. this.flowList.push(item);
  134. }
  135. },
  136. remove(id) {
  137. this.$refs.uWaterfall.remove(id);
  138. },
  139. clear() {
  140. this.$refs.uWaterfall.clear();
  141. }
  142. }
  143. };
  144. </script>
  145. <style>
  146. /* page不能写带scope的style标签中,否则无效 */
  147. page {
  148. background-color: rgb(240, 240, 240);
  149. }
  150. </style>
  151. <style lang="scss" scoped>
  152. .demo-warter {
  153. border-radius: 8px;
  154. margin: 5px;
  155. background-color: #ffffff;
  156. padding: 8px;
  157. position: relative;
  158. }
  159. .u-close {
  160. position: absolute;
  161. top: 32rpx;
  162. right: 32rpx;
  163. }
  164. .demo-img-wrap {
  165. }
  166. .demo-image {
  167. width: 100%;
  168. border-radius: 4px;
  169. }
  170. .demo-title {
  171. font-size: 30rpx;
  172. margin-top: 5px;
  173. color: $u-main-color;
  174. word-break: break-all;
  175. }
  176. .demo-tag {
  177. display: flex;
  178. margin-top: 5px;
  179. }
  180. .demo-tag-owner {
  181. background-color: $u-type-error;
  182. color: #ffffff;
  183. display: flex;
  184. align-items: center;
  185. padding: 4rpx 14rpx;
  186. border-radius: 50rpx;
  187. font-size: 20rpx;
  188. line-height: 1;
  189. }
  190. .demo-tag-text {
  191. border: 1px solid $u-type-primary;
  192. color: $u-type-primary;
  193. margin-left: 10px;
  194. border-radius: 50rpx;
  195. line-height: 1;
  196. padding: 4rpx 14rpx;
  197. display: flex;
  198. align-items: center;
  199. border-radius: 50rpx;
  200. font-size: 20rpx;
  201. }
  202. .demo-price {
  203. font-size: 30rpx;
  204. color: $u-type-error;
  205. margin-top: 5px;
  206. }
  207. .demo-shop {
  208. font-size: 22rpx;
  209. color: $u-tips-color;
  210. margin-top: 5px;
  211. }
  212. </style>