exercis-detail.tsx 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  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. isBack
  148. border={false}
  149. background={state.heightV > state.scrollTop ? 'transparent' : '#fff'}
  150. >
  151. {{
  152. right: () => (
  153. <Icon
  154. name={questIcon}
  155. size={22}
  156. color="#333"
  157. onClick={() => {
  158. showTip.value = true
  159. }}
  160. />
  161. )
  162. }}
  163. </OHeader>
  164. </OSticky>
  165. <div class={styles.topInfo}>
  166. <div class={styles.topInfoLeft}>
  167. <div class={styles.headWrap}>
  168. <Image
  169. src={infoDetail.value.avatar ? infoDetail.value.avatar : defaultIcon}
  170. fit="cover"
  171. width="68px"
  172. height="68px"
  173. />
  174. </div>
  175. <div class={styles.infoMsg}>
  176. <p>{infoDetail.value.nickname}</p>
  177. <div class={styles.tag}>
  178. {infoDetail.value.subjectNames ? infoDetail.value.subjectNames : '暂无声部'}
  179. </div>
  180. </div>
  181. </div>
  182. <div class={styles.topInfoRight}>
  183. <div class={styles.infoDay}>
  184. <p class={styles.infoDayMain}>
  185. {infoDetail.value.practiceDays ? infoDetail.value.practiceDays : 0}
  186. {''}
  187. <span>天</span>
  188. </p>
  189. <p class={styles.infoDaysub}>练习天数</p>
  190. </div>
  191. <div class={styles.infoTime}>
  192. <p class={styles.infoDayMain}>
  193. {infoDetail.value.practiceTimes ? infoDetail.value.practiceTimes : 0}
  194. {''}
  195. <span>分钟</span>
  196. </p>
  197. <p class={styles.infoDaysub}>练习时长</p>
  198. </div>
  199. </div>
  200. </div>
  201. <div class={styles.chioseWrap}>
  202. <div style={{ padding: '12px 13px', background: 'transparent' }}>
  203. <div
  204. class={styles.searchBand}
  205. onClick={() => {
  206. state.showPopoverTime = true
  207. }}
  208. >
  209. {forms.practiceMonthName}
  210. <Icon name={state.showPopoverTime ? 'arrow-up' : 'arrow-down'} />
  211. </div>
  212. </div>
  213. {/* <div style={{ padding: '12px 13px', background: 'transparent' }}>
  214. <Popover
  215. v-model:show={state.showPopoverOrchestra}
  216. actions={state.actions}
  217. showArrow={false}
  218. placement="bottom-start"
  219. offset={[0, 12]}
  220. >
  221. {{
  222. reference: () => (
  223. <div class={styles.searchBand}>
  224. 全部乐团
  225. <Icon name={state.showPopoverOrchestra ? 'arrow-up' : 'arrow-down'} />
  226. </div>
  227. )
  228. }}
  229. </Popover>
  230. </div> */}
  231. </div>
  232. </div>
  233. {showContact.value ? (
  234. <OFullRefresh
  235. v-model:modelValue={refreshing.value}
  236. onRefresh={onRefresh}
  237. style="min-height: 100vh;"
  238. >
  239. <List
  240. loading-text=" "
  241. v-model:loading={loading.value}
  242. finished={finished.value}
  243. finished-text="没有更多了"
  244. onLoad={getList}
  245. >
  246. {list.value.map((item: any) => (
  247. <DetailItem item={item} />
  248. ))}
  249. </List>
  250. </OFullRefresh>
  251. ) : (
  252. <OEmpty />
  253. )}
  254. </div>
  255. <Popup v-model:show={state.showPopoverTime} position="bottom" style="{ height: '30%' }">
  256. <DatePicker
  257. onCancel={() => {
  258. state.showPopoverTime = false
  259. }}
  260. onConfirm={checkTimer}
  261. v-model={state.currentDate}
  262. title="选择年月"
  263. minDate={minDate.value}
  264. maxDate={maxDate.value}
  265. columnsType={columnsType.value}
  266. />
  267. </Popup>
  268. <Dialog
  269. class="exercisDetailDialog"
  270. v-model:show={showTip.value}
  271. title="提示框"
  272. confirmButtonText="我知道了"
  273. v-slots={{
  274. title: () => (
  275. <div class={styles.DialogTitle}>
  276. <span></span>
  277. <p>什么是练习数据</p>
  278. </div>
  279. ),
  280. default: () => (
  281. <div class={styles.DialogConent}>
  282. <p>
  283. 练习数据是学生通过云教练自主练习的数据统计,可根据时间段查询学生的练习天数和练习时长{' '}
  284. </p>
  285. <p>练习天数:当天有曲目播放或测评记录即算练习</p>
  286. <p>练习时长:曲目播放和曲目测评的时长总和</p>
  287. </div>
  288. )
  289. }}
  290. ></Dialog>
  291. </>
  292. )
  293. }
  294. })