exercis-detail.tsx 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. import OHeader from '@/components/o-header'
  2. import OSticky from '@/components/o-sticky'
  3. import OEmpty from '@/components/o-empty'
  4. import dayjs from 'dayjs'
  5. import {
  6. Icon,
  7. Popover,
  8. DatePicker,
  9. DatePickerColumnType,
  10. Popup,
  11. List,
  12. PullRefresh,
  13. showToast,
  14. Dialog,
  15. Image
  16. } from 'vant'
  17. import OFullRefresh from '@/components/o-full-refresh'
  18. import DetailItem from './modals/detail-item'
  19. import { defineComponent, onMounted, reactive, ref, onDeactivated } from 'vue'
  20. import { useRoute, useRouter } from 'vue-router'
  21. import styles from './exercis-detail.module.less'
  22. import request from '@/helpers/request'
  23. import questIcon from '@/school/images/quest-icon.png'
  24. import defaultIcon from '@/school/images/default-icon.png'
  25. import { state as globalState } from '@/state'
  26. export default defineComponent({
  27. name: 'exercis-detail',
  28. setup() {
  29. const router = useRouter()
  30. const route = useRoute()
  31. const platformApi = ref(globalState.platformApi)
  32. const state = reactive({
  33. showPopoverTime: false,
  34. showPopoverOrchestra: false,
  35. currentDate: [dayjs().format('YYYY'), dayjs().format('MM')],
  36. actions: [
  37. { text: '全部乐团', color: 'var(--van-primary-color)' },
  38. { text: '交付团' },
  39. { text: '晋升团' }
  40. ],
  41. id: route.query.id,
  42. heightV: 0 as number,
  43. scrollTop: 0 as number
  44. })
  45. const forms = reactive({
  46. practiceMonth: route.query.practiceMonth
  47. ? route.query.practiceMonth
  48. : state.currentDate[0] + '' + state.currentDate[1],
  49. practiceMonthName: route.query.practiceMonthName
  50. ? route.query.practiceMonthName
  51. : state.currentDate[0] + '年' + state.currentDate[1] + '月',
  52. orchestraId: '',
  53. orchestraName: '',
  54. page: 1,
  55. rows: 20,
  56. userId: route.query.id,
  57. clientType: 'STUDENT'
  58. })
  59. const showTip = ref(false)
  60. const minDate = ref(new Date(dayjs().subtract(10, 'year').format('YYYY-MM-DD')))
  61. const maxDate = ref(new Date(dayjs().add(10, 'year').format('YYYY-MM-DD')))
  62. const columnsType = ref<DatePickerColumnType[]>(['year', 'month'])
  63. const refreshing = ref(false)
  64. const loading = ref(false)
  65. const finished = ref(false)
  66. const showContact = ref(false)
  67. const infoDetail = ref({} as any)
  68. const list = ref([])
  69. const getList = async () => {
  70. loading.value = true
  71. if (refreshing.value) {
  72. list.value = []
  73. forms.page = 1
  74. refreshing.value = false
  75. }
  76. try {
  77. const res = await request.post(`${platformApi.value}/musicPracticeRecord/page`, {
  78. data: { ...forms, feature: 'EVALUATION' }
  79. })
  80. if (list.value.length > 0 && res.data.current === 1) {
  81. return
  82. }
  83. forms.page = res.data.current + 1
  84. list.value = list.value.concat(res.data.rows || [])
  85. showContact.value = list.value.length > 0
  86. loading.value = false
  87. finished.value = res.data.current >= res.data.pages
  88. } catch (e: any) {
  89. // console.log(e, 'e')
  90. const message = e.message
  91. showToast(message)
  92. showContact.value = false
  93. finished.value = true
  94. }
  95. }
  96. const getDetail = async () => {
  97. try {
  98. const res = await request.get(`/api-backend/student/detail/${state.id}`)
  99. console.log(res)
  100. infoDetail.value = { ...res.data }
  101. } catch (e: any) {
  102. // console.log(e, 'e')
  103. const message = e.message
  104. showToast(message)
  105. }
  106. }
  107. onMounted(() => {
  108. getList()
  109. getDetail()
  110. window.addEventListener('scroll', handleScroll)
  111. })
  112. onDeactivated(() => {
  113. window.removeEventListener('scroll', handleScroll)
  114. })
  115. const handleScroll = () => {
  116. const scrollTop =
  117. window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0
  118. state.scrollTop = scrollTop
  119. }
  120. const getHeight = (dataHeight: number) => {
  121. state.heightV = dataHeight
  122. console.log(dataHeight, 'dataHeight')
  123. }
  124. const checkTimer = (val: any) => {
  125. forms.practiceMonth = val.selectedValues[0] + val.selectedValues[1]
  126. forms.practiceMonthName = val.selectedValues[0] + '年' + val.selectedValues[1] + '月'
  127. state.showPopoverTime = false
  128. refreshing.value = true
  129. getList()
  130. }
  131. const onRefresh = () => {
  132. finished.value = false
  133. // 重新加载数据
  134. // 将 loading 设置为 true,表示处于加载状态
  135. loading.value = true
  136. getList()
  137. }
  138. const onBack = () => {
  139. router.go(-1)
  140. }
  141. return () => (
  142. <>
  143. <div class={styles.exercisContainer}>
  144. <div class={styles.topWrap}>
  145. <OSticky position="top" background="#F8F8F8" onGetHeight={getHeight}>
  146. <OHeader
  147. border={false}
  148. background={state.heightV > state.scrollTop ? 'transparent' : '#fff'}
  149. >
  150. {{
  151. right: () => (
  152. <Icon
  153. name={questIcon}
  154. size={22}
  155. color="#333"
  156. onClick={() => {
  157. showTip.value = true
  158. }}
  159. />
  160. )
  161. }}
  162. </OHeader>
  163. </OSticky>
  164. <div class={styles.topInfo}>
  165. <div class={styles.topInfoLeft}>
  166. <div class={styles.headWrap}>
  167. <Image
  168. src={infoDetail.value.avatar ? infoDetail.value.avatar : defaultIcon}
  169. fit="cover"
  170. width="68px"
  171. height="68px"
  172. />
  173. </div>
  174. <div class={styles.infoMsg}>
  175. <p>{infoDetail.value.nickname}</p>
  176. <div class={styles.tag}>
  177. {infoDetail.value.subjectNames ? infoDetail.value.subjectNames : '暂无声部'}
  178. </div>
  179. </div>
  180. </div>
  181. <div class={styles.topInfoRight}>
  182. <div class={styles.infoDay}>
  183. <p class={styles.infoDayMain}>
  184. {infoDetail.value.practiceDays ? infoDetail.value.practiceDays : 0}
  185. {''}
  186. <span>天</span>
  187. </p>
  188. <p class={styles.infoDaysub}>练习天数</p>
  189. </div>
  190. <div class={styles.infoTime}>
  191. <p class={styles.infoDayMain}>
  192. {infoDetail.value.practiceTimes ? infoDetail.value.practiceTimes : 0}
  193. {''}
  194. <span>分钟</span>
  195. </p>
  196. <p class={styles.infoDaysub}>练习时长</p>
  197. </div>
  198. </div>
  199. </div>
  200. <div class={styles.chioseWrap}>
  201. <div style={{ padding: '12px 13px', background: 'transparent' }}>
  202. <div
  203. class={styles.searchBand}
  204. onClick={() => {
  205. state.showPopoverTime = true
  206. }}
  207. >
  208. {forms.practiceMonthName}
  209. <Icon name={state.showPopoverTime ? 'arrow-up' : 'arrow-down'} />
  210. </div>
  211. </div>
  212. {/* <div style={{ padding: '12px 13px', background: 'transparent' }}>
  213. <Popover
  214. v-model:show={state.showPopoverOrchestra}
  215. actions={state.actions}
  216. showArrow={false}
  217. placement="bottom-start"
  218. offset={[0, 12]}
  219. >
  220. {{
  221. reference: () => (
  222. <div class={styles.searchBand}>
  223. 全部乐团
  224. <Icon name={state.showPopoverOrchestra ? 'arrow-up' : 'arrow-down'} />
  225. </div>
  226. )
  227. }}
  228. </Popover>
  229. </div> */}
  230. </div>
  231. </div>
  232. {showContact.value ? (
  233. <OFullRefresh
  234. v-model:modelValue={refreshing.value}
  235. onRefresh={onRefresh}
  236. style="min-height: 100vh;"
  237. >
  238. <List
  239. loading-text=" "
  240. v-model:loading={loading.value}
  241. finished={finished.value}
  242. finished-text="没有更多了"
  243. onLoad={getList}
  244. >
  245. {list.value.map((item: any) => (
  246. <DetailItem item={item} />
  247. ))}
  248. </List>
  249. </OFullRefresh>
  250. ) : (
  251. <OEmpty />
  252. )}
  253. </div>
  254. <Popup v-model:show={state.showPopoverTime} position="bottom" style="{ height: '30%' }">
  255. <DatePicker
  256. onCancel={() => {
  257. state.showPopoverTime = false
  258. }}
  259. onConfirm={checkTimer}
  260. v-model={state.currentDate}
  261. title="选择年月"
  262. minDate={minDate.value}
  263. maxDate={maxDate.value}
  264. columnsType={columnsType.value}
  265. />
  266. </Popup>
  267. <Dialog
  268. class="exercisDetailDialog"
  269. v-model:show={showTip.value}
  270. title="提示框"
  271. confirmButtonText="我知道了"
  272. v-slots={{
  273. title: () => (
  274. <div class={styles.DialogTitle}>
  275. <span></span>
  276. <p>什么是练习数据</p>
  277. </div>
  278. ),
  279. default: () => (
  280. <div class={styles.DialogConent}>
  281. <p>
  282. 练习数据是学生通过云教练自主练习的数据统计,可根据时间段查询学生的练习天数和练习时长{' '}
  283. </p>
  284. <p>练习天数:当天有曲目播放或测评记录即算练习</p>
  285. <p>练习时长:曲目播放和曲目测评的时长总和</p>
  286. </div>
  287. )
  288. }}
  289. ></Dialog>
  290. </>
  291. )
  292. }
  293. })