index.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. <template>
  2. <div class="educationStatistics">
  3. <NavBar/>
  4. <div class="statistics-container">
  5. <org-tree v-model="orgId" @change="getOrgDataList"></org-tree>
  6. <van-row>
  7. <van-col span="12">
  8. <van-cell title="开始时间" @click="showStartPicker = true" is-link arrow-direction="down"
  9. :value="startWeekStr"/>
  10. <van-popup v-model="showStartPicker" position="bottom" custom-style="height: 20%;">
  11. <week-date-type :defaults="defaults" @onConfirm="onStartTimeConfirm" @onCancel="onCancel"/>
  12. </van-popup>
  13. </van-col>
  14. <van-col span="12">
  15. <van-cell title="结束时间" @click="showEndPicker = true" is-link arrow-direction="down" :value="endWeekStr"/>
  16. <van-popup v-model="showEndPicker" position="bottom" custom-style="height: 20%;">
  17. <week-date-type :defaults="defaults" @onConfirm="onEntTimeConfirm" @onCancel="onCancel"/>
  18. </van-popup>
  19. </van-col>
  20. </van-row>
  21. <div class="card-list">
  22. <empty v-if="!dataList || dataList.length === 0"/>
  23. <ve-table
  24. v-else
  25. maxHeight="calc(100vh - 252px)"
  26. fixedHeader
  27. borderX
  28. borderY
  29. borderAround
  30. :columns="columns"
  31. :table-data="dataList"
  32. />
  33. </div>
  34. </div>
  35. </div>
  36. </template>
  37. <script>
  38. import NavBar from '@/components/NavBar'
  39. import OrgTree from '@/components/orgTree'
  40. import dateCell from '@/components/dateCell'
  41. import selectCell from '@/components/selectCell'
  42. import WeekDateType from "views/menu/monitorStatistics/components/WeekDateType.vue";
  43. import dayjs from "dayjs";
  44. import {selectMonitorReport} from "api/toConsult";
  45. export default {
  46. components: {
  47. WeekDateType,
  48. NavBar,
  49. OrgTree,
  50. dateCell,
  51. selectCell
  52. },
  53. data() {
  54. return {
  55. orgId: '',
  56. showStartPicker: false,
  57. showEndPicker: false,
  58. startWeekStr: '', //年份
  59. endWeekStr: '', //年份
  60. startTime: new Date(),
  61. endTime: new Date(),
  62. defaults: new Date(),
  63. prop: {
  64. label: 'name',
  65. value: 'id'
  66. },
  67. loading: false,
  68. columns: [
  69. {
  70. field: 'index',
  71. key: 'index',
  72. title: '序号',
  73. width: 50,
  74. align: 'center',
  75. renderBodyCell: ({row, column, rowIndex}, h) => {
  76. return ++rowIndex
  77. }
  78. },
  79. {field: 'orgName', key: 'a', title: '单位名称', align: 'center'},
  80. {field: 'planAccessNumber', key: 'b', title: '应调阅次数', align: 'center'},
  81. {field: 'realityAccessNumber', key: 'c', title: '调阅次数', align: 'center'},
  82. {field: 'accessRate', key: 'd', title: '完成率', align: 'center'}
  83. ],
  84. dataList: []
  85. }
  86. },
  87. created() {
  88. },
  89. mounted() {
  90. this.initData()
  91. },
  92. computed: {},
  93. methods: {
  94. dayjs,
  95. formatter(type, val) {
  96. if (type === 'month') {
  97. return `${val}月`;
  98. } else if (type === 'year') {
  99. return `${val}年`;
  100. }
  101. return val;
  102. },
  103. initData() {
  104. this.orgId = JSON.parse(window.sessionStorage.getItem('SET_USER_ORGID')) + '';
  105. this.initializeDates();
  106. this.getDataList();
  107. },
  108. //机构搜索
  109. getOrgDataList(val) {
  110. this.orgId = val
  111. this.getDataList()
  112. },
  113. getDataList() {
  114. let data = {
  115. orgId: this.orgId || '',
  116. startDate: dayjs(this.startTime).startOf('day').format('YYYY-MM-DD'),
  117. endDate: dayjs(this.endTime).endOf('day').format('YYYY-MM-DD'),
  118. }
  119. selectMonitorReport(data).then(res => {
  120. if (res.data.length > 0){
  121. let arr=res.data;
  122. // 将百分比字符串转换为数字
  123. arr.forEach(item => {
  124. item.accessRate = parseFloat(item.accessRate).toFixed(2);
  125. });
  126. // 根据percentage字段进行降序排列
  127. arr.sort((a, b) => b.accessRate - a.accessRate);
  128. // 将排序后的数字转换回带有百分比符号的字符串
  129. arr.forEach(item => {
  130. item.accessRate = `${item.accessRate}%`;
  131. });
  132. // 重新赋值给dataList
  133. this.dataList = arr;
  134. }else {
  135. this.dataList = []
  136. }
  137. })
  138. },
  139. //搜索选择状态时触发
  140. onStartTimeConfirm(value, index) {
  141. // 假设 value 是一个对象,其中包含了 text 属性
  142. const weekText = value[1].text;
  143. this.startTime = value[1].weekStart;
  144. this.startWeekStr = this.getWeekStr(weekText)
  145. this.showStartPicker = false; // 关闭弹窗
  146. if (!this.validateDates()) {
  147. // 显示错误消息
  148. this.$toast('开始时间不能晚于结束时间!');
  149. this.showStartPicker=true;
  150. return;
  151. }
  152. this.getDataList();
  153. },
  154. //搜索选择状态时触发
  155. onEntTimeConfirm(value, index) {
  156. // 假设 value 是一个对象,其中包含了 text 属性
  157. const weekText = value[1].text;
  158. this.endTime = value[1].weekEnd;
  159. this.endWeekStr = this.getWeekStr(weekText);
  160. this.showEndPicker = false; // 关闭弹窗
  161. if (!this.validateDates()) {
  162. // 显示错误消息
  163. this.$toast('开始时间不能晚于结束时间!');
  164. this.showEndPicker=true;
  165. return;
  166. }
  167. console.log(this.startTime, this.endTime)
  168. this.getDataList();
  169. },
  170. onCancel() {
  171. this.showStartPicker = false;
  172. this.showEndPicker = false;
  173. },
  174. //日期格式
  175. formatDate(date) {
  176. return `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`
  177. },
  178. initializeDates() {
  179. const today = dayjs();
  180. const startOfYear = today.startOf('year');
  181. const startOfWeek = today.startOf('week');
  182. const weekOfYear = Math.ceil(startOfWeek.diff(startOfYear, 'weeks', true) + 1);
  183. this.startWeekStr = `第${weekOfYear}周`;
  184. this.endWeekStr = `第${weekOfYear}周`;
  185. this.startTime = today.startOf('week').toDate();
  186. this.endTime = today.endOf('week').toDate();
  187. },
  188. validateDates() {
  189. if (!this.startWeekStr || !this.endWeekStr) {
  190. return;
  191. }
  192. // 将周数字符串转换为数字进行比较
  193. const startWeekNumber = parseInt(this.startWeekStr.replace(/[第周]/g, ''), 10);
  194. const endWeekNumber = parseInt(this.endWeekStr.replace(/[第周]/g, ''), 10);
  195. // 开始时间晚于结束时间,显示错误消息或重新打开弹窗
  196. return startWeekNumber <= endWeekNumber;
  197. },
  198. getWeekStr(text) {
  199. if (!text) {
  200. return '';
  201. }
  202. const weekMatch = text.match(/第(\d+)周/);
  203. if (weekMatch && weekMatch[1]) {
  204. return `第${weekMatch[1]}周`;
  205. }
  206. return '';
  207. },
  208. }
  209. }
  210. </script>
  211. <style lang="scss">
  212. .van-cell-group {
  213. margin-bottom: 20px;
  214. }
  215. .van-cell-group:last-child {
  216. margin-bottom: 0;
  217. }
  218. .vue-table-root {
  219. tr,
  220. td,
  221. th {
  222. font-size: 25px !important;
  223. color: #666 !important;
  224. }
  225. }
  226. </style>
  227. <style lang="scss" scoped>
  228. .educationStatistics {
  229. }
  230. .statistics-container {
  231. }
  232. .card-list {
  233. padding: 20px;
  234. height: calc(100vh - 420px);
  235. overflow: hidden;
  236. }
  237. .card-num {
  238. display: flex;
  239. align-items: center;
  240. font-size: 28px;
  241. color: #009dff;
  242. }
  243. .flex-box {
  244. display: flex;
  245. align-items: center;
  246. > div {
  247. margin-right: 40px;
  248. }
  249. }
  250. .search-flex {
  251. display: flex;
  252. align-items: center;
  253. justify-content: space-between;
  254. > div {
  255. width: 50%;
  256. }
  257. }
  258. .van-cell__value {
  259. color: black;
  260. text-align: left;
  261. }
  262. </style>