detail.tsx 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  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/question-share.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. data: {
  66. schoolAreaId: forms.id
  67. }
  68. }
  69. );
  70. state.schoolInfo = res.data || {}
  71. // 构建年级、班级及联选择
  72. const columns: any = []
  73. res.data.classData.unshift({
  74. currentClassList: [],
  75. currentGrade: '全部年级'
  76. })
  77. res.data.classData.forEach((grade: any, index: number) => {
  78. let columnItem: any = {}
  79. columnItem.text = grade.currentGrade
  80. columnItem.value = 'grade' + index
  81. columnItem.children = []
  82. grade.currentClassList.unshift('全部班级')
  83. if (grade.currentClassList?.length) {
  84. grade.currentClassList.forEach((classObj: any, cIdx: number) => {
  85. columnItem.children.push({
  86. text: classObj,
  87. value: 'class' + cIdx
  88. })
  89. })
  90. }
  91. columns.push(columnItem)
  92. })
  93. state.gradeColumns = columns
  94. // console.log('555',res, state.gradeColumns)
  95. } catch (error) {
  96. }
  97. }
  98. const queryList = async () => {
  99. try {
  100. const res = await request.post(
  101. '/edu-app/open/meetingQuestionSetting/schoolClass',
  102. {
  103. data: {
  104. schoolAreaId: forms.id,
  105. currentGrade: state.currentGrade,
  106. currentClass: state.currentClass,
  107. sortType: state.currentSort,
  108. asc: state.currentAsc
  109. }
  110. }
  111. );
  112. state.classList = res.data || []
  113. // console.log('222',res)
  114. } catch (error) {
  115. }
  116. }
  117. const filterList = (num: number) => {
  118. if (state.currentSort !== num) {
  119. state.currentAsc = false
  120. } else {
  121. state.currentAsc = !state.currentAsc
  122. }
  123. state.currentSort = num;
  124. queryList()
  125. }
  126. const formatNumberWithComma = (num: number | string) => {
  127. // 将数字转换为字符串,去掉小数点后面的部分
  128. let [integer, decimal] = num.toString().split('.');
  129. // 使用正则表达式添加千分位分隔符
  130. integer = integer.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
  131. // 如果有小数部分,则保留小数部分
  132. return decimal ? `${integer}.${decimal}` : integer;
  133. }
  134. const onRefresh = async () => {
  135. console.log('刷新111')
  136. state.intervalOne = null;
  137. clearInterval(state.intervalOne); // 停止定时器
  138. finished.value = false;
  139. // 重新加载数据
  140. // 将 loading 设置为 true,表示处于加载状态
  141. loading.value = true;
  142. await initData()
  143. refreshing.value = false
  144. };
  145. const initData = async () => {
  146. await queryInfo()
  147. queryList()
  148. nextTick(() => {
  149. let percentage = 0;
  150. state.intervalOne = setInterval(() => {
  151. if (percentage <= state.schoolInfo.supportStudentRate) {
  152. drawCircle('circle1', 1, percentage)
  153. }
  154. if (percentage <= state.schoolInfo.participationStudentRate) {
  155. drawCircle('circle2', 2, percentage)
  156. }
  157. if (percentage === Math.floor(Number(state.schoolInfo.supportStudentRate))) {
  158. drawCircle('circle1', 1, state.schoolInfo.supportStudentRate)
  159. }
  160. if (percentage === Math.floor(Number(state.schoolInfo.participationStudentRate))) {
  161. drawCircle('circle2', 2, state.schoolInfo.participationStudentRate)
  162. }
  163. percentage += 1; // 每次增加1%
  164. if (percentage > Math.max(state.schoolInfo.supportStudentRate, state.schoolInfo.participationStudentRate)) {
  165. clearInterval(state.intervalOne); // 停止定时器
  166. state.intervalOne = null;
  167. // percentage = 0;
  168. }
  169. }, 25); // 每25ms更新一次
  170. });
  171. }
  172. onMounted(async () => {
  173. if (browser().weixin) {
  174. weChatShare.getAppSignature()
  175. }
  176. initData()
  177. });
  178. onUnmounted(() => {
  179. clearInterval(state.intervalOne); // 停止定时器
  180. state.intervalOne = null;
  181. });
  182. return () => (
  183. <OFullRefresh
  184. v-model:modelValue={refreshing.value}
  185. onRefresh={onRefresh}
  186. class={styles.refreshC}>
  187. <div class={styles.detailBody}>
  188. <div class={styles.dbTitle}>
  189. <div class={styles.dtName}>
  190. <img src={schoolIcon} />
  191. <p>{state.schoolInfo.schoolName}</p>
  192. </div>
  193. <div class={styles.dtDesc}>共<span> {state.schoolInfo.classNum} </span>个班级,<span>{state.schoolInfo.studentNum}</span>人参与调查</div>
  194. </div>
  195. {/* <div class={styles.dbStatic}>
  196. <div class={styles.dsItem}>
  197. <div><span>{formatNumberWithComma(state.schoolInfo.supportStudentNum || 0)}</span><i>人</i></div>
  198. <p>支持学校开展</p>
  199. <i class={[styles.dsIcon, styles.dsIcon1]}></i>
  200. </div>
  201. <div class={styles.dsItem}>
  202. <div><span>{state.schoolInfo.supportStudentRate}%</span></div>
  203. <p>支持率</p>
  204. <i class={[styles.dsIcon, styles.dsIcon2]}></i>
  205. </div>
  206. </div> */}
  207. {/** 圆环统计 */}
  208. <div class={styles.sRing}>
  209. <div class={[styles.srItem,styles.srItemOne]}>
  210. <div class={styles.siLeft}>
  211. <canvas id="circle1" width="85" height="85"></canvas>
  212. <p>支持率</p>
  213. </div>
  214. <div class={styles.siRight}>
  215. <div><span class={styles.sBlue}>{formatNumberWithComma(state.schoolInfo.supportStudentNum || 0)}</span><i>人</i></div>
  216. <p>支持开展</p>
  217. </div>
  218. </div>
  219. <div class={styles.srItem}>
  220. <div class={styles.siLeft}>
  221. <canvas id="circle2" width="85" height="85"></canvas>
  222. <p>参加率</p>
  223. </div>
  224. <div class={styles.siRight}>
  225. <div><span class={styles.sGreen}>{formatNumberWithComma(state.schoolInfo.participationStudentNum||0)}</span><i>人</i></div>
  226. <p>报名参加</p>
  227. </div>
  228. </div>
  229. </div>
  230. {/** 选择年级班级 */}
  231. <div class={[styles.gradeColumn, state.gradeStatus && styles.openVal]} onClick={() => state.gradeStatus = true}>
  232. <span class={state.gradeContent && styles.gcText}>{state.gradeContent ? state.gradeContent : '请选择年级班级'}</span>
  233. <i></i>
  234. </div>
  235. {/** 排序栏 */}
  236. <ul class={styles.sortColumn}>
  237. <li class={state.currentSort === 1 && styles.sortActive} onClick={() => filterList(1)}>
  238. <span>参与调查人数</span>
  239. <i class={[(state.currentSort === 1 && !state.currentAsc) && styles.actDown, (state.currentSort === 1 && state.currentAsc) && styles.actUp]}></i>
  240. </li>
  241. <li class={state.currentSort === 2 && styles.sortActive} onClick={() => filterList(2)}>
  242. <span>支持人数</span>
  243. <i class={[(state.currentSort === 2 && !state.currentAsc) && styles.actDown, (state.currentSort === 2 && state.currentAsc) && styles.actUp]}></i>
  244. </li>
  245. <li class={state.currentSort === 3 && styles.sortActive} onClick={() => filterList(3)}>
  246. <span>支持率</span>
  247. <i class={[(state.currentSort === 3 && !state.currentAsc) && styles.actDown, (state.currentSort === 3 && state.currentAsc) && styles.actUp]}></i>
  248. </li>
  249. <li class={state.currentSort === 4 && styles.sortActive} onClick={() => filterList(4)}>
  250. <span>参加人数</span>
  251. <i class={[(state.currentSort === 4 && !state.currentAsc) && styles.actDown, (state.currentSort === 4 && state.currentAsc) && styles.actUp]}></i>
  252. </li>
  253. <li class={state.currentSort === 5 && styles.sortActive} onClick={() => filterList(5)}>
  254. <span>参加率</span>
  255. <i class={[(state.currentSort === 5 && !state.currentAsc) && styles.actDown, (state.currentSort === 5 && state.currentAsc) && styles.actUp]}></i>
  256. </li>
  257. </ul>
  258. {/** 班级列表 */}
  259. <div class={styles.scList}>
  260. {
  261. state.classList.map((item: any) => (
  262. <div class={styles.sItem}>
  263. <div class={[styles.itemTile, styles.itemTileDetail]}>
  264. <img src={gradeIcon} />
  265. <p>{item.currentGrade||''}{item.currentClass || ''}</p>
  266. <div class={styles.itRight}><span class={styles.sRed}>{formatNumberWithComma(item.studentNum || 0)}</span> 人参与调查</div>
  267. </div>
  268. <ul class={styles.itemContent}>
  269. <li>
  270. <div class={styles.icTop}>
  271. <span class={styles.sBlue}>{formatNumberWithComma(item.supportStudentNum || 0)}</span><i>人</i>
  272. </div>
  273. <p>支持开展</p>
  274. </li>
  275. <li>
  276. <div class={styles.icTop}>
  277. <span class={styles.sBlue}>{Number(item.supportStudentRate || 0).toFixed(2)}%</span>
  278. </div>
  279. <p>支持率</p>
  280. </li>
  281. <li>
  282. <div class={styles.icTop}>
  283. <span class={styles.sGreen}>{formatNumberWithComma(item.participationStudentNum || 0)}</span><i>人</i>
  284. </div>
  285. <p>报名参加</p>
  286. </li>
  287. <li>
  288. <div class={styles.icTop}>
  289. <span class={styles.sGreen}>{Number(item.participationStudentRate || 0).toFixed(2)}%</span>
  290. </div>
  291. <p>参加率</p>
  292. </li>
  293. </ul>
  294. </div>
  295. ))
  296. }
  297. </div>
  298. {/* 班级 */}
  299. <Popup
  300. v-model:show={state.gradeStatus}
  301. position="bottom"
  302. round
  303. safeAreaInsetBottom
  304. lazyRender={false}
  305. class={'popupBottomSearch'}
  306. onOpen={() => {
  307. state.gradePopShow = true;
  308. }}
  309. onClosed={() => {
  310. state.gradePopShow = false;
  311. }}>
  312. {state.gradePopShow && (
  313. <Picker
  314. showToolbar
  315. v-model={state.gradeOptionIndex}
  316. columns={state.gradeColumns}
  317. onCancel={() => (state.gradeStatus = false)}
  318. onConfirm={(val: any) => {
  319. console.log('选择1111',val)
  320. state.currentGrade = val.selectedOptions[0].text === '全部年级' ? '' : val.selectedOptions[0].text
  321. state.currentClass = val.selectedOptions[1].text === '全部班级' ? '' : val.selectedOptions[1].text
  322. state.gradeOptionIndex = [val.selectedOptions[0].value, val.selectedOptions[1].value]
  323. state.gradeContent = state.currentGrade + state.currentClass
  324. state.gradeStatus = false;
  325. queryList()
  326. }}
  327. />
  328. )}
  329. </Popup>
  330. {/* <MWxTip /> */}
  331. </div>
  332. </OFullRefresh>
  333. );
  334. }
  335. });