index.tsx 9.7 KB

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