studentList.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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', 'isMusicTheory'],
  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. let showResult = []
  123. result.forEach(item => {
  124. let showStudentNum = 0
  125. if (this.typeStatus) {
  126. showStudentNum = this.courseTypeIsVip ? item.vipNum : item.practiceNum
  127. } else {
  128. showStudentNum = this.courseTypeIsVip ? item.giveVipNum : item.givePracticeNum
  129. }
  130. item.showStudentNum = showStudentNum
  131. // 判断次数大于0的学生展示
  132. if(showStudentNum > 0) {
  133. showResult.push(item)
  134. }
  135. })
  136. this.dataList = showResult
  137. if(showResult.length > 0) {
  138. this.dataShow = true
  139. } else {
  140. this.dataShow = false
  141. }
  142. } catch {
  143. //
  144. }
  145. },
  146. onCheckboxSelect(value) {
  147. if (this.checkboxSelect.includes(value.userId)) {
  148. this.checkboxSelect.forEach((item, index) => {
  149. if(item === value.userId) {
  150. this.checkboxSelect.splice(index, 1)
  151. }
  152. })
  153. } else {
  154. this.checkboxSelect.push(value.userId)
  155. }
  156. },
  157. onPopupCancel() {
  158. this.$listeners.close()
  159. },
  160. onPopupSubmit() {
  161. if (this.isMusicTheory) {
  162. if (!(this.checkboxSelect.length >= 1 && this.checkboxSelect.length <= this.studentNum)) {
  163. this.$toast(`请选择1-${this.studentNum}名学生,当前选择${this.checkboxSelect.length}名`);
  164. return;
  165. }
  166. } else {
  167. if (this.checkboxSelect.length != this.studentNum) {
  168. this.$toast(`请选择学生${this.studentNum}名,当前选择${this.checkboxSelect.length}名`);
  169. return;
  170. }
  171. }
  172. let dataList = this.dataList || []
  173. let checkList = []
  174. dataList.forEach(item => {
  175. if(this.checkboxSelect.includes(item.userId)) {
  176. checkList.push(item)
  177. }
  178. })
  179. this.$emit('submit', checkList)
  180. }
  181. }
  182. }
  183. </script>
  184. <style lang="less" scoped>
  185. @import url("../../../assets/commonLess/variable.less");
  186. .studentContainer {
  187. padding-top: .1rem;
  188. background-color: #fff;
  189. /deep/.van-cell__title {
  190. font-size: 0.16rem;
  191. color: @mFontColor;
  192. // flex: 1 auto;
  193. }
  194. .logo {
  195. width: 0.35rem;
  196. height: 0.35rem;
  197. margin-right: 0.12rem;
  198. border-radius: 100%;
  199. }
  200. .input-cell {
  201. padding: 0.12rem 0.16rem 0.2rem;
  202. .van-checkbox {
  203. justify-content: flex-end;
  204. }
  205. }
  206. /deep/.van-cell__value {
  207. height: 0.2rem;
  208. }
  209. /deep/.van-checkbox__icon .van-icon {
  210. border-color: @sFontColor;
  211. }
  212. /deep/.van-checkbox__icon--checked .van-icon {
  213. border-color: #01C1B5;
  214. }
  215. .van-tag {
  216. margin-left: 0.08rem;
  217. }
  218. }
  219. .value-times {
  220. display: flex;
  221. align-items: center;
  222. justify-content: center;
  223. }
  224. .paddingB80 {
  225. padding-bottom: 0.8rem;
  226. }
  227. .button-group-popup {
  228. position: fixed;
  229. bottom: 0;
  230. padding: 0.2rem 0;
  231. width: 100%;
  232. text-align: center;
  233. background-color: #ffffff;
  234. .btn {
  235. padding: 0 0.45rem;
  236. line-height: 0.4rem;
  237. display: inline-block;
  238. border: 1px solid @mColor;
  239. border-radius: 1rem;
  240. color: @mColor;
  241. background: #fff;
  242. font-size: 0.18rem;
  243. &.primary {
  244. color: #fff;
  245. background: @mColor;
  246. }
  247. }
  248. .btn + .btn {
  249. margin-left: 0.1rem;
  250. }
  251. }
  252. </style>