index.tsx 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. import OHeader from '@/components/o-header'
  2. import OSticky from '@/components/o-sticky'
  3. import {
  4. Button,
  5. Cell,
  6. CellGroup,
  7. Checkbox,
  8. CheckboxGroup,
  9. Grid,
  10. GridItem,
  11. Icon,
  12. Image,
  13. List,
  14. Picker,
  15. Popup,
  16. Sticky,
  17. Tag
  18. } from 'vant'
  19. import { defineComponent, onMounted, reactive, watch } from 'vue'
  20. import styles from './index.module.less'
  21. import iconTeacher from '@common/images/icon_teacher.png'
  22. import { state as baseState } from '@/state'
  23. import request from '@/helpers/request'
  24. import OEmpty from '@/components/o-empty'
  25. export default defineComponent({
  26. name: 'practice-class',
  27. props: {
  28. height: {
  29. type: [String, Number],
  30. default: 'auto'
  31. },
  32. selectItem: {
  33. type: Array,
  34. default: []
  35. }
  36. },
  37. emits: ['close', 'confirm', 'update:selectItem'],
  38. setup(props, { emit }) {
  39. const forms = reactive({
  40. showPopover: false,
  41. orchestraId: null as any,
  42. orchestraName: null as any,
  43. orchestraList: [] as any,
  44. isClick: false,
  45. list: [] as any,
  46. listState: {
  47. dataShow: true, // 判断是否有数据
  48. loading: false,
  49. finished: false
  50. },
  51. params: {
  52. type: null,
  53. page: 1,
  54. rows: 20
  55. },
  56. check: [] as any,
  57. checkboxRefs: [] as any
  58. })
  59. // 获取乐团列表
  60. const getOrchestras = async () => {
  61. try {
  62. const { data } = await request.post('/api-school/orchestra/page', {
  63. data: {
  64. page: 1,
  65. rows: 100,
  66. schoolId: baseState.user.data.school.id
  67. }
  68. })
  69. const temps = data.rows || []
  70. const s = [] as any
  71. temps.forEach((item: any) => {
  72. s.push({
  73. text: item.name,
  74. value: item.id
  75. })
  76. })
  77. forms.orchestraList = [...s]
  78. // 判断是否有乐团
  79. if (s.length > 0) {
  80. forms.orchestraId = s[0].value
  81. forms.orchestraName = s[0].text
  82. }
  83. } catch {
  84. //
  85. }
  86. }
  87. // 获取班级
  88. const getList = async () => {
  89. // 查询没有设置指导老师的班级
  90. try {
  91. if (forms.isClick) return
  92. forms.isClick = true
  93. const { data } = await request.post('/api-school/classGroup/page', {
  94. data: {
  95. ...forms.params,
  96. schoolId: baseState.user.data.school.id
  97. }
  98. })
  99. forms.isClick = false
  100. // 班级数据
  101. forms.listState.loading = false
  102. const result = data || {}
  103. // 处理重复请求数据
  104. if (forms.list.length > 0 && result.current === 1) {
  105. return
  106. }
  107. forms.list = forms.list.concat(result.rows || [])
  108. forms.listState.finished = result.current >= result.pages
  109. forms.params.page = result.current + 1
  110. forms.listState.dataShow = forms.list.length > 0
  111. } catch {
  112. forms.listState.dataShow = false
  113. forms.listState.finished = true
  114. forms.isClick = false
  115. }
  116. }
  117. const onSelect = (type: string) => {
  118. forms.checkboxRefs[type].toggle()
  119. const list: any = []
  120. forms.list.forEach((item: any) => {
  121. if (forms.check.includes(item.id)) {
  122. list.push({
  123. id: item.id,
  124. value: item.name,
  125. avatar: ''
  126. })
  127. }
  128. })
  129. emit('update:selectItem', list)
  130. }
  131. watch(
  132. () => props.selectItem,
  133. () => {
  134. initSelectItem()
  135. },
  136. { deep: true }
  137. )
  138. const initSelectItem = () => {
  139. const selectItem = props.selectItem || []
  140. const temp: any = []
  141. selectItem.forEach((item: any) => {
  142. temp.push(item.id)
  143. })
  144. forms.check = temp
  145. }
  146. onMounted(async () => {
  147. await getOrchestras()
  148. await getList()
  149. initSelectItem()
  150. })
  151. return () => (
  152. <div class={styles.practiceClass}>
  153. <Sticky position="top" offsetTop={props.height}>
  154. <div style={{ padding: '12px 13px', background: '#f6f6f6' }}>
  155. <div class={styles.searchBand} onClick={() => (forms.showPopover = true)}>
  156. {forms.orchestraName} <Icon name={forms.showPopover ? 'arrow-up' : 'arrow-down'} />
  157. </div>
  158. </div>
  159. </Sticky>
  160. {forms.listState.dataShow ? (
  161. <List
  162. v-model:loading={forms.listState.loading}
  163. finished={forms.listState.finished}
  164. finishedText=" "
  165. class={[styles.liveList]}
  166. onLoad={getList}
  167. immediateCheck={false}
  168. >
  169. <CheckboxGroup
  170. class={[styles.gridContainer, styles.gridClass]}
  171. v-model={forms.check}
  172. // onChange={(val: any) => {
  173. // console.log(val, '1212')
  174. // const list: any = []
  175. // forms.list.forEach((item: any) => {
  176. // if (val.includes(item.id)) {
  177. // list.push({
  178. // id: item.id,
  179. // value: item.name,
  180. // avatar: ''
  181. // })
  182. // }
  183. // })
  184. // emit('change', list)
  185. // }}
  186. >
  187. {forms.list.map((item: any) => (
  188. <CellGroup class={styles.classCellGroup} onClick={() => onSelect(item.id)}>
  189. <Cell center titleStyle={{ flex: '0 auto' }} valueClass={styles.classCheckbox}>
  190. {{
  191. icon: () => <Image src={iconTeacher} class={styles.img} />,
  192. title: () => (
  193. <div class={styles.content}>
  194. <div class={styles.teacherName}>
  195. <span class={['van-ellipsis', styles.name]}>{item.teacherName}</span>
  196. <Tag type="primary">{item.name}</Tag>
  197. </div>
  198. <div class={[styles.orchestraName, 'van-ellipsis']}>
  199. {item.orchestraName}
  200. </div>
  201. </div>
  202. ),
  203. value: () => (
  204. <Checkbox
  205. name={item.id}
  206. ref={(el: any) => (forms.checkboxRefs[item.id] = el)}
  207. onClick={(e: any) => {
  208. e.stopPropagation()
  209. }}
  210. ></Checkbox>
  211. )
  212. }}
  213. </Cell>
  214. <Grid border={false} columnNum={3}>
  215. <GridItem>
  216. <p class={styles.title}>{item.preStudentNum}</p>
  217. <p class={styles.name}>学生人数</p>
  218. </GridItem>
  219. <GridItem>
  220. <p class={[styles.title]}>
  221. {item.courseScheduleNum - item.completeCourseScheduleNum}
  222. </p>
  223. <p class={styles.name}>剩余课时</p>
  224. </GridItem>
  225. <GridItem>
  226. <p class={styles.title}>{item.courseScheduleNum}</p>
  227. <p class={styles.name}>总课时</p>
  228. </GridItem>
  229. </Grid>
  230. </CellGroup>
  231. ))}
  232. </CheckboxGroup>
  233. </List>
  234. ) : (
  235. <OEmpty btnStatus={false} classImgSize="SMALL" tips="暂无班级" />
  236. )}
  237. <Popup v-model:show={forms.showPopover} position="bottom" round>
  238. <Picker
  239. columns={forms.orchestraList}
  240. onCancel={() => (forms.showPopover = false)}
  241. onConfirm={(val: any) => {
  242. forms.orchestraId = val.selectedOptions[0].value
  243. forms.orchestraName = val.selectedOptions[0].text
  244. forms.showPopover = false
  245. forms.params.page = 1
  246. forms.list = []
  247. forms.listState.dataShow = true // 判断是否有数据
  248. forms.listState.loading = false
  249. forms.listState.finished = false
  250. getList()
  251. }}
  252. />
  253. </Popup>
  254. </div>
  255. )
  256. }
  257. })