exercis-detail.tsx 11 KB

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