index.tsx 8.8 KB

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