studentList.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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. <div class="paddingB80">
  17. <!-- <van-list
  18. v-model="loading"
  19. class="studentContainer"
  20. v-if="dataShow"
  21. key="data"
  22. :finished="finished"
  23. finished-text=""
  24. @load="getStudent"
  25. > -->
  26. <div class="studentContainer" v-if="dataShow" key="data">
  27. <van-checkbox-group v-model="checkboxSelect">
  28. <van-cell-group :border="false">
  29. <van-cell
  30. v-for="(item, index) in dataList"
  31. :key="index"
  32. @click="onCheckboxSelect(item)"
  33. class="input-cell"
  34. value-class="value-times"
  35. :center="true"
  36. >
  37. <template slot="icon">
  38. <img
  39. class="logo"
  40. v-if="item.avatar"
  41. :src="item.avatar"
  42. alt=""
  43. />
  44. <img
  45. class="logo"
  46. v-else
  47. src="@/assets/images/icon_student.png"
  48. alt=""
  49. />
  50. </template>
  51. <template slot="title">
  52. {{ item.username }}
  53. </template>
  54. <template slot="default">
  55. <span style="font-size: .16rem;color: #1A1A1A;">可排课次数:<span style="color: #01C1B5;">{{ item.showStudentNum }}</span></span>
  56. </template>
  57. <template slot="extra">
  58. <van-checkbox :name="item.userId">
  59. <template #icon="props">
  60. <img v-if="!item.radioDisabled" class="img-icon" :src="props.checked ? activeButtonIcon : inactiveButtonIcon" />
  61. </template>
  62. </van-checkbox>
  63. </template>
  64. </van-cell>
  65. </van-cell-group>
  66. </van-checkbox-group>
  67. </div>
  68. <!-- </van-list> -->
  69. <m-empty class="empty" msg="暂无学生" v-else key="data" />
  70. </div>
  71. <div class="button-group-popup">
  72. <span class="btn" @click="onPopupCancel">取消</span>
  73. <span class="btn primary" @click="onPopupSubmit">确定</span>
  74. </div>
  75. </div>
  76. </template>
  77. <script>
  78. import MEmpty from "@/components/MEmpty";
  79. import { getActivityStudentCanCourseNum } from '../api'
  80. export default {
  81. components: {
  82. MEmpty
  83. },
  84. // courseTypeIsVip 当前排课的类型,可能是赠送课程
  85. props: ['studentList', 'activityId', 'courseTypeIsVip', 'typeStatus', 'studentNum'],
  86. data() {
  87. return {
  88. params: {
  89. search: null,
  90. activityId: this.activityId
  91. },
  92. dataShow: true, // 是否有数据
  93. dataList: [],
  94. checkboxSelect: [],
  95. }
  96. },
  97. watch: {
  98. studentList(newVal) {
  99. if(newVal) {
  100. let tempVal = newVal || []
  101. this.checkboxSelect = []
  102. tempVal.forEach(item => {
  103. this.checkboxSelect.push(item.userId)
  104. })
  105. }
  106. }
  107. },
  108. mounted() {
  109. this.getStudent()
  110. },
  111. methods: {
  112. // 搜索
  113. onSearch() {
  114. this.dataList = [];
  115. this.getStudent();
  116. },
  117. async getStudent() {
  118. let params = this.params;
  119. try {
  120. const res = await getActivityStudentCanCourseNum(params)
  121. let result = res.data || []
  122. result.forEach(item => {
  123. let showStudentNum = 0
  124. if (this.typeStatus) {
  125. showStudentNum = this.courseTypeIsVip ? item.vipNum : item.practiceNum
  126. } else {
  127. showStudentNum = this.courseTypeIsVip ? item.giveVipNum : item.givePracticeNum
  128. }
  129. item.showStudentNum = showStudentNum
  130. })
  131. this.dataList = result
  132. } catch {
  133. //
  134. }
  135. },
  136. onCheckboxSelect(value) {
  137. if (this.checkboxSelect.includes(value.userId)) {
  138. this.checkboxSelect.forEach((item, index) => {
  139. if(item === value.userId) {
  140. this.checkboxSelect.splice(index, 1)
  141. }
  142. })
  143. } else {
  144. this.checkboxSelect.push(value.userId)
  145. }
  146. },
  147. onPopupCancel() {
  148. this.$listeners.close()
  149. },
  150. onPopupSubmit() {
  151. // if (this.checkboxSelect.length != this.studentNum) {
  152. // this.$toast(`请选择学生${this.studentNum}名,当前选择${this.checkboxSelect.length}名`);
  153. // return;
  154. // }
  155. let dataList = this.dataList || []
  156. let checkList = []
  157. dataList.forEach(item => {
  158. if(this.checkboxSelect.includes(item.userId)) {
  159. checkList.push(item)
  160. }
  161. })
  162. this.$emit('submit', checkList)
  163. }
  164. }
  165. }
  166. </script>
  167. <style lang="less" scoped>
  168. @import url("../../../assets/commonLess/variable.less");
  169. .studentContainer {
  170. padding-top: .1rem;
  171. background-color: #fff;
  172. /deep/.van-cell__title {
  173. font-size: 0.16rem;
  174. color: @mFontColor;
  175. // flex: 1 auto;
  176. }
  177. .logo {
  178. width: 0.35rem;
  179. height: 0.35rem;
  180. margin-right: 0.12rem;
  181. border-radius: 100%;
  182. }
  183. .input-cell {
  184. padding: 0.12rem 0.16rem 0.2rem;
  185. .van-checkbox {
  186. justify-content: flex-end;
  187. }
  188. }
  189. /deep/.van-cell__value {
  190. height: 0.2rem;
  191. }
  192. /deep/.van-checkbox__icon .van-icon {
  193. border-color: @sFontColor;
  194. }
  195. /deep/.van-checkbox__icon--checked .van-icon {
  196. border-color: #01C1B5;
  197. }
  198. .van-tag {
  199. margin-left: 0.08rem;
  200. }
  201. }
  202. .value-times {
  203. display: flex;
  204. align-items: center;
  205. justify-content: center;
  206. }
  207. .paddingB80 {
  208. padding-bottom: 0.8rem;
  209. }
  210. .button-group-popup {
  211. position: fixed;
  212. bottom: 0;
  213. padding: 0.2rem 0;
  214. width: 100%;
  215. text-align: center;
  216. background-color: #ffffff;
  217. .btn {
  218. padding: 0 0.45rem;
  219. line-height: 0.4rem;
  220. display: inline-block;
  221. border: 1px solid @mColor;
  222. border-radius: 1rem;
  223. color: @mColor;
  224. background: #fff;
  225. font-size: 0.18rem;
  226. &.primary {
  227. color: #fff;
  228. background: @mColor;
  229. }
  230. }
  231. .btn + .btn {
  232. margin-left: 0.1rem;
  233. }
  234. }
  235. </style>