my-page.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <template>
  2. <view class="main p-top8 " :class="checkBoxShow?'px3':''">
  3. <template v-if="listData.length > 0">
  4. <view v-for="(item, index) in listData" :key="index"
  5. :class="checkBoxShow?'mb-3 bg-color-white pl-2':''"
  6. style="border-radius: 20rpx;">
  7. <view
  8. @click="myRowClick(item)"
  9. @longpress="handleDel(item)"
  10. >
  11. <u-checkbox v-model="item.isChecked" :name="item.id" shape="circle" @change="checkBoxCheck" v-if="checkBoxShow">
  12. <slot name="pageRow" :recordModel="item" :rowShowParams="rowShowParams"></slot>
  13. </u-checkbox>
  14. <slot v-else name="pageRow" :recordModel="item" :rowShowParams="rowShowParams"></slot>
  15. </view>
  16. </view>
  17. <!-- 底部加载时的文字 -->
  18. <view class="py3">
  19. <u-loadmore :status="status" />
  20. </view>
  21. </template>
  22. <template v-else>
  23. <view class="empty">
  24. <u-empty text="暂无数据" mode="list"></u-empty>
  25. </view>
  26. </template>
  27. </view>
  28. </template>
  29. <script>
  30. export default {
  31. props: {
  32. loadData: {
  33. type: Function,
  34. required: true
  35. },
  36. checkBoxShow: {
  37. type: Boolean,
  38. default: false
  39. },
  40. pageSize: {
  41. type: Number,
  42. default: 6
  43. },
  44. swipeAction: {
  45. type: Boolean,
  46. default: false
  47. },
  48. // 组件背景颜色
  49. swipeBgColor: {
  50. type: String,
  51. default: '#ffffff'
  52. },
  53. rowShowParams: {
  54. type: Object,
  55. default: () => {}
  56. },
  57. swipeOptions: {
  58. type: Array,
  59. default: () => [
  60. ]
  61. }
  62. },
  63. data() {
  64. return {
  65. // 加载更多
  66. status: 'loadmore',
  67. pageNum: 1,
  68. type: '',
  69. loadMore: true,
  70. listData: [],
  71. checkData: {}
  72. };
  73. },
  74. mounted() {
  75. },
  76. created() {
  77. },
  78. methods: {
  79. checkBoxCheck(checkItem) {
  80. if (checkItem.value) {
  81. this.checkData[checkItem.name] = checkItem.name
  82. } else {
  83. delete this.checkData[checkItem.name]
  84. }
  85. },
  86. initPage() {
  87. // 请求结束取消刷新
  88. this.pageNum = 1;
  89. this.loadMore = true;
  90. this.listData = [];
  91. this.initData();
  92. },
  93. pagePullDownRefresh() {
  94. // 请求结束取消刷新
  95. this.pageNum = 1;
  96. this.loadMore = true;
  97. this.listData = [];
  98. this.initData();
  99. uni.stopPullDownRefresh();
  100. },
  101. pageReachBottom() {
  102. if (this.loadMore) {
  103. this.pageNum++;
  104. this.initData();
  105. }
  106. },
  107. initData() {
  108. this.status = 'loading';
  109. const parameter = { pageNum: this.pageNum, pageSize: this.pageSize };
  110. let result = null
  111. // #ifdef MP-WEIXIN
  112. result = this.$parent[this.loadData.name](parameter)
  113. // #endif
  114. // #ifdef H5
  115. result = this.loadData(parameter)
  116. // #endif
  117. // #ifdef APP-PLUS
  118. result = this.loadData(parameter)
  119. // #endif
  120. if (
  121. (typeof result === 'object' || typeof result === 'function') &&
  122. typeof result.then === 'function'
  123. ) {
  124. result.then(res => {
  125. const pages = res.pages;
  126. const list = res.rows;
  127. list.forEach(item => {
  128. item.isChecked = false
  129. })
  130. // list.forEach(item => {
  131. // item.show = false;
  132. // });
  133. this.listData = this.listData.concat(list);
  134. console.log(111, pages, this.pageNum, list, this.listData);
  135. if (pages <= this.pageNum) {
  136. this.status = 'nomore';
  137. this.loadMore = false;
  138. } else {
  139. this.status = 'loadmore';
  140. }
  141. });
  142. } else {
  143. uni.showToast({
  144. title: 'data请使用方法',
  145. icon: 'none'
  146. });
  147. }
  148. },
  149. // 使其他的列表选择隐藏
  150. // open(sel) {
  151. // this.listData.map((item, idx) => {
  152. // if (item.id === sel.id) {
  153. // item.show = true;
  154. // } else {
  155. // item.show = false;
  156. // }
  157. // });
  158. // },
  159. myButtonClick(index, index1) {
  160. let record = null;
  161. this.listData.map((item, idx) => {
  162. if (item.id === index) {
  163. record = item;
  164. }
  165. });
  166. this.$emit('buttonClick', record, index1)
  167. },
  168. myRowClick(item) {
  169. this.$emit('rowClick', item)
  170. },
  171. handleDel(item) {
  172. this.$emit('long', item)
  173. }
  174. }
  175. };
  176. </script>
  177. <style lang="less">
  178. page {
  179. background-color: #f4f4f4;
  180. }
  181. /deep/ .u-checkbox{
  182. width: 100%!important;
  183. }
  184. /deep/ .u-checkbox__label {
  185. width: 100%!important;
  186. margin-right: 0!important;
  187. }
  188. </style>