index.tsx 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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. }
  71. })
  72. const temps = data.rows || []
  73. const s = [] as any
  74. temps.forEach((item: any) => {
  75. s.push({
  76. text: item.name,
  77. value: item.id
  78. })
  79. })
  80. forms.orchestraList = [...s]
  81. // 判断是否有乐团
  82. if (s.length > 0) {
  83. forms.orchestraId = s[0].value
  84. forms.orchestraName = s[0].text
  85. }
  86. } catch {
  87. //
  88. }
  89. }
  90. // 获取班级
  91. const getList = async () => {
  92. // 查询没有设置指导老师的班级
  93. try {
  94. if (forms.isClick) return
  95. forms.isClick = true
  96. const { data } = await request.post('/api-school/classGroup/page', {
  97. data: {
  98. ...forms.params,
  99. schoolId: baseState.user.data.school.id,
  100. orchestraId: forms.orchestraId,
  101. classType: props.classType
  102. // orchestraType: 'DELIVERY'
  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. // 监听班级类型变化
  124. watch(
  125. () => props.classType,
  126. () => {
  127. forms.params.page = 1
  128. forms.list = []
  129. forms.listState.dataShow = true // 判断是否有数据
  130. forms.listState.loading = false
  131. forms.listState.finished = false
  132. getList()
  133. }
  134. )
  135. const onSelect = (type: string) => {
  136. forms.checkboxRefs[type].toggle()
  137. }
  138. // 确定选择班级
  139. const onSubmit = () => {
  140. emit('confirm', forms.check)
  141. emit('close')
  142. }
  143. onMounted(async () => {
  144. // 判断是否有乐团编号
  145. if (!props.orchestraId) {
  146. await getOrchestras()
  147. }
  148. await getList()
  149. })
  150. return () => (
  151. <div class={styles.practiceClass}>
  152. <OSticky position="top">
  153. <OHeader title="选择班级" desotry={false} />
  154. {!props.orchestraId && (
  155. <div style={{ padding: '12px 13px', background: '#f6f6f6' }}>
  156. <div class={styles.searchBand} onClick={() => (forms.showPopover = true)}>
  157. <div class={['van-ellipsis', styles.bandName]}>{forms.orchestraName}</div>
  158. <Icon name={forms.showPopover ? 'arrow-up' : 'arrow-down'} />
  159. </div>
  160. </div>
  161. )}
  162. </OSticky>
  163. {forms.listState.dataShow ? (
  164. <List
  165. v-model:loading={forms.listState.loading}
  166. finished={forms.listState.finished}
  167. style={{ marginTop: props.orchestraId ? '12px' : 0 }}
  168. finishedText=" "
  169. class={[styles.liveList]}
  170. onLoad={getList}
  171. immediateCheck={false}
  172. >
  173. <CheckboxGroup class={[styles.gridContainer, styles.gridClass]} v-model={forms.check}>
  174. {forms.list.map((item: any) => (
  175. <CellGroup
  176. class={styles.classCellGroup}
  177. onClick={() => {
  178. if (item.teacherId) {
  179. onSelect(item.id)
  180. }
  181. }}
  182. border={false}
  183. >
  184. <Cell center titleStyle={{ flex: '0 auto' }} valueClass={styles.classCheckbox}>
  185. {{
  186. icon: () => <Image src={iconTeacher} class={styles.img} />,
  187. title: () => (
  188. <div class={styles.content}>
  189. <div class={styles.teacherName}>
  190. {item.teacherName ? (
  191. <div class={[styles.name, styles.maxWidth, 'van-ellipsis']}>
  192. {item.teacherName}
  193. </div>
  194. ) : (
  195. <div class={[styles.name, 'van-ellipsis']} style={{ color: 'red' }}>
  196. 暂未设置伴学指导
  197. </div>
  198. )}
  199. <Tag type="primary">{item.name}</Tag>
  200. </div>
  201. <div class={[styles.orchestraName, 'van-ellipsis']}>
  202. {item.orchestraName}
  203. </div>
  204. </div>
  205. ),
  206. value: () => (
  207. <Checkbox
  208. name={item.id}
  209. ref={(el: any) => (forms.checkboxRefs[item.id] = el)}
  210. disabled={item.teacherId ? false : true}
  211. onClick={(e: any) => {
  212. e.stopPropagation()
  213. }}
  214. ></Checkbox>
  215. )
  216. }}
  217. </Cell>
  218. <Grid border={false} columnNum={3}>
  219. <GridItem>
  220. <p class={styles.title}>{item.preStudentNum}</p>
  221. <p class={styles.name}>学生人数</p>
  222. </GridItem>
  223. <GridItem>
  224. <p class={[styles.title]}>
  225. {item.courseScheduleNum - item.completeCourseScheduleNum}
  226. </p>
  227. <p class={styles.name}>剩余课时</p>
  228. </GridItem>
  229. <GridItem>
  230. <p class={styles.title}>{item.courseScheduleNum}</p>
  231. <p class={styles.name}>总课时</p>
  232. </GridItem>
  233. </Grid>
  234. </CellGroup>
  235. ))}
  236. </CheckboxGroup>
  237. </List>
  238. ) : (
  239. <OEmpty btnStatus={false} tips="暂无班级" />
  240. )}
  241. <OSticky position="bottom">
  242. <div class={'btnGroup'}>
  243. <Button block round type="primary" onClick={onSubmit}>
  244. 确认
  245. </Button>
  246. </div>
  247. </OSticky>
  248. <Popup v-model:show={forms.showPopover} position="bottom" round>
  249. <Picker
  250. columns={forms.orchestraList}
  251. onCancel={() => (forms.showPopover = false)}
  252. onConfirm={(val: any) => {
  253. forms.orchestraId = val.selectedOptions[0].value
  254. forms.orchestraName = val.selectedOptions[0].text
  255. forms.showPopover = false
  256. forms.params.page = 1
  257. forms.list = []
  258. forms.listState.dataShow = true // 判断是否有数据
  259. forms.listState.loading = false
  260. forms.listState.finished = false
  261. getList()
  262. }}
  263. />
  264. </Popup>
  265. </div>
  266. )
  267. }
  268. })