import { defineComponent, onMounted, onUnmounted, reactive, ref } from 'vue';
import styles from './index.module.less';
import MSticky from '@/components/m-sticky';
import MHeader from '@/components/m-header';
import { browser, formatterDatePicker } from '@/helpers/utils';
import { useRouter } from 'vue-router';
import { DatePicker, List, Popup, Tab, Tabs } from 'vant';
import { postMessage } from '@/helpers/native-message';
import { listenerMessage } from '@/helpers/native-message';
import OFullRefresh from '@/components/m-full-refresh';
import iconBird from './images/icon-bird.png';
import iconPP from './images/icon-p-p.png';
import iconNumber from './images/icon-number.png';
import iconAlbum from './images/icon-album.png';
import icon1 from './images/icon-1.png';
import icon2 from './images/icon-2.png';
import iconArrow from './images/icon-arrow.png';
import iconArrowActive from './images/icon-arrow-active.png';
import iconLl from './images/l-l.png';
import iconLc from './images/l-c.png';
import iconLr from './images/l-r.png';
import iconPl from './images/p-l.png';
import iconPc from './images/p-c.png';
import iconPr from './images/p-r.png';
import MSearch from '@/components/m-search';
import TheTimeRange from '@/components/the-time-range';
import request from '@/helpers/request';
import DetailItem from './modals/detail-item';
import MEmpty from '@/components/m-empty';
import dayjs from 'dayjs';
export default defineComponent({
name: 'exercise-record-index',
setup() {
const router = useRouter();
const tabsRef = ref();
const state = reactive({
tabActive: 'EVALUATION' as 'EVALUATION' | 'PRACTICE',
isClick: false,
showPopoverTime: false
});
//
//
const formEvaluation = reactive({
startTime: '',
endTime: '',
musicSheetName: null,
page: 1,
rows: 20
});
const fromPractice = reactive({
showData: true,
showTime: false,
currentDate: [dayjs().format('YYYY'), dayjs().format('MM')],
practiceMonthName:
dayjs().format('YYYY') + '年' + dayjs().format('MM') + '月',
practiceDetail: {} as any,
practiceList: [] as any
});
const refreshing = ref(false);
const loading = ref(false);
const finished = ref(false);
const showContact = ref(true);
const topWrapHeight = ref(0);
const infoDetail = ref({
evaluationNum: 0,
userMusicNum: 0
});
const onRefresh = () => {
finished.value = false;
// 重新加载数据
// 将 loading 设置为 true,表示处于加载状态
loading.value = true;
getList();
};
const list = ref([]);
const getList = async () => {
if (state.isClick) {
return;
}
state.isClick = true;
if (refreshing.value) {
list.value = [];
formEvaluation.page = 1;
refreshing.value = false;
}
try {
const res = await request.post(`/edu-app/musicPracticeRecord/page`, {
data: { ...formEvaluation, feature: 'EVALUATION' }
});
if (list.value.length > 0 && res.data.current === 1) {
return;
}
list.value = list.value.concat(res.data.rows || []);
formEvaluation.page = res.data.current + 1;
showContact.value = list.value.length > 0;
loading.value = false;
finished.value = res.data.current >= res.data.pages;
} catch {
showContact.value = false;
finished.value = true;
}
state.isClick = false;
};
const getDetail = async () => {
try {
const { data } = await request.post(
`/edu-app/musicPracticeRecord/studentStat`,
{
data: {
startTime: formEvaluation.startTime,
endTime: formEvaluation.endTime,
musicSheetName: formEvaluation.musicSheetName
}
}
);
infoDetail.value = { ...data };
} catch (e: any) {}
};
const onEvaluation = () => {
getDetail();
getList();
};
const tabResize = () => {
tabsRef.value?.resize();
};
//
const getPractice = async () => {
try {
const currentDate = fromPractice.currentDate.join('-');
const { data } = await request.post(
`/edu-app/musicPracticeRecord/studentTrainStat`,
{
data: {
startTime: currentDate + '-01 00:00:00',
endTime:
dayjs(currentDate).endOf('month').format('YYYY-MM-DD') +
' 23:59:59'
}
}
);
const { studentTrainStatList, ...more } = data;
fromPractice.showData = studentTrainStatList?.length > 0;
fromPractice.practiceDetail = { ...more };
const tempList: any = [];
let maxTime = 0;
studentTrainStatList?.forEach((item: any) => {
if (item.practiceTimes > maxTime) {
maxTime = item.practiceTimes;
}
});
studentTrainStatList?.forEach((item: any) => {
tempList.push({
date: dayjs(item.practiceDate).format('MM/DD'),
time: parseFloat((item.practiceTimes / 60).toFixed(2)),
rate: Math.floor((item.practiceTimes / maxTime) * 100)
});
});
fromPractice.practiceList = tempList || [];
} catch (e: any) {}
};
// 我的作品
const gotoMyWork = (pageTag = 'my_work') => {
postMessage({
api: 'open_app_page',
content: {
action: 'app',
pageTag: pageTag,
url: ''
}
});
};
onMounted(() => {
window.addEventListener('resize', tabResize);
listenerMessage('webViewOnResume', () => {
tabResize();
});
onEvaluation();
getPractice();
});
onUnmounted(() => {
window.removeEventListener('resize', tabResize);
});
return () => (
{
topWrapHeight.value = height;
}}>
{{
content: () => (
)
}}
{
formEvaluation.startTime = val.startTime
? val.startTime + ' 00:00:00'
: '';
formEvaluation.endTime = val.endTime
? val.endTime + ' 23:59:59'
: '';
state.showPopoverTime = false;
refreshing.value = true;
loading.value = true;
onEvaluation();
}}
/>
);
}
});