studentList.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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. 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.checkboxSelect.length != this.studentNum) {
  162. this.$toast(`请选择学生${this.studentNum}名,当前选择${this.checkboxSelect.length}名`);
  163. return;
  164. }
  165. let dataList = this.dataList || []
  166. let checkList = []
  167. dataList.forEach(item => {
  168. if(this.checkboxSelect.includes(item.userId)) {
  169. checkList.push(item)
  170. }
  171. })
  172. this.$emit('submit', checkList)
  173. }
  174. }
  175. }
  176. </script>
  177. <style lang="less" scoped>
  178. @import url("../../../assets/commonLess/variable.less");
  179. .studentContainer {
  180. padding-top: .1rem;
  181. background-color: #fff;
  182. /deep/.van-cell__title {
  183. font-size: 0.16rem;
  184. color: @mFontColor;
  185. // flex: 1 auto;
  186. }
  187. .logo {
  188. width: 0.35rem;
  189. height: 0.35rem;
  190. margin-right: 0.12rem;
  191. border-radius: 100%;
  192. }
  193. .input-cell {
  194. padding: 0.12rem 0.16rem 0.2rem;
  195. .van-checkbox {
  196. justify-content: flex-end;
  197. }
  198. }
  199. /deep/.van-cell__value {
  200. height: 0.2rem;
  201. }
  202. /deep/.van-checkbox__icon .van-icon {
  203. border-color: @sFontColor;
  204. }
  205. /deep/.van-checkbox__icon--checked .van-icon {
  206. border-color: #01C1B5;
  207. }
  208. .van-tag {
  209. margin-left: 0.08rem;
  210. }
  211. }
  212. .value-times {
  213. display: flex;
  214. align-items: center;
  215. justify-content: center;
  216. }
  217. .paddingB80 {
  218. padding-bottom: 0.8rem;
  219. }
  220. .button-group-popup {
  221. position: fixed;
  222. bottom: 0;
  223. padding: 0.2rem 0;
  224. width: 100%;
  225. text-align: center;
  226. background-color: #ffffff;
  227. .btn {
  228. padding: 0 0.45rem;
  229. line-height: 0.4rem;
  230. display: inline-block;
  231. border: 1px solid @mColor;
  232. border-radius: 1rem;
  233. color: @mColor;
  234. background: #fff;
  235. font-size: 0.18rem;
  236. &.primary {
  237. color: #fff;
  238. background: @mColor;
  239. }
  240. }
  241. .btn + .btn {
  242. margin-left: 0.1rem;
  243. }
  244. }
  245. </style>