studentList.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. <template>
  2. <div>
  3. <!-- <van-sticky>
  4. <van-search
  5. show-action
  6. shape="round"
  7. @search="onSearch"
  8. v-model="params.search"
  9. placeholder="请输入学生名或手机号"
  10. >
  11. <template #action>
  12. <div @click="onSearch">搜索</div>
  13. </template>
  14. </van-search>
  15. </van-sticky> -->
  16. <m-search @onSearch="onSearch" placeholder="请输入学生名或手机号" />
  17. <div class="paddingB80">
  18. <van-list
  19. v-model="loading"
  20. class="studentContainer"
  21. v-if="dataShow"
  22. key="data"
  23. :finished="finished"
  24. finished-text="没有更多学生~"
  25. @load="getStudent"
  26. >
  27. <!-- <div class="studentContainer" v-if="dataShow" key="data"> -->
  28. <van-checkbox-group v-model="checkboxSelect">
  29. <van-cell-group :border="false">
  30. <van-cell
  31. v-for="(item, index) in dataList"
  32. :key="index"
  33. @click="onCheckboxSelect(item)"
  34. class="input-cell"
  35. value-class="value-times"
  36. :center="true"
  37. >
  38. <template slot="icon">
  39. <img
  40. class="logo"
  41. v-if="item.avatar"
  42. :src="item.avatar"
  43. alt=""
  44. />
  45. <img
  46. class="logo"
  47. v-else
  48. src="@/assets/images/icon_student.png"
  49. alt=""
  50. />
  51. </template>
  52. <template slot="title">
  53. {{ item.username }}({{ item.userId }})
  54. </template>
  55. <template slot="default">
  56. <span style="font-size: 0.16rem; color: #1a1a1a"
  57. >可排课次数:<span style="color: #01c1b5">{{
  58. item.showStudentNum
  59. }}</span></span
  60. >
  61. </template>
  62. <template slot="extra">
  63. <van-checkbox :name="item.userId">
  64. <template #icon="props">
  65. <img
  66. v-if="!item.radioDisabled"
  67. class="img-icon"
  68. :src="
  69. props.checked ? activeButtonIcon : inactiveButtonIcon
  70. "
  71. />
  72. </template>
  73. </van-checkbox>
  74. </template>
  75. </van-cell>
  76. </van-cell-group>
  77. </van-checkbox-group>
  78. <!-- </div> -->
  79. </van-list>
  80. <m-empty class="empty" msg="暂无学生" v-else key="data" />
  81. </div>
  82. <div class="button-group-popup">
  83. <span class="btn" @click="onPopupCancel">取消</span>
  84. <span class="btn primary" @click="onPopupSubmit">确定</span>
  85. </div>
  86. <div class="wall"></div>
  87. </div>
  88. </template>
  89. <script>
  90. import MEmpty from "@/components/MEmpty";
  91. import MSearch from "@/components/MSearch";
  92. import { getActivityStudentCanCourseNum } from "../api";
  93. export default {
  94. components: {
  95. MEmpty,
  96. MSearch,
  97. },
  98. // courseTypeIsVip 当前排课的类型,可能是赠送课程
  99. props: [
  100. "studentList",
  101. "activityId",
  102. "courseTypeIsVip",
  103. "typeStatus",
  104. "studentNum",
  105. "isMusicTheory",
  106. ],
  107. data() {
  108. return {
  109. params: {
  110. search: null,
  111. activityId: this.activityId,
  112. page: 1,
  113. rows: 20,
  114. },
  115. dataShow: true, // 是否有数据
  116. dataList: [],
  117. checkboxSelect: [],
  118. loading: false, // 下拉刷新状态
  119. finished: false, // 数据是否加载完成
  120. };
  121. },
  122. watch: {
  123. studentList(newVal) {
  124. if (newVal) {
  125. let tempVal = newVal || [];
  126. this.checkboxSelect = [];
  127. tempVal.forEach((item) => {
  128. this.checkboxSelect.push(item.userId);
  129. });
  130. }
  131. },
  132. },
  133. mounted() {
  134. this.getStudent();
  135. },
  136. methods: {
  137. // 搜索
  138. onSearch(val) {
  139. this.params.page = 1;
  140. this.dataShow = true;
  141. this.loading = true;
  142. this.params.search = val ? val : null;
  143. this.dataList = [];
  144. this.finished = false;
  145. this.getStudent();
  146. },
  147. getStudent() {
  148. let params = this.params;
  149. params.giveFlag = this.typeStatus ? 0 : 1;
  150. getActivityStudentCanCourseNum(params).then((ress) => {
  151. let res = ress.data
  152. console.log(res)
  153. if (res.code == 200) {
  154. let result = res.data.rows || [];
  155. let showResult = [];
  156. this.isLoading = false;
  157. params.page = res.data.pageNo;
  158. result.forEach((item) => {
  159. let showStudentNum = 0;
  160. if (this.typeStatus) {
  161. showStudentNum = this.courseTypeIsVip
  162. ? item.vipNum
  163. : item.practiceNum;
  164. } else {
  165. showStudentNum = this.courseTypeIsVip
  166. ? item.giveVipNum
  167. : item.givePracticeNum;
  168. }
  169. item.showStudentNum = showStudentNum;
  170. // 判断次数大于0的学生展示
  171. if (showStudentNum > 0) {
  172. showResult.push(item);
  173. }
  174. });
  175. if(res.data.pageNo == 1){
  176. this.dataList =showResult;
  177. }else{
  178. this.dataList = this.dataList.concat(showResult);
  179. }
  180. console.log(this.dataList.length);
  181. if (this.dataList.length > 0) {
  182. this.dataShow = true;
  183. } else {
  184. this.dataShow = false;
  185. }
  186. if (params.page >= res.data.totalPage) {
  187. this.finished = true;
  188. }
  189. this.params.page++;
  190. }else {
  191. this.finished = true;
  192. }
  193. });
  194. },
  195. onCheckboxSelect(value) {
  196. if (this.checkboxSelect.includes(value.userId)) {
  197. this.checkboxSelect.forEach((item, index) => {
  198. if (item === value.userId) {
  199. this.checkboxSelect.splice(index, 1);
  200. }
  201. });
  202. } else {
  203. this.checkboxSelect.push(value.userId);
  204. }
  205. },
  206. onPopupCancel() {
  207. this.$listeners.close();
  208. },
  209. onPopupSubmit() {
  210. if (this.isMusicTheory) {
  211. if (
  212. !(
  213. this.checkboxSelect.length >= 1 &&
  214. this.checkboxSelect.length <= this.studentNum
  215. )
  216. ) {
  217. this.$toast(
  218. `请选择1-${this.studentNum}名学生,当前选择${this.checkboxSelect.length}名`
  219. );
  220. return;
  221. }
  222. } else {
  223. if (this.checkboxSelect.length != this.studentNum) {
  224. this.$toast(
  225. `请选择学生${this.studentNum}名,当前选择${this.checkboxSelect.length}名`
  226. );
  227. return;
  228. }
  229. }
  230. let dataList = this.dataList || [];
  231. let checkList = [];
  232. dataList.forEach((item) => {
  233. if (this.checkboxSelect.includes(item.userId)) {
  234. checkList.push(item);
  235. }
  236. });
  237. this.$emit("submit", checkList);
  238. },
  239. },
  240. };
  241. </script>
  242. <style lang="less" scoped>
  243. @import url("../../../assets/commonLess/variable.less");
  244. .studentContainer {
  245. height: 4rem;
  246. overflow-y: scroll;
  247. padding-top: 0.1rem;
  248. background-color: #fff;
  249. /deep/.van-cell__title {
  250. font-size: 0.16rem;
  251. color: @mFontColor;
  252. // flex: 1 auto;
  253. }
  254. .logo {
  255. width: 0.35rem;
  256. height: 0.35rem;
  257. margin-right: 0.12rem;
  258. border-radius: 100%;
  259. }
  260. .input-cell {
  261. padding: 0.12rem 0.16rem 0.2rem;
  262. .van-checkbox {
  263. justify-content: flex-end;
  264. }
  265. }
  266. /deep/.van-cell__value {
  267. height: 0.2rem;
  268. }
  269. /deep/.van-checkbox__icon .van-icon {
  270. border-color: @sFontColor;
  271. }
  272. /deep/.van-checkbox__icon--checked .van-icon {
  273. border-color: #01c1b5;
  274. }
  275. .van-tag {
  276. margin-left: 0.08rem;
  277. }
  278. }
  279. .value-times {
  280. display: flex;
  281. align-items: center;
  282. justify-content: center;
  283. }
  284. .paddingB80 {
  285. padding-bottom: 0.8rem;
  286. }
  287. .wall {
  288. content: "";
  289. height: 0.62rem;
  290. position: relative;
  291. }
  292. .button-group-popup {
  293. position: fixed;
  294. bottom: 0;
  295. padding: 0.1rem 0;
  296. width: 100%;
  297. text-align: center;
  298. background-color: #ffffff;
  299. .btn {
  300. padding: 0 0.45rem;
  301. line-height: 0.4rem;
  302. display: inline-block;
  303. border: 1px solid @mColor;
  304. border-radius: 1rem;
  305. color: @mColor;
  306. background: #fff;
  307. font-size: 0.18rem;
  308. &.primary {
  309. color: #fff;
  310. background: @mColor;
  311. }
  312. }
  313. .btn + .btn {
  314. margin-left: 0.1rem;
  315. }
  316. }
  317. </style>