ManageList.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <template>
  2. <div class="personList">
  3. <van-list
  4. v-model:loading="loading"
  5. :finished="finished"
  6. finished-text="没有更多了"
  7. @load="onLoad"
  8. >
  9. <van-checkbox-group
  10. v-if="type == 1"
  11. v-model="checked"
  12. ref="checkboxGroup"
  13. >
  14. <van-button type="primary" size="mini" @click="checkAll"
  15. >全选</van-button
  16. >
  17. <van-cell-group inset>
  18. <van-cell
  19. v-for="(item, index) in list"
  20. clickable
  21. :key="item"
  22. :title="item.name"
  23. @click="toggle(index)"
  24. >
  25. <template #right-icon>
  26. <van-checkbox
  27. shape="square"
  28. :name="item"
  29. :ref="(el) => (checkboxRefs[index] = el)"/>
  30. </template>
  31. </van-cell>
  32. </van-cell-group>
  33. </van-checkbox-group>
  34. <van-radio-group v-if="type == 0" v-model="checked">
  35. <van-cell-group inset>
  36. <van-cell
  37. v-for="item in list"
  38. clickable
  39. :key="item"
  40. :title="item.name"
  41. @click="selectes(item)"
  42. >
  43. <template #right-icon>
  44. <van-radio :name="item" />
  45. </template>
  46. </van-cell>
  47. </van-cell-group>
  48. </van-radio-group>
  49. </van-list>
  50. </div>
  51. </template>
  52. <script>
  53. import { ref } from "vue";
  54. import placeRegister from "@/api/placeRegister/placeRegister"
  55. export default {
  56. name: "personList",
  57. emits: ["selected"],
  58. props: ["type"],
  59. setup(props, { emit }) {
  60. const list = ref([]);
  61. const loading = ref(false);
  62. const finished = ref(false);
  63. let index = 0;
  64. const onLoad = () => {
  65. // 异步更新数据
  66. new placeRegister()
  67. .list({
  68. current: index + 1,
  69. size: 10,
  70. })
  71. .then(({ records }) => {
  72. list.value.push(...records);
  73. // 加载状态结束
  74. loading.value = false;
  75. index++;
  76. // 数据全部加载完成
  77. if (records.length < 10) {
  78. finished.value = true;
  79. }
  80. });
  81. };
  82. // 搜索
  83. const value = ref("");
  84. const onSearch = (val) => showToast(val);
  85. const onCancel = () => showToast("取消");
  86. // 选择人员
  87. const checked = ref([]);
  88. const checkboxRefs = ref([]);
  89. const checkboxGroup = ref(null);
  90. const toggle = (index) => {
  91. checkboxRefs.value[index].toggle();
  92. emit("selected", checked.value, 1);
  93. };
  94. // 全选
  95. const checkAll = () => {
  96. checkboxGroup.value.toggleAll(true);
  97. emit("selected", checked.value, 1);
  98. };
  99. const selectes = (val) => {
  100. checked.value = val;
  101. emit("selected", checked.value, 0);
  102. };
  103. return {
  104. // 人员
  105. list,
  106. onLoad,
  107. loading,
  108. finished,
  109. // 全选
  110. checkAll,
  111. toggle,
  112. checked,
  113. checkboxRefs,
  114. checkboxGroup,
  115. // 单选
  116. selectes,
  117. };
  118. },
  119. };
  120. </script>
  121. <style scoped>
  122. .personList {
  123. height: 65vh;
  124. overflow: auto;
  125. margin: 10px;
  126. }
  127. .van-button {
  128. top: -5px;
  129. }
  130. .search {
  131. height: 40px;
  132. line-height: 40px;
  133. }
  134. .van-list {
  135. height: 80%;
  136. margin-top: 5px;
  137. }
  138. .keyword {
  139. width: 70%;
  140. height: 25px;
  141. border-radius: 25px;
  142. border: 1px solid;
  143. padding-left: 15px;
  144. }
  145. </style>