detail.tsx 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. import { defineComponent, onMounted, reactive, ref, nextTick, onUnmounted } from 'vue';
  2. import styles from './index.module.less';
  3. import { List, Popup, DatePicker, Popover, Picker } from 'vant';
  4. import request from '@/helpers/request';
  5. import { useRoute, useRouter } from 'vue-router';
  6. import OEmpty from '@/components/m-empty';
  7. import MWxTip from '@/components/m-wx-tip';
  8. import OSearch from '@/components/m-search';
  9. import positionIcon from './images/position_icon.png';
  10. import scIcon1 from './images/sc_icon1.png';
  11. import scIcon2 from './images/sc_icon2.png';
  12. import scIcon3 from './images/sc_icon3.png';
  13. import schoolIcon from './images/school_icon.png';
  14. import gradeIcon from './images/class_icon.png';
  15. import { number } from 'echarts';
  16. import { drawCircle } from './drawGraph'
  17. import OFullRefresh from '@/components/m-full-refresh';
  18. import useWeChatShare from '@/hooks/useWeChatShare';
  19. import { browser } from '@/helpers/utils';
  20. export default defineComponent({
  21. name: 'statistics-detail',
  22. setup() {
  23. const route = useRoute();
  24. const router = useRouter();
  25. const areaTenantName = sessionStorage.getItem('areaTenantName') || ''
  26. const shareTitle = areaTenantName + '音乐(器乐)数字化转型问卷统计';
  27. const weChatShare = useWeChatShare(
  28. shareTitle,
  29. '科技赋能音乐(器乐)学习,在每一个孩子心中奏响美妙的乐章。',
  30. window.location.origin + '/classroom-app/shareImg/questionnaire-statistics-new.png'
  31. );
  32. const tabName = ref('all');
  33. const forms = reactive({
  34. schoolName: '',
  35. id: route.query.id,
  36. yearStatus: false,
  37. schoolId: null,
  38. });
  39. const refreshing = ref(false);
  40. const loading = ref(true);
  41. const finished = ref(false);
  42. const state = reactive({
  43. saveLoading: false,
  44. image: null as any,
  45. shareLoading: false,
  46. schoolInfo: {} as any,
  47. classList: [] as any,
  48. currentSort: 1, // 当前选中的排序方式
  49. currentAsc: false, // 是否生序,默认是降序
  50. gradeColumns: [],
  51. gradeStatus: false,
  52. gradePopShow: false,
  53. currentGrade: "",
  54. currentClass: "",
  55. gradeOptionIndex: [] as any,
  56. gradeContent: null as any,
  57. intervalOne: null as any, // 动画定时器
  58. });
  59. // 获取学校信息
  60. const queryInfo = async () => {
  61. try {
  62. const res = await request.post(
  63. '/edu-app/open/meetingQuestionSetting/schoolStat',
  64. {
  65. hideLoading: false,
  66. data: {
  67. schoolAreaId: forms.id
  68. }
  69. }
  70. );
  71. state.schoolInfo = res.data || {}
  72. // 构建年级、班级及联选择
  73. const columns: any = []
  74. res.data.classData.unshift({
  75. currentClassList: [],
  76. currentGrade: '全部年级'
  77. })
  78. res.data.classData.forEach((grade: any, index: number) => {
  79. let columnItem: any = {}
  80. columnItem.text = grade.currentGrade
  81. columnItem.value = 'grade' + index
  82. columnItem.children = []
  83. grade.currentClassList.unshift('全部班级')
  84. if (grade.currentClassList?.length) {
  85. grade.currentClassList.forEach((classObj: any, cIdx: number) => {
  86. columnItem.children.push({
  87. text: classObj,
  88. value: 'class' + cIdx
  89. })
  90. })
  91. }
  92. columns.push(columnItem)
  93. })
  94. state.gradeColumns = columns
  95. // console.log('555',res, state.gradeColumns)
  96. } catch (error) {
  97. }
  98. }
  99. const queryList = async () => {
  100. try {
  101. const res = await request.post(
  102. '/edu-app/open/meetingQuestionSetting/schoolClass',
  103. {
  104. data: {
  105. schoolAreaId: forms.id,
  106. currentGrade: state.currentGrade,
  107. currentClass: state.currentClass,
  108. sortType: state.currentSort,
  109. asc: state.currentAsc
  110. }
  111. }
  112. );
  113. state.classList = res.data || []
  114. // console.log('222',res)
  115. } catch (error) {
  116. }
  117. }
  118. const filterList = (num: number) => {
  119. if (state.currentSort !== num) {
  120. state.currentAsc = false
  121. } else {
  122. state.currentAsc = !state.currentAsc
  123. }
  124. state.currentSort = num;
  125. queryList()
  126. }
  127. const formatNumberWithComma = (num: number | string) => {
  128. // 将数字转换为字符串,去掉小数点后面的部分
  129. let [integer, decimal] = num.toString().split('.');
  130. // 使用正则表达式添加千分位分隔符
  131. integer = integer.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
  132. // 如果有小数部分,则保留小数部分
  133. return decimal ? `${integer}.${decimal}` : integer;
  134. }
  135. const onRefresh = async () => {
  136. // console.log('刷新111')
  137. clearDataAnimation();
  138. finished.value = false;
  139. // 重新加载数据
  140. // 将 loading 设置为 true,表示处于加载状态
  141. loading.value = true;
  142. await initData()
  143. refreshing.value = false
  144. };
  145. const clearDataAnimation = () => {
  146. clearInterval(state.intervalOne); // 停止定时器
  147. state.intervalOne = null;
  148. }
  149. const initData = async () => {
  150. await queryInfo()
  151. queryList()
  152. nextTick(() => {
  153. let percentage = 0;
  154. state.intervalOne = setInterval(() => {
  155. if (percentage <= state.schoolInfo.supportStudentRate) {
  156. // console.log(percentage,state.schoolInfo.supportStudentRate)
  157. drawCircle('circle1', 1, percentage)
  158. }
  159. if (percentage <= state.schoolInfo.participationStudentRate) {
  160. drawCircle('circle2', 2, percentage)
  161. }
  162. if (percentage === Math.floor(Number(state.schoolInfo.supportStudentRate))) {
  163. drawCircle('circle1', 1, state.schoolInfo.supportStudentRate)
  164. }
  165. if (percentage === Math.floor(Number(state.schoolInfo.participationStudentRate))) {
  166. drawCircle('circle2', 2, state.schoolInfo.participationStudentRate)
  167. }
  168. percentage += 1; // 每次增加1%
  169. if (percentage > Math.max(state.schoolInfo.supportStudentRate, state.schoolInfo.participationStudentRate)) {
  170. clearDataAnimation();
  171. // percentage = 0;
  172. }
  173. }, 25); // 每25ms更新一次
  174. });
  175. }
  176. onMounted(async () => {
  177. if (browser().weixin) {
  178. weChatShare.getAppSignature()
  179. }
  180. initData()
  181. });
  182. onUnmounted(() => {
  183. clearDataAnimation();
  184. });
  185. return () => (
  186. <OFullRefresh
  187. freshDisabled={state.gradeStatus}
  188. v-model:modelValue={refreshing.value}
  189. onRefresh={onRefresh}
  190. class={styles.refreshC}>
  191. <div class={styles.detailBody}>
  192. <div class={styles.dbTitle}>
  193. <div class={styles.dtName}>
  194. <img src={schoolIcon} />
  195. <p>{state.schoolInfo.schoolName}</p>
  196. </div>
  197. <div class={styles.dtDesc}>共<span> {state.schoolInfo.classNum} </span>个班级,<span>{state.schoolInfo.studentNum}</span>人参与调查</div>
  198. </div>
  199. {/* <div class={styles.dbStatic}>
  200. <div class={styles.dsItem}>
  201. <div><span>{formatNumberWithComma(state.schoolInfo.supportStudentNum || 0)}</span><i>人</i></div>
  202. <p>支持学校开展</p>
  203. <i class={[styles.dsIcon, styles.dsIcon1]}></i>
  204. </div>
  205. <div class={styles.dsItem}>
  206. <div><span>{state.schoolInfo.supportStudentRate}%</span></div>
  207. <p>支持率</p>
  208. <i class={[styles.dsIcon, styles.dsIcon2]}></i>
  209. </div>
  210. </div> */}
  211. {/** 圆环统计 */}
  212. <div class={styles.sRing}>
  213. <div class={[styles.srItem,styles.srItemOne]}>
  214. <div class={styles.siLeft}>
  215. <canvas id="circle1" width="85" height="85"></canvas>
  216. <p>支持率</p>
  217. </div>
  218. <div class={styles.siRight}>
  219. <div><span class={styles.sBlue}>{formatNumberWithComma(state.schoolInfo.supportStudentNum || 0)}</span><i>人</i></div>
  220. <p>支持开展</p>
  221. </div>
  222. </div>
  223. <div class={styles.srItem}>
  224. <div class={styles.siLeft}>
  225. <canvas id="circle2" width="85" height="85"></canvas>
  226. <p>参加率</p>
  227. </div>
  228. <div class={styles.siRight}>
  229. <div><span class={styles.sGreen}>{formatNumberWithComma(state.schoolInfo.participationStudentNum||0)}</span><i>人</i></div>
  230. <p>报名参加</p>
  231. </div>
  232. </div>
  233. </div>
  234. {/** 选择年级班级 */}
  235. <div class={[styles.gradeColumn, state.gradeStatus && styles.openVal]} onClick={() => state.gradeStatus = true}>
  236. <span class={state.gradeContent && styles.gcText}>{state.gradeContent ? state.gradeContent : '请选择年级班级'}</span>
  237. <i></i>
  238. </div>
  239. {/** 排序栏 */}
  240. <ul class={styles.sortColumn}>
  241. <li class={state.currentSort === 1 && styles.sortActive} onClick={() => filterList(1)}>
  242. <span>参与调查人数</span>
  243. <i class={[(state.currentSort === 1 && !state.currentAsc) && styles.actDown, (state.currentSort === 1 && state.currentAsc) && styles.actUp]}></i>
  244. </li>
  245. <li class={state.currentSort === 2 && styles.sortActive} onClick={() => filterList(2)}>
  246. <span>支持人数</span>
  247. <i class={[(state.currentSort === 2 && !state.currentAsc) && styles.actDown, (state.currentSort === 2 && state.currentAsc) && styles.actUp]}></i>
  248. </li>
  249. <li class={state.currentSort === 3 && styles.sortActive} onClick={() => filterList(3)}>
  250. <span>支持率</span>
  251. <i class={[(state.currentSort === 3 && !state.currentAsc) && styles.actDown, (state.currentSort === 3 && state.currentAsc) && styles.actUp]}></i>
  252. </li>
  253. <li class={state.currentSort === 4 && styles.sortActive} onClick={() => filterList(4)}>
  254. <span>参加人数</span>
  255. <i class={[(state.currentSort === 4 && !state.currentAsc) && styles.actDown, (state.currentSort === 4 && state.currentAsc) && styles.actUp]}></i>
  256. </li>
  257. <li class={state.currentSort === 5 && styles.sortActive} onClick={() => filterList(5)}>
  258. <span>参加率</span>
  259. <i class={[(state.currentSort === 5 && !state.currentAsc) && styles.actDown, (state.currentSort === 5 && state.currentAsc) && styles.actUp]}></i>
  260. </li>
  261. </ul>
  262. {/** 班级列表 */}
  263. <div class={styles.scList}>
  264. {
  265. state.classList.map((item: any) => (
  266. <div class={styles.sItem}>
  267. <div class={[styles.itemTile, styles.itemTileDetail]}>
  268. <img src={gradeIcon} />
  269. <p>{item.currentGrade||''}{item.currentClass || ''}</p>
  270. <div class={styles.itRight}><span class={styles.sRed}>{formatNumberWithComma(item.studentNum || 0)}</span> 人参与调查</div>
  271. </div>
  272. <ul class={styles.itemContent}>
  273. <li>
  274. <div class={styles.icTop}>
  275. <span class={styles.sBlue}>{formatNumberWithComma(item.supportStudentNum || 0)}</span><i>人</i>
  276. </div>
  277. <p>支持开展</p>
  278. </li>
  279. <li>
  280. <div class={styles.icTop}>
  281. <span class={styles.sBlue}>{Number(item.supportStudentRate || 0).toFixed(2)}%</span>
  282. </div>
  283. <p>支持率</p>
  284. </li>
  285. <li>
  286. <div class={styles.icTop}>
  287. <span class={styles.sGreen}>{formatNumberWithComma(item.participationStudentNum || 0)}</span><i>人</i>
  288. </div>
  289. <p>报名参加</p>
  290. </li>
  291. <li>
  292. <div class={styles.icTop}>
  293. <span class={styles.sGreen}>{Number(item.participationStudentRate || 0).toFixed(2)}%</span>
  294. </div>
  295. <p>参加率</p>
  296. </li>
  297. </ul>
  298. </div>
  299. ))
  300. }
  301. </div>
  302. {/* 班级 */}
  303. <Popup
  304. v-model:show={state.gradeStatus}
  305. position="bottom"
  306. round
  307. safeAreaInsetBottom
  308. lazyRender={false}
  309. class={'popupBottomSearch'}
  310. onOpen={() => {
  311. state.gradePopShow = true;
  312. }}
  313. onClosed={() => {
  314. state.gradePopShow = false;
  315. }}>
  316. {state.gradePopShow && (
  317. <Picker
  318. showToolbar
  319. v-model={state.gradeOptionIndex}
  320. columns={state.gradeColumns}
  321. onCancel={() => (state.gradeStatus = false)}
  322. onConfirm={(val: any) => {
  323. console.log('选择1111',val)
  324. state.currentGrade = val.selectedOptions[0].text === '全部年级' ? '' : val.selectedOptions[0].text
  325. state.currentClass = val.selectedOptions[1].text === '全部班级' ? '' : val.selectedOptions[1].text
  326. state.gradeOptionIndex = [val.selectedOptions[0].value, val.selectedOptions[1].value]
  327. state.gradeContent = state.currentGrade + state.currentClass
  328. state.gradeStatus = false;
  329. queryList()
  330. }}
  331. />
  332. )}
  333. </Popup>
  334. {/* <MWxTip /> */}
  335. </div>
  336. </OFullRefresh>
  337. );
  338. }
  339. });