index.tsx 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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. Tag
  17. } from 'vant'
  18. import { defineComponent, onMounted, reactive, watch } from 'vue'
  19. import styles from './index.module.less'
  20. import iconTeacher from '@common/images/icon_teacher.png'
  21. import { state as baseState } from '@/state'
  22. import request from '@/helpers/request'
  23. import OEmpty from '@/components/o-empty'
  24. export default defineComponent({
  25. name: 'practice-class',
  26. props: {
  27. classType: {
  28. type: String,
  29. default: ''
  30. },
  31. orchestraId: {
  32. // 乐团编号
  33. type: String,
  34. default: ''
  35. },
  36. selectItem: {
  37. type: Array,
  38. default: () => []
  39. }
  40. },
  41. emits: ['close', 'confirm'],
  42. setup(props, { slots, attrs, emit }) {
  43. const forms = reactive({
  44. showPopover: false,
  45. orchestraId: (props.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. page: 1,
  57. rows: 20
  58. },
  59. check: (props.selectItem || []) as any,
  60. checkboxRefs: [] as any
  61. })
  62. // 获取乐团列表
  63. const getOrchestras = async () => {
  64. try {
  65. const { data } = await request.post('/api-school/orchestra/page', {
  66. data: {
  67. page: 1,
  68. rows: 100,
  69. schoolId: baseState.user.data.school.id,
  70. status: 'DONE'
  71. }
  72. })
  73. const temps = data.rows || []
  74. const s = [] as any
  75. temps.forEach((item: any) => {
  76. s.push({
  77. text: item.name,
  78. value: item.id
  79. })
  80. })
  81. forms.orchestraList = [...s]
  82. // 判断是否有乐团
  83. if (s.length > 0) {
  84. forms.orchestraId = s[0].value
  85. forms.orchestraName = s[0].text
  86. await getList()
  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. classType: props.classType
  104. // orchestraType: 'DELIVERY'
  105. }
  106. })
  107. forms.isClick = false
  108. // 班级数据
  109. forms.listState.loading = false
  110. const result = data || {}
  111. // 处理重复请求数据
  112. if (forms.list.length > 0 && result.current === 1) {
  113. return
  114. }
  115. const tempList = forms.list.concat(result.rows || [])
  116. tempList.forEach((item: any) => {
  117. if (item.preStudentNum > 0) {
  118. forms.list.push(item)
  119. }
  120. })
  121. forms.listState.finished = result.current >= result.pages
  122. forms.params.page = result.current + 1
  123. forms.listState.dataShow = forms.list.length > 0
  124. } catch {
  125. forms.listState.dataShow = false
  126. forms.listState.finished = true
  127. forms.isClick = false
  128. }
  129. }
  130. // 监听班级类型变化
  131. watch(
  132. () => props.classType,
  133. () => {
  134. forms.params.page = 1
  135. forms.list = []
  136. forms.listState.dataShow = true // 判断是否有数据
  137. forms.listState.loading = false
  138. forms.listState.finished = false
  139. getList()
  140. }
  141. )
  142. const onSelect = (type: string) => {
  143. forms.checkboxRefs[type].toggle()
  144. }
  145. // 确定选择班级
  146. const onSubmit = () => {
  147. emit('confirm', forms.check)
  148. emit('close')
  149. }
  150. onMounted(async () => {
  151. // 判断是否有乐团编号
  152. if (!props.orchestraId) {
  153. await getOrchestras()
  154. } else {
  155. await getList()
  156. }
  157. })
  158. return () => (
  159. <div class={[styles.practiceClass, !forms.listState.dataShow && 'emptyRootContainer']}>
  160. <OSticky position="top">
  161. <OHeader title="选择班级" desotry={false} />
  162. {!props.orchestraId && (
  163. <div style={{ padding: '12px 13px', background: '#f6f6f6' }}>
  164. <div class={styles.searchBand} onClick={() => (forms.showPopover = true)}>
  165. <div class={['van-ellipsis', styles.bandName]}>{forms.orchestraName}</div>
  166. <Icon name={forms.showPopover ? 'arrow-up' : 'arrow-down'} />
  167. </div>
  168. </div>
  169. )}
  170. </OSticky>
  171. {forms.listState.dataShow ? (
  172. <List
  173. // v-model:loading={forms.listState.loading}
  174. finished={forms.listState.finished}
  175. style={{ marginTop: props.orchestraId ? '12px' : 0 }}
  176. finishedText=" "
  177. class={[styles.liveList]}
  178. onLoad={getList}
  179. immediateCheck={false}
  180. >
  181. <CheckboxGroup class={[styles.gridContainer, styles.gridClass]} v-model={forms.check}>
  182. {forms.list.map((item: any) => (
  183. <CellGroup
  184. class={styles.classCellGroup}
  185. onClick={() => {
  186. if (item.teacherId) {
  187. onSelect(item.id)
  188. }
  189. }}
  190. border={false}
  191. >
  192. <Cell center titleStyle={{ flex: '0 auto' }} valueClass={styles.classCheckbox}>
  193. {{
  194. icon: () => <Image src={iconTeacher} class={styles.img} />,
  195. title: () => (
  196. <div class={styles.content}>
  197. <div class={styles.teacherName}>
  198. {item.teacherName ? (
  199. <div class={[styles.name, styles.maxWidth, 'van-ellipsis']}>
  200. {item.teacherName}
  201. </div>
  202. ) : (
  203. <div class={[styles.name, 'van-ellipsis']} style={{ color: 'red' }}>
  204. 暂未设置伴学指导
  205. </div>
  206. )}
  207. <Tag type="primary">{item.name}</Tag>
  208. </div>
  209. <div class={[styles.orchestraName, 'van-ellipsis']}>
  210. {item.orchestraName}
  211. </div>
  212. </div>
  213. ),
  214. value: () => (
  215. <Checkbox
  216. name={item.id}
  217. ref={(el: any) => (forms.checkboxRefs[item.id] = el)}
  218. disabled={item.teacherId ? false : true}
  219. onClick={(e: any) => {
  220. e.stopPropagation()
  221. }}
  222. ></Checkbox>
  223. )
  224. }}
  225. </Cell>
  226. <Grid border={false} columnNum={3}>
  227. <GridItem>
  228. <p class={styles.title}>{item.preStudentNum}</p>
  229. <p class={styles.name}>学生人数</p>
  230. </GridItem>
  231. <GridItem>
  232. <p class={[styles.title]}>
  233. {item.courseScheduleNum - item.completeCourseScheduleNum}
  234. </p>
  235. <p class={styles.name}>剩余课时</p>
  236. </GridItem>
  237. <GridItem>
  238. <p class={styles.title}>{item.courseScheduleNum}</p>
  239. <p class={styles.name}>总课时</p>
  240. </GridItem>
  241. </Grid>
  242. </CellGroup>
  243. ))}
  244. </CheckboxGroup>
  245. </List>
  246. ) : (
  247. <OEmpty btnStatus={false} tips="暂无班级" />
  248. )}
  249. <OSticky position="bottom">
  250. <div class={'btnGroup'}>
  251. <Button block round type="primary" onClick={onSubmit}>
  252. 确认
  253. </Button>
  254. </div>
  255. </OSticky>
  256. <Popup v-model:show={forms.showPopover} position="bottom" round class={'popupBottomSearch'}>
  257. <Picker
  258. columns={forms.orchestraList}
  259. onCancel={() => (forms.showPopover = false)}
  260. onConfirm={(val: any) => {
  261. forms.orchestraId = val.selectedOptions[0].value
  262. forms.orchestraName = val.selectedOptions[0].text
  263. forms.showPopover = false
  264. forms.params.page = 1
  265. forms.list = []
  266. forms.listState.dataShow = true // 判断是否有数据
  267. forms.listState.loading = false
  268. forms.listState.finished = false
  269. getList()
  270. }}
  271. />
  272. </Popup>
  273. </div>
  274. )
  275. }
  276. })