index.tsx 9.4 KB

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