detail.tsx 13 KB

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