index.tsx 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. import OEmpty from '@/components/o-empty'
  2. import OHeader from '@/components/o-header'
  3. import OSearch from '@/components/o-search'
  4. import OSticky from '@/components/o-sticky'
  5. import { ActionSheet, Button, Cell, CellGroup, Icon, Image, List, showToast } from 'vant'
  6. import { defineComponent, onMounted, reactive, ref } from 'vue'
  7. import styles from './index.module.less'
  8. import iconEdit from '../images/icon-edit.png'
  9. import iconAdd from '@common/images/icon_add.png'
  10. import { useRouter } from 'vue-router'
  11. import UnitListItem from './models/unit-list-item'
  12. import OFullRefresh from '@/components/o-full-refresh'
  13. import { state } from '@/state'
  14. import request from '@/helpers/request'
  15. export default defineComponent({
  16. name: 'unit-list',
  17. setup() {
  18. const router = useRouter()
  19. const form = reactive({
  20. oPopover: false,
  21. list: [] as any,
  22. listState: {
  23. dataShow: true, // 判断是否有数据
  24. loading: false,
  25. finished: false
  26. },
  27. statusText: '班级类型',
  28. params: {
  29. keyword: null,
  30. classTypeCode: null,
  31. page: 1,
  32. rows: 20
  33. },
  34. isClick: false
  35. })
  36. const platformApi = state.platformApi
  37. const refreshing = ref(false)
  38. const loading = ref(false)
  39. const getList = async () => {
  40. loading.value = true
  41. try {
  42. if (refreshing.value) {
  43. form.params.page = 1
  44. form.list = []
  45. refreshing.value = false
  46. }
  47. const res = await request.post(`${platformApi}/studentUnitExamination/queryPageByTeacher`, {
  48. data: { ...form.params }
  49. })
  50. if (form.list.length > 0 && res.data.pages === 1) {
  51. return
  52. }
  53. form.params.page = res.data.current + 1
  54. //form.list =form.list .concat(res.data.rows || [])
  55. form.list = res.data.rows
  56. form.listState.dataShow = form.list.length > 0
  57. loading.value = false
  58. // form.listState.finished = true
  59. form.listState.finished = res.data.current >= res.data.pages
  60. } catch (e: any) {
  61. // console.log(e, 'e')
  62. const message = e.message
  63. showToast(message)
  64. form.listState.dataShow = false
  65. form.listState.finished = true
  66. }
  67. }
  68. const onRefresh = () => {
  69. form.listState.finished = true
  70. // 重新加载数据
  71. // 将 loading 设置为 true,表示处于加载状态
  72. loading.value = true
  73. getList()
  74. }
  75. const onSearch = () => {
  76. form.params.page = 1
  77. form.list = []
  78. form.listState.dataShow = true // 判断是否有数据
  79. form.listState.loading = false
  80. form.listState.finished = false
  81. getList()
  82. }
  83. onMounted(() => {
  84. getList()
  85. })
  86. const createUnit = () => {
  87. router.push('/unit-create')
  88. }
  89. return () => (
  90. <div class={styles.unitTest}>
  91. <OSticky position="top">
  92. {/* */}
  93. <OHeader>
  94. {{
  95. right: () =>
  96. platformApi == '/api-teacher' ? (
  97. <Icon name={iconAdd} size={19} onClick={createUnit} />
  98. ) : null
  99. }}
  100. </OHeader>
  101. <OSearch
  102. placeholder="请输入测验名称"
  103. inputBackground="white"
  104. background="#f6f8f9"
  105. onSearch={(val: any) => {
  106. form.params.keyword = val
  107. onSearch()
  108. }}
  109. v-slots={{
  110. left: () => (
  111. <div
  112. class={styles.searchBand}
  113. style={{ marginRight: '13px' }}
  114. onClick={() => (form.oPopover = true)}
  115. >
  116. {form.statusText} <Icon name={form.oPopover ? 'arrow-up' : 'arrow-down'} />
  117. </div>
  118. )
  119. }}
  120. />
  121. </OSticky>
  122. {form.listState.dataShow ? (
  123. <OFullRefresh
  124. v-model:modelValue={refreshing.value}
  125. onRefresh={onRefresh}
  126. style="min-height: 100vh;"
  127. >
  128. <List
  129. v-model:loading={form.listState.loading}
  130. finished={form.listState.finished}
  131. finishedText=" "
  132. class={[styles.liveList]}
  133. // onLoad={getList}
  134. immediateCheck={false}
  135. >
  136. {form.list.map((item: any) => (
  137. <UnitListItem item={item}></UnitListItem>
  138. ))}
  139. </List>
  140. </OFullRefresh>
  141. ) : (
  142. <OEmpty tips="暂无单元测验" />
  143. )}
  144. <ActionSheet
  145. v-model:show={form.oPopover}
  146. cancelText="取消"
  147. actions={
  148. [
  149. { name: '班级类型', id: 'ALL' },
  150. { name: '单技班', id: 'SINGLE' },
  151. { name: '乐理班', id: 'MUSIC_THEORY' },
  152. { name: '合奏班', id: 'INSTRUMENTAL_ENSEMBLE' }
  153. ] as any
  154. }
  155. onSelect={(val: any) => {
  156. form.statusText = val.name
  157. form.params.classTypeCode = val.id === 'ALL' ? null : val.id
  158. form.oPopover = false
  159. onSearch()
  160. }}
  161. />
  162. </div>
  163. )
  164. }
  165. })