index.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <template>
  2. <div class="studentList">
  3. <van-sticky>
  4. <Search @onSearch="onSearch" />
  5. <van-dropdown-menu active-color="#01C1B5">
  6. <van-dropdown-item
  7. v-model="value1"
  8. :options="option1"
  9. @change="onChange"
  10. />
  11. <van-dropdown-item
  12. v-model="value2"
  13. :options="option2"
  14. @change="onChange"
  15. />
  16. <van-dropdown-item
  17. v-model="value3"
  18. :options="option3"
  19. @change="onChange"
  20. />
  21. </van-dropdown-menu>
  22. </van-sticky>
  23. <van-list
  24. v-model="loading"
  25. v-if="dataShow"
  26. :finished="finished"
  27. :immediate-check="false"
  28. finished-text="- 没有更多内容 -"
  29. @load="getStudent"
  30. >
  31. <van-cell-group
  32. inset
  33. style="margin-top: 0.1rem"
  34. v-for="(item, index) in dataList"
  35. :key="index"
  36. @click="onDetail(item)"
  37. >
  38. <van-cell is-link center>
  39. <template #icon>
  40. <van-image class="studentLogo" :src="item.avatar || iconStudent" />
  41. </template>
  42. <template #title>
  43. <div style="display: flex; align-items: center; font-size: 0.16rem">
  44. {{ item.username }}
  45. <img
  46. v-if="item.memberRankSettingId > 0"
  47. style="width: 16px; height: 16px; margin-left: 3px"
  48. src="./images/icon_member.png"
  49. alt=""
  50. />
  51. </div>
  52. </template>
  53. <template #label>
  54. {{ item.subjectName }}
  55. </template>
  56. </van-cell>
  57. </van-cell-group>
  58. </van-list>
  59. <m-empty class="empty" v-else />
  60. </div>
  61. </template>
  62. <script>
  63. import MEmpty from "@/components/MEmpty";
  64. import Search from "@/components/Search";
  65. import { findSubSubjects } from "@/api/teacher";
  66. import { queryStudentList, queryOrganList } from "./api";
  67. export default {
  68. name: "studentList",
  69. components: {
  70. MEmpty,
  71. Search,
  72. },
  73. data() {
  74. return {
  75. iconStudent: require("@/assets/images/icon_student.png"),
  76. value1: "",
  77. value2: "",
  78. value3: "",
  79. option1: [{ text: "全部分部", value: "" }],
  80. option2: [{ text: "全部声部", value: "" }],
  81. option3: [
  82. { text: "全部学员", value: "" },
  83. { text: "会员", value: "1" },
  84. { text: "非会员", value: "0" },
  85. { text: "未生效会员", value: "2" },
  86. ],
  87. loading: false,
  88. finished: false,
  89. params: {
  90. search: null,
  91. page: 1,
  92. rows: 20,
  93. },
  94. dataShow: true, // 是否有数据
  95. dataList: [],
  96. };
  97. },
  98. mounted() {
  99. document.title = "学员列表";
  100. this.__init();
  101. this.getStudent();
  102. },
  103. methods: {
  104. onDetail(item) {
  105. this.$router.push({
  106. path: "/studentDetail",
  107. query: {
  108. id: item.userId,
  109. avatar: item.avatar,
  110. username: item.username,
  111. subjectName: item.subjectName,
  112. phone: item.parentsPhone,
  113. organName: item.organName,
  114. currentGrade: item.currentGrade,
  115. currentClass: item.currentClass,
  116. memberRankSettingId: item.memberRankSettingId,
  117. membershipDay: item.membershipDay,
  118. },
  119. });
  120. },
  121. async getStudent() {
  122. let params = this.params;
  123. params.search = params.search ? params.search : null;
  124. params.organId = this.value1;
  125. params.subjectId = this.value2;
  126. params.hasMember = this.value3;
  127. try {
  128. let studentList = await queryStudentList(params);
  129. let result = studentList.data;
  130. this.loading = false;
  131. // 重点这句,判断是不是重复请求了
  132. if (this.dataList.length > 0 && result.pageNo == 1) {
  133. return;
  134. }
  135. params.page = result.pageNo;
  136. this.dataList = this.dataList.concat(result.rows);
  137. if (params.page >= result.totalPage) {
  138. this.finished = true;
  139. }
  140. this.params.page++;
  141. // 判断是否有数据
  142. if (this.dataList.length <= 0) {
  143. this.dataShow = false;
  144. }
  145. } catch {
  146. //
  147. this.finished = true;
  148. this.dataShow = false;
  149. }
  150. },
  151. onChange() {
  152. this.params.page = 1;
  153. this.dataShow = true;
  154. this.loading = true;
  155. this.dataList = [];
  156. this.finished = false;
  157. this.getStudent();
  158. },
  159. async __init() {
  160. try {
  161. let organList = await queryOrganList();
  162. let result = organList.data || [];
  163. result.forEach((item) => {
  164. this.option1.push({
  165. text: item.value,
  166. value: item.key,
  167. });
  168. });
  169. // 声部列表
  170. await findSubSubjects().then((res) => {
  171. let result = res.data;
  172. if (result.code == 200 && result.data.length > 0) {
  173. let tempArr = [];
  174. result.data.forEach((item) => {
  175. item.value = item.id;
  176. item.text = item.name;
  177. tempArr.push(item);
  178. });
  179. this.option2.push(...tempArr);
  180. } else {
  181. this.$toast("暂无科目列表");
  182. }
  183. });
  184. } catch {
  185. //
  186. }
  187. },
  188. onSearch(val) {
  189. this.params.search = val;
  190. this.onChange();
  191. },
  192. },
  193. };
  194. </script>
  195. <style lang="less" scoped>
  196. .studentList {
  197. min-height: 100vh;
  198. }
  199. .studentLogo {
  200. width: 0.48rem;
  201. height: 0.48rem;
  202. border-radius: 50%;
  203. margin-right: 10px;
  204. overflow: hidden;
  205. }
  206. </style>