index.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <template>
  2. <view>
  3. <u-swipe-action :show="item.show" :index="index"
  4. v-for="(item, index) in list" :key="item.id"
  5. @click="click" @open="open"
  6. :options="options"
  7. >
  8. <view class="item u-border-bottom">
  9. <image mode="aspectFill" :src="item.images" />
  10. <!-- 此层wrap在此为必写的,否则可能会出现标题定位错误 -->
  11. <view class="title-wrap">
  12. <text class="title u-line-2">{{ item.title }}</text>
  13. <view class="title-wrap-one">
  14. 【{{ item.text }} 】
  15. </view>
  16. </view>
  17. <view class="title-wrap-two">
  18. <view>
  19. {{ item.time }}
  20. </view>
  21. <view>
  22. {{ item.ip }}
  23. </view>
  24. </view>
  25. </view>
  26. </u-swipe-action>
  27. </view>
  28. </template>
  29. <script>
  30. export default {
  31. data() {
  32. return {
  33. list: [
  34. {
  35. id: 1,
  36. ip: 1,
  37. time: '14.23',
  38. title: '青岛市市北区赛轮轮胎经销部',
  39. text: '订单信息',
  40. images: 'https://cdn.uviewui.com/uview/common/logo.png',
  41. show: false
  42. },
  43. {
  44. id: 2,
  45. ip: 2,
  46. time: '17.23',
  47. title: '青岛市市北区赛轮轮胎经销部',
  48. text: '订单信息',
  49. images: 'https://cdn.uviewui.com/uview/common/logo.png',
  50. show: false
  51. },
  52. {
  53. id: 3,
  54. ip: 3,
  55. time: '19.23',
  56. title: '青岛市市北区赛轮轮胎经销部',
  57. text: '订单信息',
  58. images: 'https://cdn.uviewui.com/uview/common/logo.png',
  59. show: false,
  60. }
  61. ],
  62. disabled: false,
  63. btnWidth: 180,
  64. show: false,
  65. options: [
  66. {
  67. text: '收藏',
  68. style: {
  69. backgroundColor: '#007aff'
  70. }
  71. },
  72. {
  73. text: '删除',
  74. style: {
  75. backgroundColor: '#dd524d'
  76. }
  77. }
  78. ]
  79. };
  80. },
  81. methods: {
  82. click(index, index1) {
  83. if(index1 == 1) {
  84. this.list.splice(index, 1);
  85. this.$u.toast(`删除了第${index}个cell`);
  86. } else {
  87. this.list[index].show = false;
  88. this.$u.toast(`收藏成功`);
  89. }
  90. },
  91. // 如果打开一个的时候,不需要关闭其他,则无需实现本方法
  92. open(index) {
  93. // 先将正在被操作的swipeAction标记为打开状态,否则由于props的特性限制,
  94. // 原本为'false',再次设置为'false'会无效
  95. this.list[index].show = true;
  96. this.list.map((val, idx) => {
  97. if(index != idx) this.list[idx].show = false;
  98. })
  99. }
  100. }
  101. };
  102. </script>
  103. <style lang="scss" scoped>
  104. .item {
  105. display: flex;
  106. padding: 20rpx;
  107. }
  108. image {
  109. width: 120rpx;
  110. flex: 0 0 120rpx;
  111. height: 120rpx;
  112. margin-right: 20rpx;
  113. border-radius: 12rpx;
  114. }
  115. .title {
  116. text-align: left;
  117. font-size: 29rpx;
  118. color: #333333;
  119. font-weight: bold;
  120. margin-top: 20rpx;
  121. }
  122. .title-wrap-one {
  123. margin-top: 10rpx;
  124. font-size: 23rpx;
  125. color: #999999;
  126. }
  127. .title-wrap-two {
  128. margin-left: 120rpx;
  129. margin-top: 10rpx;
  130. }
  131. .title-wrap-two>view:nth-child(1) {
  132. font-size: 19rpx;
  133. color: #999999;
  134. }
  135. .title-wrap-two>view:nth-child(2) {
  136. width: 35rpx;
  137. height: 35rpx;
  138. background: #FC3228;
  139. border-radius: 50%;
  140. color: #fff;
  141. text-align: center;
  142. font-size: 19rpx;
  143. margin: 0 auto;
  144. margin-top: 5rpx;
  145. }
  146. </style>