detail.tsx 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. import { defineComponent, onMounted, reactive, ref } 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. export default defineComponent({
  17. name: 'statistics-detail',
  18. setup() {
  19. const route = useRoute();
  20. const router = useRouter();
  21. const tabName = ref('all');
  22. const forms = reactive({
  23. schoolName: '',
  24. id: route.query.id,
  25. yearStatus: false,
  26. schoolId: null,
  27. });
  28. const refreshing = ref(false);
  29. const loading = ref(true);
  30. const state = reactive({
  31. saveLoading: false,
  32. image: null as any,
  33. shareLoading: false,
  34. schoolInfo: {} as any,
  35. classList: [] as any,
  36. currentSort: 1, // 当前选中的排序方式
  37. currentAsc: false, // 是否生序,默认是降序
  38. gradeColumns: [],
  39. gradeStatus: false,
  40. gradePopShow: false,
  41. currentGrade: "",
  42. currentClass: "",
  43. gradeOptionIndex: [] as any,
  44. gradeContent: null as any,
  45. });
  46. // 获取学校信息
  47. const queryInfo = async () => {
  48. try {
  49. const res = await request.post(
  50. '/edu-app/open/meetingQuestionSetting/schoolStat',
  51. {
  52. data: {
  53. schoolAreaId: forms.id
  54. }
  55. }
  56. );
  57. state.schoolInfo = res.data || {}
  58. // 构建年级、班级及联选择
  59. const columns: any = []
  60. res.data.classData.unshift({
  61. currentClassList: [],
  62. currentGrade: '全部年级'
  63. })
  64. res.data.classData.forEach((grade: any, index: number) => {
  65. let columnItem: any = {}
  66. columnItem.text = grade.currentGrade
  67. columnItem.value = 'grade' + index
  68. columnItem.children = []
  69. grade.currentClassList.unshift('全部班级')
  70. if (grade.currentClassList?.length) {
  71. grade.currentClassList.forEach((classObj: any, cIdx: number) => {
  72. columnItem.children.push({
  73. text: classObj,
  74. value: 'class' + cIdx
  75. })
  76. })
  77. }
  78. columns.push(columnItem)
  79. })
  80. state.gradeColumns = columns
  81. // console.log('555',res, state.gradeColumns)
  82. } catch (error) {
  83. }
  84. }
  85. const queryList = async () => {
  86. try {
  87. const res = await request.post(
  88. '/edu-app/open/meetingQuestionSetting/schoolClass',
  89. {
  90. data: {
  91. schoolAreaId: forms.id,
  92. currentGrade: state.currentGrade,
  93. currentClass: state.currentClass,
  94. sortType: state.currentSort,
  95. asc: state.currentAsc
  96. }
  97. }
  98. );
  99. state.classList = res.data || []
  100. // console.log('222',res)
  101. } catch (error) {
  102. }
  103. }
  104. const filterList = (num: number) => {
  105. if (state.currentSort !== num) {
  106. state.currentAsc = false
  107. } else {
  108. state.currentAsc = !state.currentAsc
  109. }
  110. state.currentSort = num;
  111. queryList()
  112. }
  113. const formatNumberWithComma = (num: number | string) => {
  114. // 将数字转换为字符串,去掉小数点后面的部分
  115. let [integer, decimal] = num.toString().split('.');
  116. // 使用正则表达式添加千分位分隔符
  117. integer = integer.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
  118. // 如果有小数部分,则保留小数部分
  119. return decimal ? `${integer}.${decimal}` : integer;
  120. }
  121. onMounted(async () => {
  122. await queryInfo()
  123. queryList()
  124. });
  125. return () => (
  126. <div class={styles.detailBody}>
  127. <div class={styles.dbTitle}>
  128. <div class={styles.dtName}>
  129. <img src={schoolIcon} />
  130. <p>{state.schoolInfo.schoolName}</p>
  131. </div>
  132. <div class={styles.dtDesc}>共<span> {state.schoolInfo.classNum} </span>个班级,<span>{state.schoolInfo.studentNum}</span>人参与调查</div>
  133. </div>
  134. <div class={styles.dbStatic}>
  135. <div class={styles.dsItem}>
  136. <div><span>{formatNumberWithComma(state.schoolInfo.supportStudentNum || 0)}</span><i>人</i></div>
  137. <p>支持学校开展</p>
  138. <i class={[styles.dsIcon, styles.dsIcon1]}></i>
  139. </div>
  140. <div class={styles.dsItem}>
  141. <div><span>{state.schoolInfo.supportStudentRate}%</span></div>
  142. <p>支持率</p>
  143. <i class={[styles.dsIcon, styles.dsIcon2]}></i>
  144. </div>
  145. </div>
  146. {/** 选择年级班级 */}
  147. <div class={styles.gradeColumn} onClick={() => state.gradeStatus = true}>
  148. <span class={state.gradeContent && styles.gcText}>{state.gradeContent ? state.gradeContent : '请选择年级班级'}</span>
  149. <i></i>
  150. </div>
  151. {/** 排序栏 */}
  152. <ul class={styles.sortColumn}>
  153. <li class={state.currentSort === 1 && styles.sortActive} onClick={() => filterList(1)}>
  154. <span>参与调查人数</span>
  155. <i class={[(state.currentSort === 1 && !state.currentAsc) && styles.actDown, (state.currentSort === 1 && state.currentAsc) && styles.actUp]}></i>
  156. </li>
  157. <li class={state.currentSort === 2 && styles.sortActive} onClick={() => filterList(2)}>
  158. <span>支持人数</span>
  159. <i class={[(state.currentSort === 2 && !state.currentAsc) && styles.actDown, (state.currentSort === 2 && state.currentAsc) && styles.actUp]}></i>
  160. </li>
  161. <li class={state.currentSort === 3 && styles.sortActive} onClick={() => filterList(3)}>
  162. <span>支持率</span>
  163. <i class={[(state.currentSort === 3 && !state.currentAsc) && styles.actDown, (state.currentSort === 3 && state.currentAsc) && styles.actUp]}></i>
  164. </li>
  165. </ul>
  166. {/** 班级列表 */}
  167. <div class={styles.scList}>
  168. {
  169. state.classList.map((item: any) => (
  170. <div class={styles.sItem}>
  171. <div class={styles.itemTile}>
  172. <img src={gradeIcon} />
  173. <p>{item.currentGrade||''}{item.currentClass || ''}</p>
  174. </div>
  175. <ul class={styles.itemContent}>
  176. <li>
  177. <div class={styles.icTop}>
  178. <span class={styles.sRed}>{formatNumberWithComma(item.studentNum || 0)}</span><i>人</i>
  179. </div>
  180. <p>参与调查</p>
  181. </li>
  182. <li>
  183. <div class={styles.icTop}>
  184. <span class={styles.sBlue}>{formatNumberWithComma(item.supportStudentNum || 0)}</span><i>人</i>
  185. </div>
  186. <p>支持学校开展</p>
  187. </li>
  188. <li>
  189. <div class={styles.icTop}>
  190. <span class={styles.sBlue}>{Number(item.supportStudentRate).toFixed(2)}%</span>
  191. </div>
  192. <p>支持率</p>
  193. </li>
  194. </ul>
  195. </div>
  196. ))
  197. }
  198. </div>
  199. {/* 班级 */}
  200. <Popup
  201. v-model:show={state.gradeStatus}
  202. position="bottom"
  203. round
  204. safeAreaInsetBottom
  205. lazyRender={false}
  206. class={'popupBottomSearch'}
  207. onOpen={() => {
  208. state.gradePopShow = true;
  209. }}
  210. onClosed={() => {
  211. state.gradePopShow = false;
  212. }}>
  213. {state.gradePopShow && (
  214. <Picker
  215. showToolbar
  216. v-model={state.gradeOptionIndex}
  217. columns={state.gradeColumns}
  218. onCancel={() => (state.gradeStatus = false)}
  219. onConfirm={(val: any) => {
  220. console.log('选择1111',val)
  221. state.currentGrade = val.selectedOptions[0].text === '全部年级' ? '' : val.selectedOptions[0].text
  222. state.currentClass = val.selectedOptions[1].text === '全部班级' ? '' : val.selectedOptions[1].text
  223. state.gradeOptionIndex = [val.selectedOptions[0].value, val.selectedOptions[1].value]
  224. state.gradeContent = state.currentGrade + state.currentClass
  225. state.gradeStatus = false;
  226. queryList()
  227. }}
  228. />
  229. )}
  230. </Popup>
  231. {/* <MWxTip /> */}
  232. </div>
  233. );
  234. }
  235. });