summary.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  1. <script setup lang="ts">
  2. import DeptTree2 from '@/views/pms/iotrhdailyreport/DeptTree2.vue'
  3. import quarterOfYear from 'dayjs/plugin/quarterOfYear'
  4. import dayjs from 'dayjs'
  5. import { IotRhDailyReportApi } from '@/api/pms/iotrhdailyreport'
  6. import { useDebounceFn } from '@vueuse/core'
  7. import CountTo from '@/components/count-to1.vue'
  8. dayjs.extend(quarterOfYear)
  9. const rangeShortcuts = [
  10. {
  11. text: '今天',
  12. value: () => {
  13. const today = dayjs()
  14. return [today.startOf('day').toDate(), today.endOf('day').toDate()]
  15. }
  16. },
  17. {
  18. text: '昨天',
  19. value: () => {
  20. const yesterday = dayjs().subtract(1, 'day')
  21. return [yesterday.startOf('day').toDate(), yesterday.endOf('day').toDate()]
  22. }
  23. },
  24. {
  25. text: '本周',
  26. value: () => {
  27. return [dayjs().startOf('week').toDate(), dayjs().endOf('week').toDate()]
  28. }
  29. },
  30. {
  31. text: '上周',
  32. value: () => {
  33. const lastWeek = dayjs().subtract(1, 'week')
  34. return [lastWeek.startOf('week').toDate(), lastWeek.endOf('week').toDate()]
  35. }
  36. },
  37. {
  38. text: '本月',
  39. value: () => {
  40. return [dayjs().startOf('month').toDate(), dayjs().endOf('month').toDate()]
  41. }
  42. },
  43. {
  44. text: '上月',
  45. value: () => {
  46. const lastMonth = dayjs().subtract(1, 'month')
  47. return [lastMonth.startOf('month').toDate(), lastMonth.endOf('month').toDate()]
  48. }
  49. },
  50. {
  51. text: '本季度',
  52. value: () => {
  53. return [dayjs().startOf('quarter').toDate(), dayjs().endOf('quarter').toDate()]
  54. }
  55. },
  56. {
  57. text: '上季度',
  58. value: () => {
  59. const lastQuarter = dayjs().subtract(1, 'quarter')
  60. return [lastQuarter.startOf('quarter').toDate(), lastQuarter.endOf('quarter').toDate()]
  61. }
  62. },
  63. {
  64. text: '今年',
  65. value: () => {
  66. return [dayjs().startOf('year').toDate(), dayjs().endOf('year').toDate()]
  67. }
  68. },
  69. {
  70. text: '去年',
  71. value: () => {
  72. const lastYear = dayjs().subtract(1, 'year')
  73. return [lastYear.startOf('year').toDate(), lastYear.endOf('year').toDate()]
  74. }
  75. },
  76. {
  77. text: '最近7天',
  78. value: () => {
  79. return [dayjs().subtract(6, 'day').toDate(), dayjs().toDate()]
  80. }
  81. },
  82. {
  83. text: '最近30天',
  84. value: () => {
  85. return [dayjs().subtract(29, 'day').toDate(), dayjs().toDate()]
  86. }
  87. },
  88. {
  89. text: '最近90天',
  90. value: () => {
  91. return [dayjs().subtract(89, 'day').toDate(), dayjs().toDate()]
  92. }
  93. },
  94. {
  95. text: '最近一年',
  96. value: () => {
  97. return [dayjs().subtract(1, 'year').toDate(), dayjs().toDate()]
  98. }
  99. }
  100. ]
  101. interface Query {
  102. pageNo: number
  103. pageSize: number
  104. deptId: number
  105. contractName?: string
  106. taskName?: string
  107. createTime: string[]
  108. }
  109. const id = 157
  110. const query = ref<Query>({
  111. pageNo: 1,
  112. pageSize: 10,
  113. deptId: 157,
  114. createTime: []
  115. })
  116. const totalWorkKeys = [
  117. ['totalCount', '个', '总数', 'i-tabler:report-analytics text-sky'],
  118. [
  119. 'alreadyReported',
  120. '个',
  121. '已填报',
  122. 'i-material-symbols:check-circle-outline-rounded text-emerald'
  123. ],
  124. ['notReported', '个', '未填报', 'i-material-symbols:cancel-outline-rounded text-rose'],
  125. [
  126. 'totalFuelConsumption',
  127. 'L',
  128. '累计油耗',
  129. 'i-material-symbols:directions-car-outline-rounded text-sky'
  130. ],
  131. [
  132. 'totalPowerConsumption',
  133. 'KWH',
  134. '累计用电量',
  135. 'i-material-symbols:electric-bolt-outline-rounded text-sky'
  136. ],
  137. [
  138. 'totalWaterInjection',
  139. '方',
  140. '累计注水量',
  141. 'i-material-symbols:water-drop-outline-rounded text-sky'
  142. ],
  143. ['totalGasInjection', '万方', '累计注气量', 'i-material-symbols:cloud-outline text-sky']
  144. ]
  145. const totalWork = ref({
  146. totalCount: 0,
  147. alreadyReported: 0,
  148. notReported: 0,
  149. totalFuelConsumption: 0,
  150. totalPowerConsumption: 0,
  151. totalWaterInjection: 0,
  152. totalGasInjection: 0
  153. })
  154. const totalLoading = ref(false)
  155. const getTotal = useDebounceFn(async () => {
  156. totalLoading.value = true
  157. const { pageNo, pageSize, ...other } = query.value
  158. try {
  159. let res1: any[]
  160. if (query.value.createTime.length !== 0) {
  161. res1 = await IotRhDailyReportApi.rhDailyReportStatistics({
  162. createTime: query.value.createTime
  163. })
  164. totalWork.value.totalCount = res1[0].count
  165. totalWork.value.alreadyReported = res1[1].count
  166. totalWork.value.notReported = res1[2].count
  167. }
  168. const res2 = await IotRhDailyReportApi.totalWorkload(other)
  169. totalWork.value = {
  170. ...totalWork.value,
  171. ...res2,
  172. totalGasInjection: (res2.totalGasInjection || 0) / 10000
  173. }
  174. } finally {
  175. totalLoading.value = false
  176. }
  177. }, 1000)
  178. interface List {
  179. id: number | null
  180. name: string | null
  181. type: '1' | '2' | '3'
  182. cumulativeGasInjection: number | null
  183. cumulativeWaterInjection: number | null
  184. cumulativePowerConsumption: number | null
  185. cumulativeFuelConsumption: number | null
  186. transitTime: number | null
  187. }
  188. const total = ref<number>(1000)
  189. const list = ref<List[]>([])
  190. const type = ref('2')
  191. const columns = (type: string) => {
  192. return [
  193. {
  194. label: type === '2' ? '项目部' : '队伍',
  195. prop: 'name'
  196. },
  197. {
  198. label: '累计注气量(万方)',
  199. prop: 'cumulativeGasInjection'
  200. },
  201. {
  202. label: '累计注水量(方)',
  203. prop: 'cumulativeWaterInjection'
  204. },
  205. {
  206. label: '累计用电量(KWH)',
  207. prop: 'cumulativePowerConsumption'
  208. },
  209. {
  210. label: '累计油耗(L)',
  211. prop: 'cumulativeFuelConsumption'
  212. }
  213. ]
  214. }
  215. const listLoading = ref(false)
  216. const formatter = (row: List, column: any) => {
  217. return row[column.property] ?? 0
  218. }
  219. const getList = useDebounceFn(async () => {
  220. listLoading.value = true
  221. try {
  222. const res = (await IotRhDailyReportApi.getIotRhDailyReportSummary(query.value)) as {
  223. total: number
  224. list: any[]
  225. }
  226. const { total: resTotal, list: resList } = res
  227. total.value = resTotal
  228. type.value = resList[0]?.type || '2'
  229. list.value = resList.map(
  230. ({ id, projectDeptIa, projectDeptName, teamId, teamName, sort, taskId, type, ...other }) => ({
  231. id: type === '2' ? projectDeptIa : teamId,
  232. name: type === '2' ? projectDeptName : teamName,
  233. ...other,
  234. cumulativeGasInjection: (other.cumulativeGasInjection || 0) / 10000
  235. })
  236. )
  237. } finally {
  238. listLoading.value = false
  239. }
  240. }, 1000)
  241. const handleDeptNodeClick = (node: any) => {
  242. query.value.deptId = node.id
  243. handleQuery()
  244. }
  245. const handleQuery = (setPage = true) => {
  246. if (setPage) {
  247. query.value.pageNo = 1
  248. }
  249. getTotal()
  250. getList()
  251. }
  252. const resetQuery = () => {
  253. query.value = {
  254. pageNo: 1,
  255. pageSize: 10,
  256. deptId: 157,
  257. contractName: '',
  258. taskName: '',
  259. createTime: []
  260. }
  261. handleQuery()
  262. }
  263. watch(
  264. () => query.value.createTime,
  265. () => handleQuery(false)
  266. )
  267. onMounted(() => {
  268. handleQuery()
  269. })
  270. </script>
  271. <template>
  272. <div class="grid grid-cols-[16%_1fr] gap-5">
  273. <div class="bg-white dark:bg-[#1d1e1f] rounded-lg shadow p-4">
  274. <DeptTree2 :deptId="id" @node-click="handleDeptNodeClick" />
  275. </div>
  276. <div class="grid grid-rows-[62px_164px_1fr] h-full gap-5">
  277. <el-form
  278. size="default"
  279. class="bg-white dark:bg-[#1d1e1f] rounded-lg shadow px-8 gap-8 flex items-center justify-between"
  280. >
  281. <div class="flex items-center gap-8">
  282. <el-form-item label="项目">
  283. <el-input
  284. v-model="query.contractName"
  285. placeholder="请输入项目"
  286. clearable
  287. @keyup.enter="handleQuery()"
  288. class="!w-240px"
  289. />
  290. </el-form-item>
  291. <el-form-item label="任务">
  292. <el-input
  293. v-model="query.taskName"
  294. placeholder="请输入任务"
  295. clearable
  296. @keyup.enter="handleQuery()"
  297. class="!w-240px"
  298. />
  299. </el-form-item>
  300. <el-form-item label="创建时间">
  301. <el-date-picker
  302. v-model="query.createTime"
  303. value-format="YYYY-MM-DD HH:mm:ss"
  304. type="daterange"
  305. start-placeholder="开始日期"
  306. end-placeholder="结束日期"
  307. :shortcuts="rangeShortcuts"
  308. class="!w-220px"
  309. />
  310. </el-form-item>
  311. </div>
  312. <el-form-item>
  313. <el-button type="primary" @click="handleQuery()">
  314. <Icon icon="ep:search" class="mr-5px" /> 搜索
  315. </el-button>
  316. <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
  317. </el-form-item>
  318. </el-form>
  319. <div class="grid grid-cols-7 gap-8">
  320. <div
  321. v-for="info in totalWorkKeys"
  322. :key="info[0]"
  323. class="bg-white dark:bg-[#1d1e1f] rounded-lg shadow p-4 flex flex-col items-center justify-center gap-2"
  324. >
  325. <div class="size-7.5" :class="info[3]"></div>
  326. <count-to class="text-2xl font-medium" :start-val="0" :end-val="totalWork[info[0]]">
  327. <span class="text-xs leading-8 text-[var(--el-text-color-regular)]">暂无数据</span>
  328. </count-to>
  329. <div class="text-xs font-medium text-[var(--el-text-color-regular)]">{{ info[1] }}</div>
  330. <div class="text-sm font-medium text-[var(--el-text-color-regular)]">{{ info[2] }}</div>
  331. </div>
  332. </div>
  333. <div class="bg-white dark:bg-[#1d1e1f] rounded-lg shadow pt-4 px-8">
  334. <el-table
  335. v-loading="listLoading"
  336. :data="list"
  337. :stripe="true"
  338. :style="{ width: '100%' }"
  339. max-height="600"
  340. class="min-h-143"
  341. show-overflow-tooltip
  342. >
  343. <el-table-column
  344. v-for="item in columns(type)"
  345. :key="item.prop"
  346. :label="item.label"
  347. :prop="item.prop"
  348. align="center"
  349. :formatter="formatter"
  350. />
  351. </el-table>
  352. <Pagination
  353. class="mt-8"
  354. :total="total"
  355. v-model:page="query.pageNo"
  356. v-model:limit="query.pageSize"
  357. @pagination="getList"
  358. />
  359. </div>
  360. </div>
  361. </div>
  362. </template>
  363. <style scoped>
  364. :deep(.el-form-item) {
  365. margin-bottom: 0;
  366. }
  367. :deep(.el-table) {
  368. border-top-right-radius: 8px;
  369. border-top-left-radius: 8px;
  370. .el-table__cell {
  371. height: 52px;
  372. }
  373. .el-table__header-wrapper {
  374. .el-table__cell {
  375. background: var(--el-fill-color-light);
  376. }
  377. }
  378. }
  379. </style>