exercis-detail.tsx 9.8 KB

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